# @modelcontextprotocol/node

> Model Context Protocol implementation for TypeScript - Node.js middleware

Latest version **2.0.0** (published 2026-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @modelcontextprotocol/node
pnpm add @modelcontextprotocol/node
yarn add @modelcontextprotocol/node
bun add @modelcontextprotocol/node
```

## Health

**Score 60/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score; popular repo.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-07-27 |
| First published | 2026-04-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13425 |
| Author | Anthropic, PBC |
| Maintainers | jspahrsummers, pcarleton, fweinberger, thedsp, ochafik-ant |
| Keywords | modelcontextprotocol, mcp, node.js, middleware |

## Links

- npm: https://www.npmjs.com/package/@modelcontextprotocol/node
- Repository: https://github.com/modelcontextprotocol/typescript-sdk
- Homepage: https://modelcontextprotocol.io
- Issues: https://github.com/modelcontextprotocol/typescript-sdk/issues
- npm.io page: https://npm.io/package/@modelcontextprotocol/node

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-07-27
- 2.0.0-beta.5 — 2026-07-21
- 2.0.0-beta.4 — 2026-07-13
- 2.0.0-beta.3 — 2026-07-09
- 2.0.0-beta.2 — 2026-07-02
- 2.0.0-beta.1 — 2026-06-30
- 2.0.0-alpha.4 — 2026-06-30
- 2.0.0-alpha.3 — 2026-06-25
- 2.0.0-alpha.2 — 2026-04-01

## README

# `@modelcontextprotocol/node`

Node.js adapters for the MCP TypeScript server SDK.

This package is a thin Node.js integration layer for [`@modelcontextprotocol/server`](https://github.com/modelcontextprotocol/typescript-sdk/tree/main/packages/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

```bash
npm install @modelcontextprotocol/server @modelcontextprotocol/node
```

## Exports

- `NodeStreamableHTTPServerTransport`
- `StreamableHTTPServerTransportOptions` (type alias for `WebStandardStreamableHTTPServerTransportOptions`)
- `toNodeHandler(handler, opts?)` — adapt a web-standard `{ fetch }` MCP handler to a Node `(req, res, parsedBody?)` handler
- `hostHeaderValidation(allowedHostnames)` / `localhostHostValidation()` — `Host` header guards for hand-wired `node:http` servers
- `originValidation(allowedOriginHostnames)` / `localhostOriginValidation()` — `Origin` header guards for hand-wired `node:http` servers
- `ToNodeHandlerOptions`, `FetchLikeMcpHandler`, `NodeMcpRequestHandler` (types for `toNodeHandler`)
- `toWebRequest(req, parsedBody?, opts?)` — the Node `IncomingMessage` → web-standard `Request` conversion `toNodeHandler` performs internally, exported on its own (for example to feed `isLegacyRequest()` from a hand-wired `(req, res)` handler)
- `ToWebRequestOptions` (options type for `toWebRequest`)
- `NodeIncomingMessageLike`, `NodeServerResponseLike` (structural Node request/response shapes)

## Usage

### Express + Streamable HTTP

```ts
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

Plain `node:http` has no middleware chain, so bind loopback explicitly and
compose the `Host`/`Origin` guards in front of the transport — matching the
defaults the framework app factories (`createMcpExpressApp`,
`createMcpHonoApp`, `createMcpFastifyApp`) apply for you. The guards answer
rejected requests with `403` themselves and return `false`, so the handler
must not touch the request further.

```ts
import { createServer } from 'node:http';
import { localhostHostValidation, localhostOriginValidation, NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
import { McpServer } from '@modelcontextprotocol/server';

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

const validateHost = localhostHostValidation();
const validateOrigin = localhostOriginValidation();

createServer(async (req, res) => {
    if (!validateHost(req, res) || !validateOrigin(req, res)) return;
    const transport = new NodeStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
    await server.connect(transport);
    await transport.handleRequest(req, res);
}).listen(3000, '127.0.0.1');
```

---
_Source: https://npm.io/package/@modelcontextprotocol/node · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
