mcp-sdk-typescript
Production-ready MCP SDK for TypeScript with automatic Bun optimization, streamable HTTP transport, and real-time session management
claude mcp add --transport stdio the-ihor-mcp-sdk-typescript node path/to/server.js \ --env NODE_ENV="production" \ --env MCP_LOG_LEVEL="info"
How to use
The MCP SDK for TypeScript provides a type-safe framework to build streaming MCP servers with real-time communication over HTTP. It exposes an MCPApp for registering tools, a StreamableHttpTransport that handles runtime-optimized transport (Bun or Node.js) and Server-Sent Events, and a rich set of response types (TextResponse, ProgressResponse, LogResponse, ErrorResponse, RawResponse, etc.). You can define tools with schemas using Zod for validation and implement async generator handlers to yield streaming responses as the client consumes them. This setup enables production-grade session management, error handling, and memory management while offering an architecture that scales for real-time, long-running interactions. Use the SDK to create an MCP server project scaffold, register tools such as an echo service or a long-running processor, and rely on the transport layer to manage SSE streams and session correlation across Bun or Node.js runtimes.
How to install
Prerequisites:
- Node.js (and optionally Bun for best performance)
- Basic TypeScript project setup (tsconfig, npm/yarn/pnpm)
Install the MCP SDK library into your project:
# Using Bun (recommended for performance)
bun add @the-ihor/mcp-sdk-typescript
# Using npm/Node.js
npm install @the-ihor/mcp-sdk-typescript
# Using yarn
yarn add @the-ihor/mcp-sdk-typescript
If you plan to scaffold a full MCP server project using the provided CLI, install the CLI tool as well (example usage shown in Quick Start):
# Create a new MCP server project (via Bun or NPX)
bunx @the-ihor/adi-create-mcp-server
# or
npx @the-ihor/adi-create-mcp-server
Configure TypeScript and build steps according to your chosen runtime (Bun or Node.js). For example, ensure your tsconfig.json aligns with module resolution and target ES version, and include a build script if you are compiling TS to JS for Node environments.
Additional notes
Tips and common considerations:
- Runtime detection automatically selects Bun.serve when running under Bun; otherwise Node.js HTTP server is used. Ensure your environment supports SSE and persistent streaming.
- Use the provided response types (TextResponse, ProgressResponse, LogResponse, etc.) to convey structured data and progress updates to clients.
- Implement proper session management by leveraging the transport layer, which maps requests to responses via session IDs.
- When debugging, enable verbose logging and inspect transport-level errors, as they often indicate transport or network issues rather than application logic failures.
- If you plan to publish tooling (CLI scaffolds), keep tool schemas in sync with Zod validators to ensure end-user requests are validated server-side.
- For production, monitor memory management around long-lived streams and implement cancellation or cleanup for expired sessions.
Related MCP Servers
mcp-agent
Lightweight, focused utilities to manage connections and execute MCP tools with minimal integration effort. Use it to directly call tools or build simple agents within your current architecture.
docmole
Dig through any documentation with AI - MCP server for Claude, Cursor, and other AI assistants
obsidian
MCP server for Obsidian vault management - enables Claude and other AI assistants to read, write, search, and organize your notes
civitai
A Model Context Protocol server for browsing and discovering AI models on Civitai
logseq
Model Context Protocol server for Logseq knowledge base integration with AI assistants
voicepeak
MCP server for VOICEPEAK text-to-speech synthesis