59API

← Retour aux guides

Connect Claude Desktop to Your API with MCP

Claude Code · EN · 2026-09-16

Use MCP to Connect Claude Desktop to a Custom API

Claude Desktop does not provide a setting for replacing the API endpoint used by its built-in chat model. In other words, adding an ANTHROPIC_BASE_URL value to Claude Desktop settings will not route the desktop conversation through a third-party relay. The supported and practical way to connect Claude Desktop to your own endpoint is Model Context Protocol (MCP): Claude Desktop launches a local MCP server, and that server calls your API as a tool.

This approach is useful for internal order systems, documentation search, CRM records, deployment dashboards, or any REST API that Claude should access during a conversation. The example below creates a read-only order lookup tool. Replace the path and response handling with your own API contract.

1. Create a Small Local MCP Server

Create a folder, then install the MCP SDK and Zod for input validation:

mkdir claude-custom-api && cd claude-custom-api && npm init -y && npm install @modelcontextprotocol/sdk zod

Create a file named server.mjs with this implementation:

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; const server = new McpServer({ name: "custom-api", version: "1.0.0" }); server.tool("lookup_order", "Find an order by its ID", { orderId: z.string().min(1) }, async ({ orderId }) => { const url = `${process.env.CUSTOM_API_BASE_URL}/orders/${encodeURIComponent(orderId)}`; const response = await fetch(url, { headers: { Authorization: `Bearer ${process.env.CUSTOM_API_TOKEN}`, Accept: "application/json" } }); if (!response.ok) throw new Error(`API request failed: ${response.status}`); const order = await response.json(); return { content: [{ type: "text", text: JSON.stringify(order) }] }; }); await server.connect(new StdioServerTransport());

The MCP server communicates with Claude Desktop through standard input and output, while fetch() sends the authenticated request to your endpoint. Do not write debug logs to standard output because MCP uses that channel for protocol messages. If you need diagnostics, write them to standard error instead.

2. Register the Tool in Claude Desktop

Open Claude Desktop configuration. On macOS, the usual file is ~/Library/Application Support/Claude/claude_desktop_config.json. On Windows, use %APPDATA%\Claude\claude_desktop_config.json. Add the following configuration, using absolute paths and your real API values:

{ "mcpServers": { "custom-api": { "command": "node", "args": ["/absolute/path/to/claude-custom-api/server.mjs"], "env": { "CUSTOM_API_BASE_URL": "https://internal.example.com/api", "CUSTOM_API_TOKEN": "replace-with-a-scoped-token" } } } }

Restart Claude Desktop after saving the file. In a new chat, ask: “Use the custom-api tool to look up order 4815.” Claude should request or invoke the tool and return the API result. If it does not appear, verify that Node.js is available to the desktop application, the script path is absolute, and the endpoint can be reached from your machine.

3. Keep the Integration Safe and Useful

Where 59API Fits for Claude and GPT Development

MCP connects Claude Desktop to your business API; it does not replace Claude Desktop’s hosted model connection. When you need to route model calls from Claude Code, an Anthropic-compatible application, or an OpenAI SDK application, 59API is a strong low-cost option. Its API base URL is https://api.59api.com, and it provides pay-as-you-go access to Claude Opus, Sonnet, Haiku, Fable, and GPT models while maintaining compatibility with Claude Code, Codex, and OpenAI SDK workflows.

For example, a Claude Code environment can use ANTHROPIC_BASE_URL=https://api.59api.com together with your 59API key. That gives development teams a budget-friendly relay without intentionally downgrading model quality, while the MCP tool above keeps Claude Desktop connected to the systems that matter. If you are testing multi-model workflows or want lower-cost API usage, consider signing up for 59API and reviewing its referral rebate options.

Tarifs · Docs

PrĂȘt Ă  commencer ?

Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.

Inscription gratuite