SSE Proxy Decoupling (ADR-130): - Fix ruvbrain-sse proxy: proper MCP handshake, session creation, drain polling - Fix internal queue endpoints: session_create keeps receiver, drain returns buffered messages - Add response_queues to AppState for SSE proxy communication - Skip sparsifier for >5M edge graphs (was crashing on 16M edges) - Add SSE_DISABLED/MAX_SSE env vars for configurable connection limits - Route SSE to dedicated mcp.pi.ruv.io subdomain (Cloudflare CNAME) - Serve SSE at root / path on proxy (no /sse needed) - Update all references from pi.ruv.io/sse to mcp.pi.ruv.io - Fix Dockerfile consciousness crate build (feature/version mismatches) Claude Code CLI Source Research (ADR-133): - 19 research documents analyzing Claude Code internals (3000+ lines) - Decompiler script + RVF corpus builder for all major versions - Binary RVF containers for v0.2, v1.0, v2.0, v2.1 (300-2068 vectors each) - Call graphs, class hierarchies, state machines from minified source Integration Strategy (ADR-134): - 6-tier integration plan: WASM MCP, agents, hooks, cache, SDK, plugin - Integration guide with architecture diagrams and performance targets Co-Authored-By: claude-flow <ruv@ruv.net>
4.7 KiB
Claude Code CLI: MCP (Model Context Protocol) Integration
Overview
Claude Code acts as an MCP client, connecting to external MCP servers to extend its tool, resource, and prompt capabilities.
Transport Layer
Four transport types supported:
| Transport | Protocol | Use Case |
|---|---|---|
stdio |
stdin/stdout | Local process (most common) |
sse |
Server-Sent Events | Remote persistent connection |
streamable-http |
HTTP streaming | Modern remote transport |
websocket |
WebSocket | Bidirectional real-time |
MCP Protocol Methods
Claude Code implements these MCP protocol methods:
Core
initialize-- Handshake and capability negotiationping-- Keepalive
Tools
tools/list-- Discover available toolstools/call-- Execute a tool
Resources
resources/list-- List available resourcesresources/read-- Read a resource
Prompts
prompts/list-- List available prompt templatesprompts/get-- Get a specific prompt
Completions
completion/complete-- Auto-completion support
Notifications
notifications/initialized-- Client initializednotifications/cancelled-- Operation cancellednotifications/message-- Status messagesnotifications/progress-- Progress updates
Connection Management
MCPConnectionManager
Central manager for all MCP server connections:
MCPConnectionManager
|-- MCPConnections (active connection pool)
|-- MCPServer definitions (from config)
|-- MCPTool registry (discovered tools)
|-- MCPToolOutput handling
|-- MCPToolOverrides (user overrides)
Configuration Sources
MCP servers can be defined in multiple places (priority order):
--mcp-configCLI argument (JSON file or string)--strict-mcp-config-- Use ONLY --mcp-config, ignore all else.mcp.jsonin project root.claude/settings.json(user level).claude/settings.local.json(local level)- Managed settings (enterprise)
Server Definition Format
{
"mcpServers": {
"server-name": {
"command": "npx",
"args": ["-y", "package-name"],
"env": { "KEY": "value" }
}
}
}
Or for remote servers:
{
"mcpServers": {
"remote-server": {
"url": "https://example.com/mcp",
"transport": "sse"
}
}
}
Tool Discovery and Deferred Loading
Eager vs Deferred Tools
- Eager: Tools from MCP servers with few tools are loaded immediately
- Deferred: Tools from servers with many tools (like claude-flow) are
loaded on-demand via the
ToolSearchbuilt-in tool
The ToolSearch tool allows Claude to discover deferred tools by:
- Querying with a name or keyword
- Getting back full JSON Schema definitions
- Then calling those tools normally
Controlled by ENABLE_TOOL_SEARCH env var.
Tool Naming Convention
MCP tools are prefixed: mcp__<server-name>__<tool-name>
Example: mcp__claude-flow_alpha__swarm_init
The MCP_NO_PREFIX / CLAUDE_AGENT_SDK_MCP_NO_PREFIX env vars can
disable this prefixing.
OAuth for Remote MCP
Remote MCP servers can use OAuth authentication:
MCP_CLIENT_SECRET-- Client secret for OAuthMCP_OAUTH_CALLBACK_PORT-- Local callback portMCP_OAUTH_CLIENT_METADATA_URL-- Client metadata URLMCP_CLIENT_METADATA_URL-- Alternative metadata URLOAuthClientConfig-- Full OAuth configurationOAuthClientAuthHandler-- Authentication handler
Batch Connection
For performance, MCP server connections are batched:
MCP_SERVER_CONNECTION_BATCH_SIZE-- Max concurrent connectionsMCP_REMOTE_SERVER_CONNECTION_BATCH_SIZE-- Max concurrent remote connectionsMCP_CONNECTION_NONBLOCKING-- Non-blocking connection mode
MCP Output Handling
MCP_OUTPUT_TOKENS-- Token budget for MCP outputMAX_MCP_OUTPUT_TOKENS-- Maximum output tokensMCP_LARGE_OUTPUT_FILES-- Save large outputs to filesMCP_TRUNCATION_PROMPT_OVERRIDE-- Custom truncation message
MCP Debug
--mcp-debugflag (deprecated, use--debug)MCPDebug-- Debug mode stateMCPLogsPath-- MCP debug log location
MCP Proxy
Claude Code can proxy MCP connections:
MCP_PROXY_URL-- Upstream proxy URLMCP_PROXY_PATH-- Proxy path prefix- Used for session ingress:
/v2/session_ingress/shttp/mcp/
Server Approval
Users must approve MCP servers from .mcp.json:
enabledMcpjsonServers-- Approved server listdisabledMcpjsonServers-- Rejected server listenableAllProjectMcpServers-- Auto-approve alldeniedMcpServers-- Enterprise denylistallowedMcpServers-- Enterprise allowlist
MCP Instrumentation
MCP_INSTR_DELTA/CLAUDE_CODE_MCP_INSTR_DELTA-- Instrumentation interval- Connected to OpenTelemetry for observability