MCP Integration
- Entity ID:
ent-mcp-integration - Type:
service - Scope:
shared
What it is
The Model Context Protocol (MCP) integration is Claude Code's primary extensibility mechanism — a full 24-file protocol implementation (300KB+) supporting stdio, SSE, and WebSocket transports. The MCP client alone is 119K lines, making it the most complete MCP implementation in existence. Any server implementing the MCP protocol can register tools, expose resources, and push notifications into a Claude Code session.
Claude Code doesn't overlay MCP — it IS MCP. Every capability including Computer Use runs as a tool call through the same protocol. External servers adopt identical patterns.
Why it exists
Claude Code needed an extensibility model that could:
1. Integrate arbitrary external tools without modifying the core codebase
2. Preserve prompt cache economics — enterprise MCP setups add 55,000+ tokens before the first user message
3. Support multiple transport protocols — local tools via stdio, remote servers via SSE/WebSocket
4. Enable the channel system — channels (peer messaging, notifications) are implemented as MCP servers declaring experimental['claude/channel'] capability
The decision to make MCP foundational rather than a plugin layer means all tools — built-in and external — share the same dispatch, caching, and permission infrastructure.
What depends on it
- Channel system — Channels are MCP servers with
experimental['claude/channel']capability. The entire channel infrastructure reuses MCP's server discovery, connection management, and notification protocol. - Tool registration — All MCP tools are sorted alphabetically and appended after built-in tools. The two groups never interleave, preserving the expensive built-in prefix cache.
- KAIROS autonomous agents — MCP servers must meet latency requirements (p95 <300ms read, <1s write) for autonomous agent use. Idempotency keys required since background agents repeat requests.
- Skill system — Skills can declare MCP tool dependencies
- System prompt assembly — MCP tool definitions consume context tokens and are placed in the dynamic suffix
Trade-offs and limitations
Context cost: Each MCP server's tool definitions consume tokens on every request. Five active servers can consume 55,000+ tokens. Community consensus: keep servers project-scoped to avoid context pollution.
Cache partitioning: MCP tools are appended after built-ins to avoid cache breaks. This makes registration order-dependent — adding/removing an MCP server invalidates the MCP tool cache but preserves the built-in prefix.
Tool documentation deduplication: A lightweight LLM side-query checks if the user has already seen a tool's description in the last N turns. If yes, docs are stripped from context. This saves tokens but adds latency.
Auth complexity: The auth module is 88KB — JWT + OAuth for server authentication. This is the second-largest file in the MCP subsystem.
Architecture
Key files
| File | Size | Role |
|---|---|---|
src/services/mcp/client.ts |
119KB | Full protocol client |
src/services/mcp/auth.ts |
88KB | JWT + OAuth authentication |
src/services/mcp/config.ts |
51KB | Server discovery, .mcp.json parsing |
src/services/mcp/useManageMCPConnections.ts |
44KB | Server lifecycle hook |
Dedicated MCP tools
MCPTool— Generic execution of any MCP server toolListMcpResourcesTool— List resources exposed by MCP serversReadMcpResourceTool— Read specific MCP resourcesMcpAuthTool— Handle MCP server authenticationMonitorTool— Lifecycle monitoring for MCP connectionsToolSearchTool— Lazy tool loading (deferred schema fetch)
Server discovery
Servers configured in .mcp.json (project-scoped) or ~/.claude.json (global):
{
"mcpServers": {
"server-name": {
"command": "server-binary",
"args": [],
"env": {}
}
}
}
Three-Layer Tool Result Pattern
Production MCP servers should return data in three tiers: 1. Index — Fast, always-loaded references (~150 chars per entry) 2. Detailed data — Fetched on demand 3. Raw transcripts — Searched, never bulk-reloaded
Key claims
clm-mcp-119k: The MCP client is 119K lines — the most complete MCP implementation in existenceclm-mcp-cache-partition: MCP tools are appended after built-ins to preserve cache prefix economicsclm-mcp-channel-reuse: Channels are MCP servers declaringexperimental['claude/channel']clm-mcp-context-cost: Five active MCP servers consume 55,000+ tokens before the first user message
Relationships
- implements: Model Context Protocol standard
- contains: mcp-client, mcp-auth, mcp-config, mcp-connection-manager
- depended_on_by: channel-system, tool-registration, kairos, skill-system
- uses: system-prompt-assembly (for tool definition placement)
Evidence
src-20260409-d8242dda0eb8: V1 Wiki: MCP Integrationsrc-20260409-edbed459cd6a: DeepWiki Claude Code analysis
Open questions
- How does MCP tool permission interact with the permission pipeline? Are MCP tools subject to the same auto-mode classification?
- What happens when an MCP server's tool conflicts with a built-in tool name?
- How does tool documentation deduplication affect accuracy when tools have changed between sessions?