Skip to content

Commit edbb81d

Browse files
committed
docs: add comprehensive MCP server configuration guide
Add documentation for all MCP server configuration options including: - External stdio servers (with note that Claude Code auto-spawns them) - SSE and HTTP remote servers - Config file path option - MCP tool naming pattern This addresses issue #87 by clarifying how to configure MCP servers and explaining that users don't need to manually run stdio servers.
1 parent 27575ae commit edbb81d

File tree

1 file changed

+81
-1
lines changed

1 file changed

+81
-1
lines changed

README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,91 @@ Code. See [src/claude_agent_sdk/client.py](src/claude_agent_sdk/client.py).
8787

8888
Unlike `query()`, `ClaudeSDKClient` additionally enables **custom tools** and **hooks**, both of which can be defined as Python functions.
8989

90+
### MCP Server Configuration
91+
92+
The SDK supports multiple ways to configure [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) servers that provide tools to Claude:
93+
94+
#### External Stdio Servers
95+
96+
For existing MCP servers that run as separate processes, use dictionary-based configuration. **You don't need to manually run these servers** - Claude Code automatically spawns and manages them:
97+
98+
```python
99+
from claude_agent_sdk import ClaudeAgentOptions, ClaudeSDKClient
100+
101+
options = ClaudeAgentOptions(
102+
mcp_servers={
103+
"filesystem": {
104+
"type": "stdio", # Optional, "stdio" is the default
105+
"command": "npx",
106+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/allowed/dir"],
107+
"env": {"DEBUG": "true"} # Optional environment variables
108+
},
109+
"github": {
110+
"command": "npx",
111+
"args": ["-y", "@modelcontextprotocol/server-github"],
112+
"env": {"GITHUB_TOKEN": "your-token"}
113+
}
114+
},
115+
# Pre-approve specific MCP tools to avoid permission prompts
116+
allowed_tools=["mcp__filesystem__read_file", "mcp__github__list_repos"]
117+
)
118+
119+
async with ClaudeSDKClient(options=options) as client:
120+
await client.query("List files in the allowed directory")
121+
async for msg in client.receive_response():
122+
print(msg)
123+
```
124+
125+
MCP tool names follow the pattern `mcp__<server-name>__<tool-name>`.
126+
127+
#### SSE and HTTP Servers
128+
129+
For remote MCP servers accessible via HTTP:
130+
131+
```python
132+
options = ClaudeAgentOptions(
133+
mcp_servers={
134+
"remote-sse": {
135+
"type": "sse",
136+
"url": "https://example.com/mcp/sse",
137+
"headers": {"Authorization": "Bearer token"} # Optional
138+
},
139+
"remote-http": {
140+
"type": "http",
141+
"url": "https://example.com/mcp",
142+
"headers": {"Authorization": "Bearer token"} # Optional
143+
}
144+
}
145+
)
146+
```
147+
148+
#### Using a Config File
149+
150+
You can also pass a path to an MCP configuration file:
151+
152+
```python
153+
options = ClaudeAgentOptions(
154+
mcp_servers="/path/to/mcp-config.json" # or Path object
155+
)
156+
```
157+
158+
The config file should follow the MCP configuration format:
159+
```json
160+
{
161+
"mcpServers": {
162+
"filesystem": {
163+
"command": "npx",
164+
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
165+
}
166+
}
167+
}
168+
```
169+
90170
### Custom Tools (as In-Process SDK MCP Servers)
91171

92172
A **custom tool** is a Python function that you can offer to Claude, for Claude to invoke as needed.
93173

94-
Custom tools are implemented in-process MCP servers that run directly within your Python application, eliminating the need for separate processes that regular MCP servers require.
174+
Custom tools are implemented as in-process MCP servers that run directly within your Python application, eliminating the need for separate processes that regular MCP servers require.
95175

96176
For an end-to-end example, see [MCP Calculator](examples/mcp_calculator.py).
97177

0 commit comments

Comments
 (0)