SDK MCP Servers (In-Process)
SDK MCP servers are in-process MCP servers that run directly within your Python application, eliminating the need for separate processes that regular MCP servers require.Benefits Over External Servers
- No subprocess management - Runs in the same process as your application
- Better performance - No IPC overhead for tool calls
- Simpler deployment - Single Python process instead of multiple
- Easier debugging - All code runs in the same process
- Type safety - Direct Python function calls with type hints
- Direct access - Tools have direct access to your application’s state
Creating a Simple SDK MCP Server
Use the@tool decorator to define tools and create_sdk_mcp_server() to bundle them:
MCP tool names follow the pattern
mcp__<server_name>__<tool_name>. For example, a tool named greet in a server named tools becomes mcp__tools__greet.Complete Calculator Example
Here’s a complete example with multiple tools:Tool Input Schemas
The@tool decorator supports different schema formats:
Accessing Application State
SDK tools run in-process and can access your application’s state directly:External MCP Servers
External MCP servers run as separate processes and communicate via stdio, HTTP, or SSE.Stdio Server Configuration
HTTP Server Configuration
SSE Server Configuration
Mixed Server Configuration
You can use both SDK and external MCP servers together:Checking MCP Server Status
You can check the connection status of your MCP servers:connected- Server is connected and readyfailed- Connection failedneeds-auth- Server requires authenticationpending- Connection in progressdisabled- Server is disabled
Migrating from External to SDK Servers
Loading MCP Servers from Configuration Files
You can load MCP server configurations from a JSON file:Error Handling
SDK tools can return errors by settingis_error: True:
Best Practices
Choose SDK servers when possible
Choose SDK servers when possible
SDK servers provide better performance and simpler deployment. Use external servers only when you need to integrate with existing services or languages other than Python.
Handle errors gracefully
Handle errors gracefully
Always validate inputs and handle errors in your tool functions. Return
is_error: True to indicate failures to Claude.Use descriptive names and descriptions
Use descriptive names and descriptions
Clear tool names and descriptions help Claude understand when and how to use your tools.
Keep tools focused
Keep tools focused
Each tool should do one thing well. Break complex operations into multiple focused tools.
Use allowed_tools for security
Use allowed_tools for security
Always specify
allowed_tools to control which tools Claude can access, preventing unauthorized tool usage.