mirror of
https://github.com/codeaashu/claude-code.git
synced 2026-04-08 14:18:50 +03:00
3.4 KiB
3.4 KiB
Prompt 11: MCP Client/Server Integration
Context
You are working in /workspaces/claude-code. The CLI has built-in MCP (Model Context Protocol) support:
- MCP Client — connects to external MCP servers (tools, resources)
- MCP Server — exposes Claude Code itself as an MCP server
MCP lets the CLI use tools provided by external servers and lets other clients use Claude Code as a tool provider.
Key Files
src/services/mcp/— MCP client implementationsrc/services/mcp/types.ts— MCP config typessrc/entrypoints/mcp.ts— MCP server mode entrypointsrc/tools/MCPTool/— Tool that calls MCP serverssrc/tools/ListMcpResourcesTool/— Lists MCP resourcessrc/tools/ReadMcpResourceTool/— Reads MCP resourcessrc/tools/McpAuthTool/— MCP server authenticationmcp-server/— Standalone MCP server sub-project (from Prompt 04)
Task
Part A: Understand MCP client architecture
Read src/services/mcp/ directory:
- How are MCP servers discovered? (
.mcp.jsonconfig file?) - How are MCP server connections established? (stdio, HTTP, SSE?)
- How are MCP tools registered and made available?
- What is the
ScopedMcpServerConfigtype?
Part B: Understand MCP config format
Search for .mcp.json or MCP config loading code. Document:
- Where does the config file live? (
~/.claude/.mcp.json? project root?) - What's the config schema? (server name, command, args, env?)
- How are multiple servers configured?
Example config you might find:
{
"mcpServers": {
"my-server": {
"command": "node",
"args": ["path/to/server.js"],
"env": {}
}
}
}
Part C: Verify MCP SDK integration
The project uses @modelcontextprotocol/sdk (^1.12.1). Check:
- Is it installed in
node_modules/? - Does the import work:
import { Client } from '@modelcontextprotocol/sdk/client/index.js' - Are there version compatibility issues?
Part D: Test MCP client with our own server
Create a test that:
- Starts the
mcp-server/we fixed in Prompt 04 as a child process - Connects to it via stdio using the MCP client from
src/services/mcp/ - Lists available tools
- Calls one tool (e.g.,
list_filesorsearch_code)
Create scripts/test-mcp.ts:
// scripts/test-mcp.ts
// Test MCP client/server roundtrip
// Usage: bun scripts/test-mcp.ts
import './src/shims/preload.js'
// TODO:
// 1. Spawn mcp-server as a child process (stdio transport)
// 2. Create MCP client from src/services/mcp/
// 3. Connect client to server
// 4. List tools
// 5. Call a tool
// 6. Print results
Part E: Test MCP server mode
The CLI can run as an MCP server itself (src/entrypoints/mcp.ts). Read this file and verify:
- What tools does it expose?
- What resources does it provide?
- Can it be started with
bun src/entrypoints/mcp.ts?
Part F: Create sample MCP config
Create a .mcp.json in the project root (or wherever the app looks for it) that configures the local MCP server:
{
"mcpServers": {
"claude-code-explorer": {
"command": "node",
"args": ["mcp-server/dist/index.js"],
"env": {
"CLAUDE_CODE_SRC_ROOT": "./src"
}
}
}
}
Verification
- MCP client code in
src/services/mcp/loads without errors - MCP server mode (
src/entrypoints/mcp.ts) starts without crashing - A roundtrip test (client → server → response) works
.mcp.jsonconfig file is created and parseable