Skip to main content
Glama
@nestjs/mcp

@nestjs/mcp

Official
by nestjs

Description

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

Related MCP server: mcp-nestjs

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

License

Nest is MIT licensed.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      A NestJS module for building Model Context Protocol (MCP) servers using decorators to expose services as tools, resources, and prompts. It features auto-discovery, a built-in playground UI, and support for multiple transports including SSE and Stdio.
      19 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Build MCP servers inside NestJS applications using ordinary controllers with decorators for tools, resources, and prompts, supporting authentication and authorization.
      65 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      NestJS package that provides decorator-based tool discovery, TypeBox/AJV validation, and MCP SDK server construction for building MCP servers.
      66 npm
      MIT