NestJS MCP

v1.0.0Developer Toolsstable

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.

mcpmcp-servermcp-toolsnestjsnestjs-module
Share:
34
Stars
0
Downloads
0
Weekly
0/5

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

Create tools and functions for LLMs using NestJS decorators.
Enable automatic validation and OpenAI Function Calls.
Build production-ready MCP servers with NestJS.
LicenseMIT
Languagetypescript
Versionv1.0.0
UpdatedMay 12, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

NPM

npx -y @nestjs-mcp/server

Manual Installation

npx -y @nestjs-mcp/server

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

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
1

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 zod
2

Import 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 {}
3

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) }] };
  }
}
4

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 {}
5

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 start

NestJS 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.

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.

Quick Config Preview

{ "mcpServers": { "nestjs": { "command": "npx", "args": ["-y", "@nestjs-mcp/server"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

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.

33,000+ ServersFree & Open SourceStep-by-Step Guides