NestJS MCP server
Commit Nov 15, 2026Integrates Model Context Protocol into NestJS applications to expose tools, resources, and prompts via decorators and standard NestJS middleware.
Also known as nestjs/mcp, @nestjs/mcp
- Stars
- 15
- Tools
- —
- Downloads, 30 days
- —
- Latest version
- —
- Last commit
- Nov 15, 2026
- License
- MIT
What is NestJS MCP?
NestJS integrates Model Context Protocol into NestJS applications to expose tools, resources, and prompts via decorators and standard NestJS middleware.
Summary generated from the project's README
About NestJS MCP server
This module integrates the Model Context Protocol into NestJS applications, allowing developers to expose tools, resources, and prompts through standard provider methods. By using decorators, you can define your MCP interface directly within your existing backend architecture. It supports schema validation using Zod, ArkType, Valibot, or JSON Schema to ensure input integrity for every tool call.
Developers can deploy the server using Streamable HTTP via Express, Fastify, or the Node adapter, making it suitable for stateless scaling behind load balancers. It also supports stdio for standalone application contexts. The implementation is compatible with both the 2025 and 2026-07-28 protocol revisions. Because it runs through standard NestJS middleware, you can apply guards, interceptors, pipes, and exception filters to your MCP endpoints. It can even function as an OAuth 2.1 resource server with per-tool scopes and custom token verification.
What you can do with it
- 1Expose backend logic as toolsTurn existing service methods into MCP tools by applying decorators and input schemas.
- 2Secure MCP endpoints with middlewareApply standard NestJS guards and interceptors to control access to your protocol resources.
- 3Deploy scalable MCP servicesServe your MCP server over HTTP to allow it to scale behind a load balancer.
- 4Implement OAuth 2.1 securityUse the module as a resource server that supports protected metadata and per-tool scopes.
Written from the project's README. Every use case is checked against a quote from it.
How to install NestJS MCP
Formats verified 10 Nov 2026Add to CursorAdd to GooseInstall NestJS MCP in Claude Code
$ claude mcp add mcp -- npx -y @nestjs/mcpInstall NestJS MCP in Cursor
~/.cursor/mcp.json
{
"mcpServers": {
"mcp": {
"command": "npx",
"args": [
"-y",
"@nestjs/mcp"
]
}
}
}Install NestJS MCP in VS Code
.vscode/mcp.json
{
"servers": {
"mcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@nestjs/mcp"
]
}
}
}Install NestJS MCP in VS Code CLI
$ code --add-mcp '{"name":"mcp","type":"stdio","command":"npx","args":["-y","@nestjs/mcp"]}'Install NestJS MCP in Claude Desktop
claude_desktop_config.json
{
"mcpServers": {
"mcp": {
"command": "npx",
"args": [
"-y",
"@nestjs/mcp"
]
}
}
}Install NestJS MCP in Codex
$ codex mcp add mcp -- npx -y @nestjs/mcpInstall NestJS MCP in Codex config.toml
~/.codex/config.toml
[mcp_servers.mcp] command = "npx" args = ["-y", "@nestjs/mcp"]
Install NestJS MCP in Gemini CLI
$ gemini mcp add -s user mcp npx -- -y @nestjs/mcpInstall NestJS MCP in Gemini settings.json
~/.gemini/settings.json
{
"mcpServers": {
"mcp": {
"command": "npx",
"args": [
"-y",
"@nestjs/mcp"
]
}
}
}Automated checks
Ran Nov 14, 2026Full report →Not verified yet. A server needs a score of 80, no serious finding, and enough data for us to check. How checks work · What to fix for more points
- Source repository linked and reachablenestjs/mcp is public and reachablegithub.com/nestjs/mcp ↗Pass
- Package names this repository as its source@nestjs/mcp names nestjs/mcp as sourcenpmjs.com/package/@nestjs/mcp ↗Pass
- Build provenance (Sigstore attestation)No build attestation published for this releaseNot checked
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit or release 2026-11-12github.com/nestjs/mcp ↗Pass
- OpenSSF ScorecardNot checked
- Package name not close to a popular packageNo popular package one edit away from @nestjs/mcpPass
- No critical advisory in the package or its dependenciesNot checked
- No hidden instructions to the model0 tool descriptions and the README read; no override phrases, credential paths or hidden charactersPass
- Destructive tools are labelledNot checked
- Remote endpoint answers the MCP handshakeNot checked
README
View on GitHubDescription
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).
Installation
$ npm i --save @nestjs/mcp @modelcontextprotocol/server zod
Zod 4.2 or later; any other Standard Schema library that produces JSON Schema works too.
Quick Start
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.
Support
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.
Stay in touch
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
License
Nest is MIT licensed.
NestJS MCP questions
How do I add NestJS MCP to Claude Code?
Run claude mcp add mcp -- npx -y @nestjs/mcp in your terminal. Add --scope user to make it available in every project.
How do I add NestJS MCP to Cursor?
Open ~/.cursor/mcp.json and add the server under mcpServers, using the Cursor config shown in the install section above.
How do I expose tools and resources in NestJS?
You can use the @Tool and @Resource decorators on provider methods, defining schemas with libraries like Zod, ArkType, or JSON Schema.
What transport protocols are supported?
The server supports Streamable HTTP for existing Nest applications (Express, Fastify, or Node) and stdio for standalone application contexts.
Can I use NestJS guards and interceptors with MCP?
Yes, MCP calls run through Nest's standard guards, interceptors, pipes, and exception filters.
Does it support OAuth?
Yes, it can act as an OAuth 2.1 resource server with features like protected resource metadata and per-tool scopes.