Skip to main content
The Claude Agent SDK supports both SDK MCP servers (in-process) and external MCP servers (separate processes). SDK servers run directly within your Python application, providing better performance and simpler deployment.

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:
Server status values:
  • connected - Server is connected and ready
  • failed - Connection failed
  • needs-auth - Server requires authentication
  • pending - Connection in progress
  • disabled - 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:
The configuration file should follow the standard MCP server configuration format.

Error Handling

SDK tools can return errors by setting is_error: True:

Best Practices

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.
Always validate inputs and handle errors in your tool functions. Return is_error: True to indicate failures to Claude.
Clear tool names and descriptions help Claude understand when and how to use your tools.
Each tool should do one thing well. Break complex operations into multiple focused tools.
Always specify allowed_tools to control which tools Claude can access, preventing unauthorized tool usage.