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).
Literal['stdio']
Server type. Optional for backwards compatibility (defaults to "stdio").
str
required
Command to execute (e.g., "node", "python", "npx").
list[str]
Command arguments.
dict[str, str]
Environment variables for the server process.

Example

McpSSEServerConfig

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

Example

McpHttpServerConfig

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

Example

McpSdkServerConfig

Configuration for in-process MCP servers using the Python MCP SDK.
Literal['sdk']
required
Server type.
str
required
Server name identifier.
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.
str
required
Server name as configured.
McpServerConnectionStatus
required
Current connection status.
McpServerInfo
Server information from MCP handshake (available when connected).
str
Error message (available when status is "failed").
McpServerStatusConfig
Server configuration (includes URL for HTTP/SSE servers).
str
Configuration scope (e.g., "project", "user", "local", "claudeai", "managed").
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: