Production-ready, horizontally scalable TypeScript implementation for building MCP servers and clients
The Model Context Protocol (MCP) is revolutionizing how AI agents interact with tools, data, and services. As adoption accelerates, the need for enterprise-grade infrastructure becomes critical.
This project provides a complete, production-ready MCP implementation designed from the ground up for:
- Horizontal scalability β Run multiple server instances behind load balancers
- Session persistence β Maintain client state across restarts and scaling events
- Full observability β Correlate logs, metrics, and traces across distributed systems
- Protocol compliance β Wire-compatible with the official MCP SDK
- Extensibility β Add custom features without forking core protocol logic
Our goal: Make it easy to build scalable, reliable, and observable MCP serversβfrom startup MVPs to enterprise deployments.
We took a protocol-first approach: instead of building high-level abstractions that hide the protocol, we built a modular, layered architecture that gives you full control while reducing boilerplate.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Application β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Server/Client Classes β Feature System β Custom Extensions β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Protocol Layer β
β (Connection management, request/response correlation, lifecycle) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Schema Validation (Standard Schema) β Session Management β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Transport Layer β
β (Pluggable: HTTP, stdio, distributed brokers, WebRTC, etc.) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββ
β Load Balancer β
βββββββββββββββ¬ββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β β β
ββββββββββΌβββββββββ ββββββββββΌβββββββββ ββββββββββΌβββββββββ
β HTTP Node 1 β β HTTP Node 2 β β HTTP Node 3 β
β (Transport) β β (Transport) β β (Transport) β
ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ
β β β
βββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββββββββ
β EventBroker β
β (NATS / Kafka / Redis / ...) β
βββββββββββββββ¬ββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β β β
ββββββββββΌβββββββββ ββββββββββΌβββββββββ ββββββββββΌβββββββββ
β Worker 1 β β Worker 2 β β Worker 3 β
β (MCP Handler) β β (MCP Handler) β β (MCP Handler) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
This monorepo contains a suite of packages for building MCP infrastructure:
| Package | npm | Description |
|---|---|---|
| model-context-protocol-specification | Canonical TypeScript types and Zod v4 schemas for all MCP message types. Foundation for type-safe MCP development. | |
| model-context-protocol-sdk | Core SDK with Protocol, Server, and Client implementations. Feature-based architecture for tools, resources, prompts, and completions. | |
| model-context-protocol-framework | Higher-level abstractions and patterns for common MCP use cases. (Coming soon) |
| Package | npm | Description |
|---|---|---|
| model-context-protocol-distributed-streamable-http-server-transport | Enterprise HTTP transport with EventBroker abstraction for horizontal scaling. Supports NATS, Kafka, Redis, or custom brokers. | |
| model-context-protocol-webrtc-transport | WebRTC transport for real-time, peer-to-peer MCP connections. (In development) |
| Package | npm | Description |
|---|---|---|
| model-context-protocol-opentelemetry-instrumentation | OpenTelemetry instrumentation for automatic tracing, metrics, and log correlation. (In development) |
In distributed systems, sessions are everything. They're your routing key, persistence boundary, and observability anchor.
// Every handler receives full session context
tools.registerTool(myTool, async (args, context, info) => {
const session = context.session;
// Access session state
const userPrefs = session.getValue<UserPrefs>('preferences');
// Session metadata for observability
console.log(`[${session.id}] Processing tool call`);
return await processWithSession(args, session);
});Instead of monolithic handlers, we use a composable feature system:
const server = new Server({
serverInfo: { name: "my-server", version: "1.0.0" },
capabilities: {
tools: { listChanged: true },
resources: { subscribe: true },
prompts: {}
}
});
// Features are self-contained and reusable
server.addFeature(new ToolsFeature(myTools));
server.addFeature(new ResourcesFeature(myResources));
server.addFeature(new PromptsFeature(myPrompts));
server.addFeature(new MyCustomFeature());The protocol layer knows nothing about HTTP, WebSockets, or message brokers:
// Same server logic, different transports
const server = new Server({ /* ... */ });
// Local development with stdio
await server.connect(stdioTransport);
// Production with distributed HTTP
await server.connect(distributedHttpTransport);
// Real-time with WebRTC
await server.connect(webRTCTransport);We don't hide validationβwe make it explicit and pluggable:
import { StandardSchemaValidator, defaultSchemaResolver } from "model-context-protocol-sdk/protocol";
const server = new Server({
schemaValidator: new StandardSchemaValidator(),
schemaResolver: defaultSchemaResolver,
enforceSchemaValidation: true
});Compatible with Zod v4, Valibot, ArkType, or any Standard Schema-compatible validator.
Every layer is designed for observability with lifecycle hooks:
onBeforeSendRequest/onAfterSendRequestonBeforeSendNotification/onAfterSendNotificationonBeforeReceive/onAfterReceive
| Aspect | Official SDK | This SDK |
|---|---|---|
| Goal | Quick start, batteries included | Enterprise scale, full control |
| Transport | Bundled transports | Transport interface + plugins |
| Sessions | Transport-managed | First-class protocol concept |
| Validation | Optional, built-in | Explicit, pluggable (Standard Schema) |
| Handlers | Direct method handlers | Feature-based composition |
| Distributed | Single-node focus | Distributed-first design |
| Observability | Basic callbacks | Structured hooks + correlation |
Use the Official SDK when:
- Building a quick prototype or demo
- Single-node deployment is sufficient
- You want maximum convenience with minimal configuration
Use this SDK when:
- Building production infrastructure
- Planning horizontal scaling
- Need fine-grained control over protocol behavior
- Integrating with existing observability stack
- Building custom transports or extensions
npm install model-context-protocol-sdk
# For runtime validation (recommended)
npm install zod @standard-schema/specimport { Server, ToolsFeature } from "model-context-protocol-sdk/server";
const server = new Server({
serverInfo: { name: "my-server", version: "1.0.0" },
capabilities: { tools: { listChanged: true } },
instructions: "This server provides utility tools."
});
const tools = new ToolsFeature();
tools.registerTool(
{
name: "greet",
description: "Generate a greeting",
inputSchema: {
type: "object",
properties: { name: { type: "string" } },
required: ["name"]
}
},
async (args) => ({
content: [{ type: "text", text: `Hello, ${(args as any).name}!` }]
})
);
server.addFeature(tools);
await server.connect(transport);import { Client } from "model-context-protocol-sdk/client";
const client = new Client();
await client.connect(transport);
const result = await client.request({
method: "tools/call",
params: { name: "greet", arguments: { name: "World" } }
}, { route: { sessionId } });model-context-protocol/
βββ packages/
β βββ specification/ # Types & Zod schemas
β βββ sdk/ # Core Protocol, Server, Client
β βββ framework/ # High-level abstractions
β βββ transports/
β β βββ server/
β β β βββ distributed-streamable-http/
β β βββ webrtc-transport/
β βββ opentelemetry/
β βββ instrumentation/
βββ examples/
β βββ server/ # Complete example server
βββ e2e/
β βββ server/ # E2E tests with official & our client
βββ nx.json # Nx workspace config
βββ package.json
- Node.js 20+
- pnpm 9+
pnpm installpnpm nx run-many -t build# Unit tests
pnpm nx run-many -t test
# E2E tests (start server first)
pnpm nx serve server # Terminal 1
pnpm nx test e2e-server # Terminal 2pnpm nx serve server
# Server runs at http://localhost:3333/mcpThrough building this implementation, we discovered several insights about MCP in production:
The MCP spec leaves session management largely to implementers. In distributed systems, this becomes the central challenge. We found that treating sessions as first-class routing keys (rather than transport concerns) dramatically simplifies horizontal scaling.
Protocol boundaries are trust boundaries. While the official SDK offers optional validation, production systems benefit from explicit, always-on validation. Our Standard Schema integration makes this pluggable while maintaining performance.
Large MCP servers with many tools/resources become unwieldy with direct handler registration. Our feature-based architecture enables:
- Testing features in isolation
- Reusing features across servers
- Third-party feature packages
By strictly separating transport from protocol, we enabled transports the official SDK doesn't support:
- Distributed HTTP: Multiple nodes sharing a message broker
- WebRTC: Browser-to-server without HTTP
- Custom brokers: NATS, Kafka, Redis Streams, etc.
- Core SDK (Protocol, Server, Client)
- Specification package with Zod v4 schemas
- Distributed Streamable HTTP transport
- E2E test suite with official SDK compatibility
- OpenTelemetry instrumentation
- WebRTC transport
- Framework package with common patterns
- Stdio transport
- Authentication middleware examples
- Kubernetes deployment guides
We're building this in the open because we believe MCP infrastructure should be a community effort.
- Issues: Bug reports, feature requests, questions
- PRs: Bug fixes, documentation, new features
- Discussions: Architecture decisions, use cases, best practices
- SDK Documentation β Core SDK guide
- Distributed Transport β Scaling guide
- Example Server β Working example
- E2E Tests β Test patterns
- MCP Specification β Official protocol docs
This project is fully open-source under the GNU Affero General Public License v3.0 (AGPLv3). See LICENSE for the complete terms.
If you're interested in an enterprise license with different terms, please contact: operator@tsok.org