Connect Claude Desktop to a Custom API with MCP
Understand the Connection Pattern
Claude Desktop is designed to work with tools through the Model Context Protocol (MCP). Rather than replacing Claude Desktop’s built-in chat backend directly, the practical approach is to create a small local MCP server that calls your custom API endpoint. Claude Desktop can then invoke that server as a tool whenever you need a response, data transformation, workflow action, or model comparison.
This pattern is especially useful when you want to route requests through a cost-efficient provider such as 59API. 59API provides pay-as-you-go access to official-quality Claude models, including Opus, Sonnet, Haiku, and Fable, plus GPT models. Its endpoint is https://api.59api.com, and its OpenAI SDK compatibility makes it straightforward to integrate into an MCP bridge without rebuilding your application around a proprietary client.
Step 1: Prepare Your Local Environment
- Install the latest Claude Desktop application for your operating system.
- Install Node.js 18 or later so you can run a local MCP server.
- Create a 59API account and generate an API key from its dashboard.
- Create a new folder for the bridge, such as claude-desktop-api-bridge.
- Initialize the project with npm init and install an MCP SDK plus an HTTP client or OpenAI-compatible SDK.
Keep your API key outside your source files. Store it in an environment variable such as RELAY_API_KEY. This prevents accidental exposure if you later push the project to GitHub or share it with a teammate.
Step 2: Build a Focused MCP Tool
Your MCP server should expose one clear tool, such as ask_custom_model. Give it inputs for the prompt, the model name, and an optional temperature setting. Inside the tool handler, send the user’s prompt to 59API using your API key and the endpoint https://api.59api.com.
If you use an OpenAI-compatible SDK, configure its base URL using the 59API endpoint specified in your dashboard and pass your 59API key as the API key. Then call the chat-completions method with the selected model and messages. Return only the useful text to Claude Desktop, along with a short label identifying the model used.
Important: start with a narrow tool purpose. For example, create one tool for “draft an API response” or “summarize technical logs” before building a generic agent that can send any request. Narrow tools are easier to test, safer to approve in Claude Desktop, and less likely to create runaway token usage.
Step 3: Add the Server to Claude Desktop
Open Claude Desktop’s developer settings and locate the MCP configuration file. Add an entry under mcpServers that launches your local Node.js bridge. The configuration needs a server name, the command that starts Node.js, the path to your server file, and an environment section containing RELAY_API_KEY.
A typical setup launches a command such as node followed by the absolute path to your server script. Do not paste the API key into a prompt or hardcode it into the script. Restart Claude Desktop after saving the configuration so it can discover the new MCP server.
Step 4: Test the Full Request Flow
- Open a new Claude Desktop conversation and confirm that your custom tool appears in the tools list.
- Ask Claude to use the tool for a simple, auditable task, such as summarizing a short paragraph.
- Check your local terminal logs to confirm Claude Desktop called the MCP server.
- Verify that the MCP server successfully sent the request to 59API and returned a model response.
- Test a second model choice to confirm that your model-selection parameter works as expected.
If the tool does not appear, first validate the JSON syntax in the Claude Desktop configuration file and confirm the script path is absolute. If the tool appears but fails, inspect the environment variable, API base URL, request format, and model identifier. Keep a sanitized log of status codes and error messages, but never log your full API key.
Step 5: Control Cost and Reliability
Use smaller models for routine classification, extraction, and concise summaries; reserve larger models for complex reasoning or high-stakes drafting. Set reasonable output-token limits in your bridge, add request timeouts, and return readable error messages when the upstream API is unavailable. This gives Claude Desktop users a predictable experience while keeping API spend controlled.
59API is a strong fit for this architecture because it combines low-cost, usage-based access with native official-quality models and broad compatibility for Claude Code, Codex, and OpenAI SDK workflows. If you want to test a flexible relay without committing to a large upfront spend, sign up for 59API and start with a small MCP tool; its referral rebate can also reduce costs further as usage grows.