Skip to main content

Overview

The Claude Agent SDK supports Model Context Protocol (MCP) servers for extending Claude’s capabilities with custom tools and resources.

McpServerConfig

Union type for all MCP server configuration types.

McpStdioServerConfig

Configuration for stdio-based MCP servers (most common).
type
Literal['stdio']
Server type. Optional for backwards compatibility (defaults to "stdio").
command
str
required
Command to execute (e.g., "node", "python", "npx").
args
list[str]
Command arguments.
env
dict[str, str]
Environment variables for the server process.

Example

McpSSEServerConfig

Configuration for Server-Sent Events (SSE) MCP servers.
type
Literal['sse']
required
Server type.
url
str
required
SSE endpoint URL.
headers
dict[str, str]
HTTP headers for the connection.

Example

McpHttpServerConfig

Configuration for HTTP-based MCP servers.
type
Literal['http']
required
Server type.
url
str
required
HTTP endpoint URL.
headers
dict[str, str]
HTTP headers for requests.

Example

McpSdkServerConfig

Configuration for in-process MCP servers using the Python MCP SDK.
type
Literal['sdk']
required
Server type.
name
str
required
Server name identifier.
instance
McpServer
required
MCP server instance from the mcp package.

Example

MCP Status Types

Types returned by ClaudeSDKClient.get_mcp_status() for querying server connection status.

McpServerConnectionStatus

  • "connected" - Server is connected and ready
  • "failed" - Connection failed (see error field)
  • "needs-auth" - Server requires authentication
  • "pending" - Connection in progress
  • "disabled" - Server is disabled

McpServerStatus

Status information for a single MCP server.
name
str
required
Server name as configured.
status
McpServerConnectionStatus
required
Current connection status.
serverInfo
McpServerInfo
Server information from MCP handshake (available when connected).
error
str
Error message (available when status is "failed").
config
McpServerStatusConfig
Server configuration (includes URL for HTTP/SSE servers).
scope
str
Configuration scope (e.g., "project", "user", "local", "claudeai", "managed").
tools
list[McpToolInfo]
Tools provided by this server (available when connected).

McpStatusResponse

Response from ClaudeSDKClient.get_mcp_status().

Example

MCP Control Methods

The SDK provides methods for controlling MCP servers:

Reconnect Server

Reconnects a disconnected or failed MCP server.

Toggle Server

Enables or disables an MCP server.

Send MCP Message

Sends a raw MCP message to a server.

Loading MCP Servers from File

You can load MCP server configurations from a JSON file:
mcp-config.json: