MCPConnectionManager.tsx. MCP servers extend Claude Code with additional tools, resources, and capabilities. Any tool exposed by an MCP server is automatically registered and available to the agent.
Architecture
Configuring an MCP Server
MCP servers are declared insettings.json under the mcpServers key. Each entry specifies the server name, transport, and connection parameters:
Environment variables referenced with
${VAR_NAME} syntax in settings.json are expanded at connection time by src/services/mcp/envExpansion.ts.Transport Types
- stdio
- sse (HTTP EventSource)
- http (Streamable HTTP)
- ws (WebSocket)
- sdk (in-process)
Claude Code spawns a child process and communicates over its The child process is managed by
stdin/stdout. This is the most common transport for local MCP servers.client.ts using the @modelcontextprotocol/sdk StdioClientTransport. The process is killed when the MCP connection is closed.Connecting to an MCP Server
Server discovery
On startup,
MCPConnectionManager.tsx reads mcpServers from settings.json (and any workspace-level claude.json overrides). Each entry becomes a MCPServerConnection record.Transport initialization
Based on the
type field, the appropriate transport is created: StdioClientTransport spawns the process; SSEClientTransport opens the event stream; StreamableHTTPClientTransport or WebSocketClientTransport establishes the network connection.MCP handshake
The MCP client sends an
initialize request with the client capabilities. The server responds with its own capabilities and protocol version. This follows the MCP spec initialization sequence.Tool listing
After initialization, the client calls
tools/list to enumerate all tools the server exposes. Each tool’s name, description, and JSON Schema input spec are captured.Tool registration
Each server tool is wrapped in an
MCPTool instance and registered into the tool dispatch map using the naming convention mcp__<server>__<tool>. The tool’s JSON Schema becomes its Zod validation schema.Tool calls
When the agent invokes an MCP tool,
MCPTool.call() forwards the request to the MCP server over the established transport and streams the result back as a tool_result block.Tool Naming Convention
MCP tools are registered under the patternmcp__<server>__<tool>:
| MCP server name | MCP tool name | Registered as |
|---|---|---|
filesystem | read_file | mcp__filesystem__read_file |
github | create_pull_request | mcp__github__create_pull_request |
my-server | search | mcp__my-server__search |
Resource Listing
Beyond tools, MCP servers can expose resources — files, databases, or other data sources. Two built-in tools wrap this capability:| Tool | Description |
|---|---|
ListMcpResourcesTool | Lists all resources available from a connected MCP server |
ReadMcpResourceTool | Reads the content of a specific MCP resource by URI |
Authentication
Claude Code supports three authentication methods for MCP servers: API key via headers — the simplest option; specify anAuthorization or x-api-key header in the server config.
OAuth 2.0 — configured via McpOAuthConfig in src/services/mcp/auth.ts. Claude Code handles the full authorization code flow, including token storage and refresh. The OAuth callback port is managed by oauthPort.ts.
Cross-App Access (XAA / SEP-990) — an Anthropic-specific flow implemented in xaa.ts and xaaIdpLogin.ts. Used for Claude.ai-hosted MCP servers where Claude Code authenticates as an Anthropic-identity client. The spec reference is SEP-990.
Managing MCP Connections
The/mcp slash command provides a live view of all configured MCP servers and their connection status. From the /mcp UI you can:
- View which servers are connected, connecting, or errored
- See the list of tools registered from each server
- Manually trigger a reconnect
- View raw connection error details
useManageMCPConnections.ts and surfaced through the React/Ink terminal UI.