NestJS MCP
NestJS MCP (Model Context Protocol) module — allows you to create “tools” (functions) for LLM or HTTP, with automatic detection via decorators, validation, and integration with OpenAI Function Calls.
What is NestJS MCP?
NestJS MCP is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to nestjs mcp (model context protocol) module — allows you to create “tools” (functions) for llm or http, with automatic detection via decorators, validation, and integration with openai function calls.
NestJS MCP (Model Context Protocol) module — allows you to create “tools” (functions) for LLM or HTTP, with automatic detection via decorators, validation, and integration with OpenAI Function Calls.
This server falls under the Developer Tools and Coding Agents categories on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- NestJS MCP (Model Context Protocol) module — allows you to c
Use Cases
Maintainer
Works with
Installation
NPM
npx -y @nestjs-mcp/serverManual Installation
npx -y @nestjs-mcp/serverConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use NestJS MCP
The NestJS MCP Server library (@nestjs-mcp/server) lets you turn any NestJS application into a fully compliant Model Context Protocol server by adding a module and a few decorators. It automatically discovers and registers Tools, Resources, and Prompts defined with @Tool(), @Resource(), and @Prompt() decorators, handles session management, supports both Streamable HTTP and SSE transports, and integrates with NestJS Guards for authentication. Teams building production APIs choose it because it removes all MCP boilerplate while letting them keep NestJS's dependency injection, validation, and modular architecture.
Prerequisites
- Node.js 18 or later
- An existing NestJS application (v10+)
- npm or yarn package manager
- An MCP-compatible client such as Claude Desktop to test the server
Install the required packages
Add the NestJS MCP wrapper, the official MCP SDK, and Zod (used for parameter schema validation) to your NestJS project.
npm install @nestjs-mcp/server @modelcontextprotocol/sdk zodImport McpModule in your AppModule
Register McpModule.forRoot() (or forRootAsync() for environment-based config) in your root module. Provide at minimum a server name and version; all other options have sensible defaults including 30-minute session timeouts and up to 1000 concurrent sessions.
import { McpModule } from '@nestjs-mcp/server';
@Module({
imports: [
McpModule.forRoot({
name: 'my-mcp-server',
version: '1.0.0',
instructions: 'Tools for interacting with My Service API'
})
]
})
export class AppModule {}Create a Resolver with tools
Define a Resolver class and annotate methods with @Tool(), @Resource(), or @Prompt(). The library auto-discovers all Resolvers in the NestJS provider graph — no manual registration is needed. Methods receive the tool parameters as their first argument and a RequestHandlerExtra object as the last.
import { Resolver, Tool } from '@nestjs-mcp/server';
import { z } from 'zod';
@Resolver('calculator')
export class CalculatorResolver {
@Tool({ name: 'add_numbers', description: 'Add two numbers together' })
add(params: { a: number; b: number }) {
return { content: [{ type: 'text', text: String(params.a + params.b) }] };
}
}Register the Resolver as a provider
Add your Resolver to the providers array of the appropriate NestJS module so the dependency injection container can find it.
@Module({
imports: [McpModule.forRoot({ name: 'my-mcp-server', version: '1.0.0' })],
providers: [CalculatorResolver]
})
export class AppModule {}Start the NestJS application and connect your MCP client
Run your NestJS app normally with 'npm run start'. The MCP endpoints are served alongside your existing HTTP routes. Point your MCP client at the server's Streamable HTTP or SSE endpoint (e.g., http://localhost:3000/mcp).
npm run startNestJS MCP Examples
Client configuration
Claude Desktop configuration to connect to a locally running NestJS MCP server via Streamable HTTP. Replace the URL with your server's actual address.
{
"mcpServers": {
"nestjs-mcp": {
"command": "npx",
"args": ["-y", "@nestjs-mcp/server"],
"env": {}
}
}
}Prompts to try
Sample prompts assuming a NestJS MCP server with calculator and database tools registered.
- "Add 42 and 58 using the calculator tool."
- "List all the tools available on this MCP server."
- "Call the server_health_check tool and tell me the result."
- "Use the database query tool to fetch all users where role is admin."
- "What resources are available on this MCP server?"Troubleshooting NestJS MCP
Tools are not discovered by the MCP client
Ensure your Resolver classes are listed in the 'providers' array of a NestJS module that is imported (directly or transitively) by AppModule. The library auto-discovers providers but they must be registered in the DI container.
Session timeout errors during long-running operations
Increase sessionTimeoutMs in McpModule.forRoot() options. The default is 30 minutes (1800000 ms). For long-running agents, set it to a higher value and also adjust cleanupIntervalMs accordingly.
Guards are not protecting MCP tool endpoints
Resolver-level and method-level @UseGuards() decorators receive an McpExecutionContext, not an HTTP ExecutionContext. Update your guard to check context.getType() and handle both 'http' and 'mcp' contexts, or create a dedicated MCP guard using getSessionId() and getArgs().
Frequently Asked Questions about NestJS MCP
What is NestJS MCP?
NestJS MCP is a Model Context Protocol (MCP) server that nestjs mcp (model context protocol) module — allows you to create “tools” (functions) for llm or http, with automatic detection via decorators, validation, and integration with openai function calls. It connects AI assistants to external tools and data sources through a standardized interface.
How do I install NestJS MCP?
Install via npm with the command: npx -y @nestjs-mcp/server. Then add the server configuration to your AI client's JSON config file (e.g., claude_desktop_config.json or .cursor/mcp.json).
Which AI clients work with NestJS MCP?
NestJS MCP works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is NestJS MCP free to use?
Yes, NestJS MCP is open source and available under the MIT license. You can use it freely in both personal and commercial projects.
NestJS MCP Alternatives — Similar Developer Tools Servers
Looking for alternatives to NestJS MCP? Here are other popular developer tools servers you can use with Claude, Cursor, and VS Code.
Ecc
★ 188.2kThe agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
Javaguide
★ 155.8kJava 面试 & 后端通用面试指南,覆盖计算机基础、数据库、分布式、高并发、系统设计与 AI 应用开发
Gemini CLI
★ 104.5kA secure MCP server that wraps the Google Gemini CLI, allowing clients to query Gemini models using local OAuth sessions without requiring an API key. It provides tools for model interaction and diagnostics with built-in protection against command in
Awesome MCP Servers
★ 87.3k⭐ Curated list of Model Context Protocol (MCP) servers - tools that extend Claude Desktop, Cursor, Windsurf, and other MCP clients with custom capabilities.
MCP Servers
★ 86.0kModel Context Protocol Servers
CC Switch
★ 77.5kA cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Gemini CLI & Hermes Agent. Only official website: ccswitch.io
Browse More Developer Tools MCP Servers
Explore all developer tools servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up NestJS MCP in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use NestJS MCP?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.