What Is the MCP SDK?
The MCP SDK is the official collection of libraries published by Anthropic for building Model Context Protocol servers and clients. Rather than implementing the full JSON-RPC protocol, connection management, and capability negotiation yourself, you use the SDK and focus on writing your tool implementations.
The SDK handles the boring parts of MCP: message framing, transport lifecycle, schema validation, error formatting, and the initialization handshake. You handle the interesting parts: what your tools actually do.
Quick Definition#
The MCP SDK is a set of official libraries (TypeScript, Python, and community variants for other languages) that abstract MCP protocol details so developers can focus on building tools, resources, and prompts rather than protocol implementation.
The Two Primary SDKs#
TypeScript SDK: @modelcontextprotocol/sdk#
Published to npm under the @modelcontextprotocol organization. This is the reference implementation and tends to receive new MCP features first.
Installation:
npm install @modelcontextprotocol/sdk
# or
pnpm add @modelcontextprotocol/sdk
Requirements: Node.js 18+
Package structure: The SDK uses ESM modules with subpath imports. Key entry points:
@modelcontextprotocol/sdk/server/mcp.js—McpServerclass for building servers@modelcontextprotocol/sdk/server/stdio.js—StdioServerTransport@modelcontextprotocol/sdk/server/sse.js—SSEServerTransport@modelcontextprotocol/sdk/client/index.js—Clientclass for building clients@modelcontextprotocol/sdk/client/stdio.js—StdioClientTransport@modelcontextprotocol/sdk/client/sse.js—SSEClientTransport
Minimal TypeScript MCP server:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({
name: "weather-server",
version: "1.0.0",
});
// Register a tool using Zod for schema validation
server.tool(
"get_weather",
"Get current weather for a city",
{
city: z.string().describe("City name"),
units: z.enum(["celsius", "fahrenheit"]).default("celsius"),
},
async ({ city, units }) => {
const data = await fetchWeatherAPI(city, units);
return {
content: [{ type: "text", text: `${city}: ${data.temp}° ${data.condition}` }],
};
}
);
// Start the server over stdio transport
const transport = new StdioServerTransport();
await server.connect(transport);
The TypeScript SDK integrates with Zod for schema validation, which gives you both TypeScript type safety and the JSON Schema definitions that MCP uses for capability descriptions.
Python SDK: mcp#
Published to PyPI as the mcp package. Maintained by Anthropic with feature parity to the TypeScript SDK for all stable MCP features.
Installation:
pip install mcp
# or with uv:
uv add mcp
# For HTTP/SSE transport support:
pip install "mcp[fastapi]"
Requirements: Python 3.10+
Minimal Python MCP server:
import mcp.server.stdio
from mcp.server import Server
from mcp.server.models import InitializationOptions
from mcp.types import Tool, TextContent
import mcp.types as types
server = Server("weather-server")
@server.list_tools()
async def list_tools() -> list[Tool]:
return [
Tool(
name="get_weather",
description="Get current weather for a city",
inputSchema={
"type": "object",
"properties": {
"city": {"type": "string", "description": "City name"},
"units": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["city"],
},
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict) -> list[types.ContentBlock]:
if name == "get_weather":
city = arguments["city"]
units = arguments.get("units", "celsius")
data = await fetch_weather_api(city, units)
return [TextContent(type="text", text=f"{city}: {data['temp']}° {data['condition']}")]
raise ValueError(f"Unknown tool: {name}")
async def main():
async with mcp.server.stdio.stdio_server() as (read_stream, write_stream):
await server.run(
read_stream,
write_stream,
InitializationOptions(
server_name="weather-server",
server_version="1.0.0",
capabilities=server.get_capabilities(),
),
)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
The Python SDK uses decorator-based registration (similar to FastAPI) and asyncio for concurrency.
High-Level Server Pattern: McpServer vs. Low-Level Server#
Both SDKs offer two levels of abstraction:
High-Level (Recommended for most use cases)#
TypeScript: McpServer class with .tool(), .resource(), and .prompt() methods.
Python: FastMCP class (as of late 2025) with decorator-based registration.
The high-level API handles routing, schema conversion, and error wrapping automatically. Use this unless you have a specific reason to drop to the low level.
Low-Level (For advanced use cases)#
TypeScript: Server class where you manually implement ListToolsRequestSchema and CallToolRequestSchema handlers.
Python: Server class with @server.list_tools() and @server.call_tool() decorators.
Use the low level when you need dynamic tool registration (tools change at runtime), custom capability negotiation, or fine-grained control over protocol messages. See advanced MCP patterns for examples.
Resources and Prompts: Beyond Tools#
The SDK supports all three MCP primitive types:
Resources#
Read-only data the AI can access. Registered with a URI scheme:
server.resource(
"config://app",
"Application configuration",
async () => ({
contents: [{
uri: "config://app",
text: JSON.stringify(await loadAppConfig()),
mimeType: "application/json",
}],
})
);
Prompts#
Reusable prompt templates with parameters:
server.prompt(
"analyze_logs",
"Analyze application logs for errors",
{ timeRange: z.string().describe("Time range like '1h' or '24h'") },
async ({ timeRange }) => ({
messages: [{
role: "user",
content: {
type: "text",
text: `Analyze the following logs from the last ${timeRange} and identify errors:\n\n${await fetchLogs(timeRange)}`,
},
}],
})
);
Community SDKs#
Beyond the official TypeScript and Python SDKs, community-maintained implementations exist for other languages:
| Language | Package | Status |
|---|---|---|
| Go | github.com/mark3labs/mcp-go | Active |
| Rust | mcp-sdk-rs (crates.io) | Active |
| Java | io.github.stephanj:mcp4j | Active |
| C# / .NET | ModelContextProtocol (NuGet) | Active |
| Ruby | mcp-rb | Early |
| Swift | Community packages | Early |
Community SDKs vary in how closely they track the spec. For production use, verify that the SDK version you are using supports the specific MCP spec version your client requires.
SDK Versioning and the MCP Spec#
The SDKs follow the MCP specification version. When Anthropic updates the spec, the SDK releases a new version. Key things to know:
- The TypeScript SDK package version does not directly correspond to the MCP spec version — check the package changelog for which spec features are supported.
- The
initializehandshake includes aprotocolVersionfield; both client and server SDKs negotiate which spec version to use. - Using mismatched SDK versions (very old client, very new server) may result in the negotiated version falling back to an older feature set.
Debugging and Testing Tools#
The MCP SDK ecosystem includes tools for development:
- MCP Inspector: A browser-based debugging tool that connects to your server and lets you call tools manually. Run it with
npx @modelcontextprotocol/inspector. See the test and debug MCP server tutorial for a complete walkthrough. - Claude Desktop: The fastest way to test an stdio server in a real client environment.
- SDK test utilities: Both SDKs include
InMemoryTransportfor writing unit tests that test your tool logic without launching real processes.
Getting Started Paths#
For TypeScript developers:
npm install @modelcontextprotocol/sdk zod- Build a custom MCP server
- Test with MCP Inspector
- Add to Claude Desktop config
- Deploy remotely following the deploy remote MCP server tutorial
For Python developers:
pip install mcp- Build a server following the Python examples in the build MCP server tutorial
- Test with
mcp dev your_server.py(the SDK includes a dev mode) - Package and deploy
Related Terms#
Browse all terms in the AI agent glossary.
- MCP Server — what you build with the server side of the SDK
- MCP Client — what you build with the client side of the SDK
- MCP Transport — how SDK-built servers and clients communicate
- Agent SDK — broader category of SDKs for building AI agents
- Model Context Protocol — the specification the SDK implements
Frequently Asked Questions#
Is the MCP SDK open source?
Yes. Both the TypeScript SDK (@modelcontextprotocol/sdk) and Python SDK (mcp) are published under the MIT license. The source code is at github.com/modelcontextprotocol/typescript-sdk and github.com/modelcontextprotocol/python-sdk respectively. Anthropic actively maintains both repositories and accepts community contributions.
Do I need to use the official SDK, or can I implement MCP from scratch?
You can implement MCP from scratch — it is a JSON-RPC 2.0 protocol with well-documented message schemas available at modelcontextprotocol.io. However, the SDKs handle substantial complexity including transport abstraction, capability negotiation, message routing, and error formatting. Implementing this correctly from scratch is several weeks of work. Use the SDK unless you have a language that no SDK covers and cannot use one of the community SDKs.
How do I keep my server updated as the MCP spec evolves?
Follow the @modelcontextprotocol/sdk or mcp package changelogs for breaking changes. Subscribe to the modelcontextprotocol GitHub organization for spec updates. New spec versions are typically negotiated backward-compatibly in the initialize handshake — your server will continue to work with older clients, just without access to newer features. Plan SDK updates with the same care you would give any core infrastructure dependency.