A progressive Node.js framework for building efficient and scalable server-side applications.
Model Context Protocol module for Nest: tools, resources and prompts are methods of your providers, declared with decorators and a schema (Zod, ArkType, Valibot or JSON Schema), and run through Nest's guards, interceptors, pipes and exception filters. The server is served over Streamable HTTP from your existing Nest application (Express, Fastify or the Node adapter), statelessly so it scales behind any load balancer, to clients of both the 2026-07-28 and the 2025 protocol revisions, and over stdio from a standalone application context. It can act as an OAuth 2.1 resource server with protected resource metadata, WWW-Authenticate challenges, per-tool scopes and a token verifier of your own, and comes with an in-memory test client. Built on the official MCP TypeScript SDK (@modelcontextprotocol/server).
$ npm i --save @nestjs/mcp @modelcontextprotocol/server zodZod 4.2 or later; any other Standard Schema library that produces JSON Schema works too.
Import the module, and decorate the methods of a provider:
import { Injectable, Module } from '@nestjs/common';
import { McpModule, Resource, Tool, type McpContext } from '@nestjs/mcp';
import * as z from 'zod';
@Injectable()
export class NotesTools {
constructor(private readonly notes: NotesService) {}
@Tool({
description: 'Save a note',
inputSchema: z.object({ text: z.string().describe('What to remember') }),
})
add({ text }: { text: string }, ctx: McpContext) {
return this.notes.add(text, ctx.authInfo?.clientId);
}
@Resource({ uri: 'notes://all', mimeType: 'application/json' })
all() {
return this.notes.all();
}
}
@Module({
imports: [McpModule.forRoot({ name: 'notes', version: '1.0.0' })],
providers: [NotesService, NotesTools],
})
export class AppModule {}app.listen(3000) now serves the MCP endpoint at http://localhost:3000/mcp, a route like any other (the global prefix and middleware apply to it). Guards, interceptors, pipes and filters run around every call; McpExecutionContext.create(context) reads the call in them, as GqlExecutionContext does for GraphQL.
The sample is a notes server with a guard and an interceptor, served over HTTP and stdio: npm run build && npx tsc -p sample/tsconfig.json, then node sample/dist/main.js (HTTP) or node sample/dist/stdio.js (stdio).
Read Overview & Tutorial to get started and for the module's options, Primitives for tools, resources, prompts, guards and authorization, Transports for the HTTP endpoint and stdio, and Testing for the in-memory client.
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
Nest is MIT licensed.