Help with setting MCP servers?
Hey guys, can someone help me with setting mcp servers? what files should I create and how to configure it to the ClaudeCodeOptions?
something like that
servers = {
# custom MCP server in my app module
"e2b-mcp-server": {
"command": "python",
"args": ["-m", "app.mcp.e2b_mcp_server"],
"env": {
"PYTHONPATH": str(Path(__file__).parent.parent.parent),
"E2B_API_KEY": e2b_api_key,
},
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": github_personal_access_token
},
},
}
options = ClaudeCodeOptions(
mcp_servers=servers,
)
I must to run this mcp server in order to use it? Can I simply create a tool (simple function to use) to pass to the Clade code? i dont want overcomplex it with McpServer ..
no you don't need to run the mcp server and I don't think claude code supports tools right now
Okay, so can u please explain to me little but more, lets say i want to use MCP for custom bash commands. I need to create the python mcp server for that (with the function), and how should i pass to Claude code this file? And if i dont run the mcp server how claude code communicates with it?
MCP server configuration is now well-documented. You can configure MCP servers in two ways:
- External MCP servers via
mcp_serversinClaudeAgentOptions:
options = ClaudeAgentOptions(
mcp_servers={
"my_server": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@your/mcp-server"]
}
}
)
- In-process SDK MCP servers via
create_sdk_mcp_server()and the@tooldecorator:
from claude_agent_sdk import tool, create_sdk_mcp_server
@tool("greet", "Greet a user", {"name": str})
async def greet(args):
return {"content": [{"type": "text", "text": f"Hello {args['name']}!"}]}
server = create_sdk_mcp_server("my_tools", tools=[greet])
options = ClaudeAgentOptions(mcp_servers={"my_tools": server})
See the SDK documentation and the examples/ directory in this repo for more details. Closing as answered.