MCP Server NestJS Module Library
About
# MCP Server NestJS Module Library <!-- omit in toc --> [](https://www.npmjs.com/package/@nestjs-mcp/server) [](https://github.com/semantic-release/…
Details
- License
- MIT license
Explore
This library provides a set of decorators to define MCP capabilities and apply cross-cutting concerns such as guards. Decorators can be used at both the Resolver (class) level and the method level.
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
- Download and install Highlight from highlightai.com/download
- Navigate to the plugins tab and select "Add Custom Plugin"
-
Configure the plugin with the settings below
Plugin Name
MCP Server NestJS Module LibraryCommand (node, npx, python, etc.)Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.
- Enable "Start Automatically" if you want the plugin to start when Highlight launches
From the repository
```sh
npm install @nestjs-mcp/server @modelcontextprotocol/sdk zod
This library provides two main ways to register MCP capabilities in your NestJS application:
A Tool is an action or function that can be invoked by LLMs. Tools may have side effects and can accept parameters to perform computations or trigger operations.
- Learn more: MCP Tools documentation
Decorate methods within a Resolver class to expose them as MCP Tools. Accepts options compatible with server.tool() from @modelcontextprotocol/sdk. The name should use snake_case.
import { Tool, Resolver } from '@nestjs-mcp/server';
import { RequestHandlerExtra } from '@nestjs-mcp/server'; // Import type for extra info
import { z } from 'zod'; // Example using Zod for schema
// Example Zod schema for parameters
const SumParams = z.object({
num1: z.number(),
num2: z.number(),
});
@Resolver('utils') // Must be in a Resolver class
export class MyTools {
@Tool({
name: 'calculate_sum',
description: 'Calculates the sum of two numbers.',
paramSchema: SumParams, // Use the Zod schema
})
sumTool(
params: z.infer<typeof SumParams>, // First arg is typed parameters from schema
extra: RequestHandlerExtra, // Contains sessionId and other metadata
) {
console.log(Calculating sum for session: ${extra.sessionId});
const result = params.num1 + params.num2;
/ ... return CallToolResult ... /
return { content: [{ type: 'text', text: Result: ${result} }] };
}
}
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
{
"mcpServers": {
"mcp server nestjs module library": {
"nestjs-mcp-server": {
"command": "npx",
"args": [
"@modelcontextprotocol/inspector"
]
}
}
}
}
McpServers
{
"nestjs-mcp-server": {
"command": "npx",
"args": [
"@modelcontextprotocol/inspector"
]
}
}
---
Overview <!-- omit in toc -->
NestJS MCP Server is a modular library for building Model Context Protocol (MCP) servers using NestJS. It provides decorators, modules, and integration patterns to expose MCP resources, tools, and prompts in a scalable, maintainable way. This project is a wrapper for the official @modelcontextprotocol/sdk and is always kept compatible with its types and specification.
---
Table of Contents <!-- omit in toc -->
- Overview
- Installation
- Quickstart
- What is MCP?
- Core Concepts
- Server
- Resource
- Tool
- Prompt
- Module API
- forRoot
- forRootAsync
- forFeature
- Module Usage
- 1. Global Registration with McpModule.forRoot
- 2. Feature Module Registration with McpModule.forFeature
- Capabilities
- Resolver Decorator
- Prompt Decorator
- Resource Decorator
- Tool Decorator
- RequestHandlerExtra Parameter
- Guards
- Global-level guards
- Resolver-level guards
- Method-level guards
- Guard Example
- MCP Execution Context
- Session Management
- Transport Options
- Inspector Playground
- Examples
- Changelog
- License
- Contributions
---
Installation
```sh
npm install @nestjs-mcp/server @modelcontextprotocol/sdk zod
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



