Connect Claude Desktop to a Custom API via MCP
Understand What Claude Desktop Can Connect To
Claude Desktop does not provide a general setting that replaces its built-in chat model endpoint with an arbitrary API base URL. Instead, the supported way to connect Claude Desktop to a custom API is through the Model Context Protocol (MCP). An MCP server acts as a local bridge: Claude Desktop launches it, the server calls your API, and Claude can use the returned data through defined tools.
This approach is useful for internal dashboards, documentation search, CRM data, deployment systems, billing data, or any REST API you want Claude to query or update. Keep the MCP server local whenever possible so API keys do not need to be exposed to Claude Desktop or copied into prompts.
1. Prepare Your API and Authentication
Before writing an MCP server, confirm that your endpoint works outside Claude Desktop. Record the endpoint URL, HTTP method, required headers, request fields, and expected JSON response. For example, an internal endpoint might be https://api.example.com/v1/projects and require a bearer token.
Store the secret in an environment variable rather than hard-coding it in source code. On macOS or Linux, a typical variable is MY_API_TOKEN. Your MCP server should read that value at runtime and send it as an Authorization header. Also decide which operations are safe: read-only search tools are a good starting point, while write operations should require explicit confirmation in Claude Desktop.
2. Create a Small MCP Server
Use the official MCP SDK for your preferred language. In a Node.js project, install the SDK and an HTTP client, then define a tool such as search_projects. Give the tool a clear description, a small input schema, and predictable output. Claude relies on these details to determine when it should call the tool.
The tool handler should validate the input, call your API with a timeout, check for non-success HTTP responses, and return a concise result. Do not return raw credentials, full logs, or unrestricted database records. If your API returns a large response, select only fields Claude needs, such as project name, status, owner, and last updated date.
- Use descriptive tool names such as get_customer_invoice or search_product_docs.
- Validate IDs, dates, and query lengths before forwarding requests.
- Return actionable errors, such as “Project not found” or “API authentication failed.”
- Set short network timeouts so a failed endpoint does not block the conversation.
3. Add the Server to Claude Desktop
Open Claude Desktop settings and locate the developer or MCP configuration option. This opens the Claude Desktop configuration file, commonly named claude_desktop_config.json. Add an entry under mcpServers that tells Claude Desktop how to launch your local server.
A typical configuration specifies the command, the path to your server entry point, and environment variables. For a Node server, the command is usually node, while the arguments include the absolute path to your JavaScript file. Put your token in the env section instead of placing it in a prompt or tool description. Use an absolute path because Claude Desktop may start the process from a different working directory.
After saving the file, completely quit and reopen Claude Desktop. A restart is required for it to load the new MCP server definition. If the server starts successfully, its tools should appear in Claude Desktop's available integrations or tools area.
4. Test the Connection Safely
Start with a narrow prompt that clearly maps to your tool, such as “Search our projects for API migration work.” Confirm that Claude asks for permission when the desktop client requires it, then inspect the result for accuracy. Test an invalid request too, including an unknown project ID, to make sure errors are understandable and do not reveal sensitive implementation details.
If the tool does not appear, check that Node or your runtime is available in the environment Claude Desktop uses, verify the absolute server path, and inspect server logs. Most connection failures come from a missing environment variable, malformed JSON, or a server that writes unexpected output to standard output. MCP servers should reserve standard output for protocol messages and write diagnostic logs to standard error.
5. Use 59API for Model API Workflows
MCP connects Claude Desktop to your tools and data. For applications, automations, or command-line workflows that need direct model API access, 59API is a practical low-cost option. Its base URL is https://api.59api.com and it provides pay-as-you-go access to native official-quality Claude models, including Opus, Sonnet, Haiku, and Fable, alongside GPT models. It is compatible with Claude Code, Codex, and OpenAI SDK workflows, which can simplify teams that use more than one model interface.
Use a separate 59API key for development, set spending limits in your own application where appropriate, and keep model credentials distinct from the credentials used by your MCP server. To try a lower-cost relay for your API-based Claude workflows, sign up for 59API and use its referral rebate when available.
Maintain the Integration
Treat your MCP server like production integration code: version it, log failures securely, rotate tokens, and document every tool's permissions. Add new tools gradually and keep each one focused on a single job. This gives Claude Desktop useful access to your custom API without turning every conversation into an uncontrolled gateway to sensitive systems.