Skip to main content

Module sdk_mcp

Module sdk_mcp 

Source
Expand description

In-process MCP (Model Context Protocol) server support.

This module allows you to define custom tools that run within your Rust application and are exposed to Claude Code via the MCP protocol. These tools appear alongside Claude Code’s built-in tools and can be invoked by the model during conversations.

§Example

use claude_code::{tool, create_sdk_mcp_server, McpServerConfig, ToolAnnotations};
use serde_json::{json, Value};

let weather_tool = tool(
    "get_weather",
    "Get current weather for a location",
    json!({
        "type": "object",
        "properties": {
            "location": {"type": "string", "description": "City name"}
        },
        "required": ["location"]
    }),
    |args: Value| async move {
        let location = args["location"].as_str().unwrap_or("unknown");
        Ok(json!({
            "content": [{"type": "text", "text": format!("Weather in {location}: 22°C, sunny")}]
        }))
    },
);

let server_config = create_sdk_mcp_server("my-tools", "1.0.0", vec![weather_tool]);

Structs§

McpSdkServer
In-process MCP server that hosts custom tools.
SdkMcpTool
Definition of an in-process MCP tool.

Functions§

create_sdk_mcp_server
Creates an McpSdkServerConfig for use in ClaudeAgentOptions::mcp_servers.
tool
Creates a new SdkMcpTool with the given name, description, schema, and handler.

Type Aliases§

SdkMcpToolHandler
Handler function type for SDK MCP tools.