@modelcontextprotocol/sdk is the official low-level software development kit for the Model Context Protocol (MCP), maintained by the protocol creators. It provides core classes for building MCP clients and servers with full control over transports and message handling. mcp-framework is a community-built wrapper designed to simplify server creation by reducing boilerplate code and automating transport setup. Both enable AI models to connect with external data sources, but they differ in abstraction level and maintenance backing.
Connecting AI models to external data requires a stable interface. The Model Context Protocol (MCP) provides this standard. When building servers in JavaScript, you generally choose between the official @modelcontextprotocol/sdk and community wrappers like mcp-framework. Let's compare how they handle setup, tool definitions, and server lifecycle.
@modelcontextprotocol/sdk requires you to manually configure the transport layer.
// @modelcontextprotocol/sdk: Manual transport setup
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new Server(
{ name: "my-server", version: "1.0.0" },
{ capabilities: { tools: {} } }
);
const transport = new StdioServerTransport();
await server.connect(transport);
mcp-framework abstracts the transport logic away.
// mcp-framework: Auto transport setup
import { MCP } from "mcp-framework";
const app = new MCP({
name: "my-server",
version: "1.0.0"
});
// Transport is handled internally
await app.start();
@modelcontextprotocol/sdk uses explicit schema validators for tools.
// @modelcontextprotocol/sdk: Explicit schema
import { z } from "zod";
import { ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "get_weather",
description: "Get weather data",
inputSchema: z.object({ city: z.string() }).shape
}
]
};
});
mcp-framework often simplifies tool registration with decorators or methods.
app.tool() directly.// mcp-framework: Simplified registration
app.tool("get_weather", {
description: "Get weather data",
params: { city: "string" }
}, async (args) => {
return { data: `Weather in ${args.city}` };
});
@modelcontextprotocol/sdk exposes raw protocol errors.
// @modelcontextprotocol/sdk: Manual error handling
server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
// Tool logic
return { content: [] };
} catch (error) {
console.error("Tool failed:", error);
throw error; // Propagates to MCP client
}
});
mcp-framework often includes global error hooks.
// mcp-framework: Global error hook
app.onError((error, toolName) => {
console.error(`Tool ${toolName} failed:`, error);
// Framework handles response formatting
});
@modelcontextprotocol/sdk is updated directly by the protocol maintainers.
// @modelcontextprotocol/sdk: Direct access to new features
// When protocol updates, you update this package
import { NewFeatureSchema } from "@modelcontextprotocol/sdk/types.js";
mcp-framework depends on the community maintainer updating the wrapper.
// mcp-framework: Waiting for wrapper update
// You might need to wait for the framework to support new protocol features
// or drop down to the underlying SDK manually
Despite the differences in abstraction, both packages rely on the same underlying protocol standards.
// Both send standard JSON-RPC payloads
// { jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }
// Both require explicit transport config for network access
// SDK: new SseServerTransport()
// Framework: app.configure({ transport: 'sse' })
// Tool shape is consistent across both
// { name: "...", description: "...", inputSchema: {...} }
| Feature | @modelcontextprotocol/sdk | mcp-framework |
|---|---|---|
| Maintenance | 🟢 Official Team | 🟡 Community Maintainer |
| Setup | 🛠️ Manual Transport | ⚡ Auto Transport |
| Tool Definition | 📝 Explicit Schemas | 🚀 Simplified Methods |
| Control | 🎛️ Full Low-Level Access | 📦 Abstracted |
| Update Speed | 🚀 Immediate Protocol Support | ⏳ Depends on Wrapper |
| Best For | 🏢 Production Systems | 🧪 Prototypes & Internal Tools |
@modelcontextprotocol/sdk is like building with raw materials 🧱 — you have full control over every brick and beam. It is the right choice for teams building critical infrastructure where stability and direct protocol support are non-negotiable.
mcp-framework is like using a prefabricated kit 🏠 — you get walls and roofs instantly. It is perfect for hacking together a quick demo or internal tool where speed matters more than long-term maintenance guarantees.
Final Thought: If you are building something you plan to maintain for years, stick with the official SDK. If you need to show a working prototype by tomorrow, the framework will get you there faster — just be ready to refactor later.
Choose the official SDK if you need long-term stability, full control over transport layers, and direct alignment with protocol updates. It is the safest choice for production systems where reliability and official support matter most. You will write more setup code, but you avoid dependencies on third-party abstractions that might lag behind protocol changes.
Choose mcp-framework if you want to prototype quickly or prefer a simpler API that hides transport complexity. It is suitable for internal tools or experiments where developer speed is more important than strict adherence to the official maintenance cycle. Be aware that community wrappers may require more effort to update when the core protocol changes.
The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This TypeScript SDK implements the full MCP specification, making it easy to:
npm install @modelcontextprotocol/sdk zod
This SDK has a required peer dependency on zod for schema validation. The SDK internally imports from zod/v4, but maintains backwards compatibility with projects using Zod v3.25 or later. You can use either API in your code by importing from zod/v3 or zod/v4:
To see the SDK in action end-to-end, start from the runnable examples in src/examples:
Install dependencies (from the SDK repo root):
npm install
Run the example Streamable HTTP server:
npx tsx src/examples/server/simpleStreamableHttp.ts
Run the interactive client in another terminal:
npx tsx src/examples/client/simpleStreamableHttp.ts
This pair of examples demonstrates tools, resources, prompts, sampling, elicitation, tasks and logging. For a guided walkthrough and variations (stateless servers, JSON-only responses, SSE compatibility, OAuth, etc.), see docs/server.md and docs/client.md.
An MCP server is typically created with McpServer and connected to a transport such as Streamable HTTP or stdio. The SDK supports:
Runnable server examples live under src/examples/server and are documented in docs/server.md.
The detailed APIs, including ResourceTemplate, completions, and display-name metadata, are covered in docs/server.md, with runnable implementations in simpleStreamableHttp.ts.
The SDK includes higher-level capabilities for richer workflows:
Conceptual overviews and links to runnable examples are in:
Key example servers include:
The high-level Client class connects to MCP servers over different transports and exposes helpers like listTools, callTool, listResources, readResource, listPrompts, and getPrompt.
Runnable clients live under src/examples/client and are described in docs/client.md, including:
simpleStreamableHttp.ts)streamableHttpWithSseFallbackClient.ts)Some parts of the SDK (for example, JWT-based client authentication in auth-extensions.ts via jose) rely on the Web Crypto API exposed as globalThis.crypto.
See docs/faq.md for details on supported Node.js versions and how to polyfill globalThis.crypto when running on older Node.js runtimes.
The SDK ships runnable examples under src/examples. Use these tables to find the scenario you care about and jump straight to the corresponding code and docs.
| Scenario | Description | Example file(s) | Related docs |
|---|---|---|---|
| Streamable HTTP server (stateful) | Feature-rich server with tools, resources, prompts, logging, tasks, sampling, and optional OAuth. | simpleStreamableHttp.ts | server.md, capabilities.md |
| Streamable HTTP server (stateless) | No session tracking; good for simple API-style servers. | simpleStatelessStreamableHttp.ts | server.md |
| JSON response mode (no SSE) | Streamable HTTP with JSON responses only and limited notifications. | jsonResponseStreamableHttp.ts | server.md |
| Server notifications over Streamable HTTP | Demonstrates server-initiated notifications using SSE with Streamable HTTP. | standaloneSseWithGetStreamableHttp.ts | server.md |
| Deprecated HTTP+SSE server | Legacy HTTP+SSE transport for backwards-compatibility testing. | simpleSseServer.ts | server.md |
| Backwards-compatible server (Streamable HTTP + SSE) | Single server that supports both Streamable HTTP and legacy SSE clients. | sseAndStreamableHttpCompatibleServer.ts | server.md |
| Form elicitation server | Uses form elicitation to collect non-sensitive user input. | elicitationFormExample.ts | capabilities.md |
| URL elicitation server | Demonstrates URL-mode elicitation in an OAuth-protected server. | elicitationUrlExample.ts | capabilities.md |
| Sampling and tasks server | Combines tools, logging, sampling, and experimental task-based execution. | toolWithSampleServer.ts | capabilities.md |
| OAuth demo authorization server | In-memory OAuth provider used with the example servers. | demoInMemoryOAuthProvider.ts | server.md |
| Scenario | Description | Example file(s) | Related docs |
|---|---|---|---|
| Interactive Streamable HTTP client | CLI client that exercises tools, resources, prompts, elicitation, and tasks. | simpleStreamableHttp.ts | client.md |
| Backwards-compatible client (Streamable HTTP → SSE) | Tries Streamable HTTP first, then falls back to SSE on 4xx responses. | streamableHttpWithSseFallbackClient.ts | client.md, server.md |
| SSE polling client | Polls a legacy SSE server and demonstrates notification handling. | ssePollingClient.ts | client.md |
| Parallel tool calls client | Shows how to run multiple tool calls in parallel. | parallelToolCallsClient.ts | client.md |
| Multiple clients in parallel | Demonstrates connecting multiple clients concurrently to the same server. | multipleClientsParallel.ts | client.md |
| OAuth clients | Examples of client_credentials (basic and private_key_jwt) and reusable providers. | simpleOAuthClient.ts, simpleOAuthClientProvider.ts, simpleClientCredentials.ts | client.md |
| URL elicitation client | Works with the URL elicitation server to drive secure browser flows. | elicitationUrlExample.ts | capabilities.md |
Shared utilities:
inMemoryEventStore.ts (see server.md).For more details on how to run these examples (including recommended commands and deployment diagrams), see src/examples/README.md.
Issues and pull requests are welcome on GitHub at https://github.com/modelcontextprotocol/typescript-sdk.
This project is licensed under the MIT License—see the LICENSE file for details.