Connecting Claude to an MCP Server
Independent educational resource, not an official Anthropic course. Facts about the API, prices and limits were checked against Anthropic's documentation on 15 November 2026 and the code was run against a local mock of the API, not the live service. Check the linked official pages before relying on a number, and test with your own key.
You have a server. There are three ways to put Claude in front of it, and they differ in who runs the client, what features work and how much control you keep. Picking the wrong one is the usual source of "the tools don't show up" and "it can't see my local server". This lesson covers Claude Code, Claude Desktop, the Messages API connector and your own client, with the exact configuration for each and the limits the documentation states.
What you'll learn
- Adding a server to Claude Code, with scopes and a shared
.mcp.json.
- The Claude Desktop configuration file.
- The Messages API MCP connector (beta): what it supports and what it doesn't.
- How to choose between all three and your own client.
Before you start
Option 1: Claude Code
Claude Code is an MCP host. You add servers with claude mcp add. The command takes a name, then either a URL (for HTTP) or a command to launch (for stdio). The -- separates Claude's options from the server's own command, which is passed through unchanged:
# local stdio server (our shop server)
claude mcp add --transport stdio shop -- python mcp/shop_server.py
# remote HTTP server with a bearer token
claude mcp add --transport http shop-remote https://mcp.example.com/mcp \
--header "Authorization: Bearer $SHOP_MCP_TOKEN"
claude mcp list # servers and their health
claude mcp get shop # details for one
claude mcp remove shop
Inside a session, /mcp shows each server's status (connected, needs authentication, failed), lets you complete OAuth sign-in for remote servers, reconnect or disable one. The documentation lists three transports: HTTP (recommended for remote), SSE (deprecated) and stdio for local processes. I checked the claude mcp add --help output on a local install and it matches this syntax, but the CLI changes often, so check --help on yours.
Scopes
| Scope | Flag | Who sees it | Stored in |
| Local (default) | --scope local | You, in this project | ~/.claude.json |
| Project | --scope project | Everyone who clones the repo | .mcp.json in the project root |
| User | --scope user | You, in every project | ~/.claude.json |
A project-scoped .mcp.json is committed, so the whole team gets the same servers. It supports environment variable expansion, so tokens stay out of the file:
{
"mcpServers": {
"shop": {
"command": "python",
"args": ["mcp/shop_server.py"]
},
"shop-remote": {
"type": "http",
"url": "${SHOP_MCP_URL:-https://mcp.example.com/mcp}",
"headers": { "Authorization": "Bearer ${SHOP_MCP_TOKEN}" }
}
}
}
${VAR} expands to the variable's value and ${VAR:-default} uses a default when it's unset. Never write a real token into a committed file.
What Claude Code does for safety
- In interactive sessions it asks for approval before using a project-scoped server from
.mcp.json. claude mcp reset-project-choices resets those choices.
- Non-interactive runs (
claude -p and Agent SDK sessions) can't show that prompt and load project servers without asking, so block unwanted ones with disabledMcpjsonServers or --strict-mcp-config.
- It warns when a tool's output exceeds 10,000 tokens and limits it to 25,000 by default (
MAX_MCP_OUTPUT_TOKENS raises it). Longer text results are saved to a file.
- The documentation warns to verify that you trust each server, because servers that fetch outside content can expose you to prompt injection.
Option 2: Claude Desktop
Claude Desktop reads a JSON file. On Linux the quickstart gives ~/.config/Claude/claude_desktop_config.json; macOS and Windows have their own locations in the same page. The servers go under mcpServers, each with a command and args:
{
"mcpServers": {
"shop": {
"command": "/ABSOLUTE/PATH/TO/venv/bin/python",
"args": ["/ABSOLUTE/PATH/TO/shop_server.py"]
}
}
}
Use absolute paths. The quickstart warns that you may need the full path to the executable too, because the app may not share your shell's PATH. Restart the app after editing, and the MCP controls appear once at least one server is configured correctly.
Option 3: the Messages API connector (beta)
If you're calling the API from your own code, the MCP connector lets the API connect to a remote MCP server for you, with no client code of your own. It's a beta feature and has real limits, which the documentation states:
- Of the MCP feature set, only tool calls are supported. Resources and prompts don't come through.
- The server must be reachable over HTTP from the internet (Streamable HTTP or SSE). A local stdio server can't be connected directly.
- You send the beta header
mcp-client-2025-11-20, an mcp_servers list and a matching mcp_toolset entry in tools. Every server must be used by exactly one toolset.
- The model's responses contain
mcp_tool_use and mcp_tool_result blocks. The API runs the calls itself, so you don't write a loop.
- Authentication is an OAuth bearer token in
authorization_token. You obtain and refresh it yourself.
import os
import anthropic
client = anthropic.Anthropic() # ANTHROPIC_API_KEY comes from the environment
response = client.beta.messages.create(
model="claude-sonnet-5-5",
max_tokens=1000,
messages=[{"role": "user", "content": "Where is order A100?"}],
mcp_servers=[{
"type": "url",
"url": "https://mcp.example.com/mcp", # must be reachable from the public internet
"name": "shop",
"authorization_token": os.environ["SHOP_MCP_TOKEN"],
}],
tools=[{
"type": "mcp_toolset",
"mcp_server_name": "shop",
"default_config": {"enabled": False}, # deny by default...
"configs": {"lookup_order": {"enabled": True}}, # ...then allow only what you need
}],
betas=["mcp-client-2025-11-20"],
)
print(response.stop_reason)
The default_config turns every tool off, and configs turns on only the ones you want. This is the allow-list pattern from lesson 7.3, done by the API. A newer beta header, mcp-client-2026-09-15, records and lets you pin a server's tool list so it can't change mid-conversation; check the connector page for the current details before relying on it. Beta features change, and the documentation notes that this feature has already replaced an earlier version.
We checked these parameters against the documentation's examples and the SDK accepted our request shape, but we did not run it against a live MCP server or the live API, because that needs a public server and an API key. Test it with your own.
Option 4: your own client
Lesson 7.3's bridge gives you everything the connector doesn't: stdio servers, resources and prompts, your own approvals, results capped to a size you choose and an audit trail. The cost is that you maintain the loop. For anything that must run unattended against private systems, this is often the right choice, and it's what the project in 7.10 uses.
Choosing
| You want | Use |
| Claude to use tools while you code | Claude Code, project or user scope |
| Claude in a desktop chat app to reach local files or tools | Claude Desktop config |
| API calls that reach a public, remote server, with minimal code | The Messages API connector |
| Local servers, resources, prompts, approvals and audit in your own app | Your own client (7.3) |
Real-world use case (illustrative scenario)
This scenario is an invented example to show how the ideas fit together. It is not a case study and its details are not measured results.
A team commits .mcp.json with a read-only staging database server, so every developer's Claude Code can inspect staging data on day one. Developers add personal servers at user scope. The customer-facing support agent doesn't use Claude Code at all: it's a Python service with its own MCP client, an allow list and an approval queue. Same protocol, three different arrangements, each chosen for what it needs.
Mistakes to avoid
- Committing tokens in
.mcp.json instead of using ${VAR}.
- Approving a project server without reading what it runs.
- Pointing the API connector at a local stdio server.
- Expecting resources and prompts to work through the connector.
- Relative paths in a Desktop config.
Security notes
A project's .mcp.json can contain a command that runs on your machine. Treat a pull request that edits it like a pull request that edits a build script. Use the narrowest token a server needs and keep it in the environment. For non-interactive Claude Code, don't rely on the approval prompt: it can't appear.
Cost and speed
Every connected server's tool definitions are sent to the model, so more servers means more input tokens. The API connector's allow list and Claude Code's server controls both cut that. Remote servers add a network round trip to each call.
Key takeaways
claude mcp add with stdio or HTTP; scopes decide who shares it; .mcp.json goes in git with ${VAR} for secrets.
- Claude Desktop uses a JSON file with absolute paths.
- The API connector is beta, tools only, remote HTTP only.
- Your own client gives the most control and the most work.
Lesson recap: pick the arrangement by who runs the client and what you need.
Quick quiz
- Which scope writes to
.mcp.json?
- Why use
${SHOP_MCP_TOKEN} in .mcp.json?
- What two limits does the API connector have?
- How do you allow only one tool from a server in the connector?
- Why doesn't the approval prompt help in
claude -p?
Answers and explanations
- Project scope (
--scope project).
- So the real token stays in each person's environment, not in a file that's committed to git.
- It supports tool calls only, and the server must be publicly reachable over HTTP.
- Set
default_config.enabled to false on the toolset and enable that tool under configs.
- Non-interactive runs can't show a prompt, so project servers load without asking. Use
disabledMcpjsonServers or --strict-mcp-config.
Official references and further reading
Related tutorials