typescript-sdk/packages/middleware/node
Repository files (latest commit first)
Filename Latest commit message Latest commit date
github-actions[bot] e4227d135c
Version Packages (alpha) (#1845)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2026-06-25 20:44:33 +01:00
..
src chore: switch to module ESNext + moduleResolution bundler (#2095) 2026-06-25 11:49:17 +01:00
test v2: codemod iterations, canonical zod schema exports from sdk-shared (#2354) 2026-06-25 19:42:44 +01:00
CHANGELOG.md Version Packages (alpha) (#1845) 2026-06-25 20:44:33 +01:00
eslint.config.mjs v2: codemod iterations, canonical zod schema exports from sdk-shared (#2354) 2026-06-25 19:42:44 +01:00
package.json Version Packages (alpha) (#1845) 2026-06-25 20:44:33 +01:00
README.md fix: resolve TypeDoc warnings from directory-pointing relative links (#1546) 2026-02-17 23:25:54 +00:00
tsconfig.json v2: codemod iterations, canonical zod schema exports from sdk-shared (#2354) 2026-06-25 19:42:44 +01:00
tsdown.config.ts fix(middleware): stop bundling workspace type graphs into .d.ts (avoids dts-gen OOM) (#2339) 2026-06-23 10:26:49 +01:00
typedoc.json Add API documentation with GitHub Pages deployment (#1109) 2026-01-20 17:22:24 +02:00
vitest.config.js [v2] Decouple server from express and hono - http framework-agnostic MCP server (#1326) 2026-01-16 12:13:25 +02:00

@modelcontextprotocol/node

Node.js adapters for the MCP TypeScript server SDK.

This package is a thin Node.js integration layer for @modelcontextprotocol/server. It provides a Streamable HTTP transport that works with Node’s IncomingMessage / ServerResponse.

For web‑standard runtimes (Cloudflare Workers, Deno, Bun, etc.), use WebStandardStreamableHTTPServerTransport from @modelcontextprotocol/server directly.

Install

npm install @modelcontextprotocol/server @modelcontextprotocol/node

Exports

  • NodeStreamableHTTPServerTransport
  • StreamableHTTPServerTransportOptions (type alias for WebStandardStreamableHTTPServerTransportOptions)

Usage

Express + Streamable HTTP

import { createMcpExpressApp } from '@modelcontextprotocol/express';
import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
import { McpServer } from '@modelcontextprotocol/server';

const server = new McpServer({ name: 'my-server', version: '1.0.0' });
const app = createMcpExpressApp();

app.post('/mcp', async (req, res) => {
    const transport = new NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
    await server.connect(transport);

    // If you use Express JSON parsing, pass the pre-parsed body to avoid re-reading the stream.
    await transport.handleRequest(req, res, req.body);
});

Node.js http server

import { createServer } from 'node:http';
import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
import { McpServer } from '@modelcontextprotocol/server';

const server = new McpServer({ name: 'my-server', version: '1.0.0' });

createServer(async (req, res) => {
    const transport = new NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
    await server.connect(transport);
    await transport.handleRequest(req, res);
}).listen(3000);