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§
- McpSdk
Server - In-process MCP server that hosts custom tools.
- SdkMcp
Tool - Definition of an in-process MCP tool.
Functions§
- create_
sdk_ mcp_ server - Creates an
McpSdkServerConfigfor use inClaudeAgentOptions::mcp_servers. - tool
- Creates a new
SdkMcpToolwith the given name, description, schema, and handler.
Type Aliases§
- SdkMcp
Tool Handler - Handler function type for SDK MCP tools.