rekog-labs/MCP-Nest

A NestJS module to effortlessly create Model Context Protocol (MCP) servers for exposing AI tools, resources, and prompts.

690 ★110 forksTypeScriptUpdated 2d ago

What you need to know

A NestJS module (@McpController + McpStrategy) that exposes tools, resources, and prompts from any NestJS application over MCP, running as a CustomTransportStrategy microservice so guards, pipes, interceptors, and exception filters apply natively.

Install

npm install @rekog/mcp-nest @modelcontextprotocol/server @modelcontextprotocol/core @modelcontextprotocol/node zod@^4
npm install @rekog/mcp-nest-auth  (optional built-in authorization server)
npm install @nestjs/typeorm typeorm  (optional, for the TypeORM store)

Usage

  • Annotate a controller with @McpController() and methods with @Tool({ name, description, parameters: z.object(...) }) using NestJS microservice @Payload/@Ctx decorators.
  • Create a McpStrategy with transports: [new StreamableHttpTransport()] (or StdioTransport for STDIO-only), connect it via app.connectMicroservice({ strategy: mcp }).
  • Call startAllMicroservices() before listen() so MCP HTTP routes are mounted; mcp.setHttpAdapter(app.getHttpAdapter()) is needed for HTTP transports.
  • For STDIO-only, use NestFactory.createMicroservice(AppModule, { strategy: mcp }) and disable logging (stdout is reserved for the protocol).

Key features

  • NestJS microservice strategy: tools/resources/prompts are real @MessagePattern-like handlers with guards, pipes, interceptors, and exception filters.
  • Multi-transport support: Streamable HTTP and STDIO, selected via the transports array.
  • Dual-era protocol support: one endpoint serves both the 2025-era protocol (initialize + sessions) and the stateless 2026-07-28 revision concurrently, with no change to tool code.
  • Per-tool authorization, elicitation (interactive tool calls with user input), full request-context access in handlers, and server mutation/instrumentation.
  • Guard-based authentication with OAuth, including a built-in authorization server (Beta) or external ones (Keycloak, Auth0, etc.), plus dependency injection throughout.

Best for

NestJS teams that want to expose existing, dependency-injected application logic as an MCP server while keeping the full NestJS middleware ecosystem.

Caveats

  • Built-in authorization server is Beta and lives in a separate package (@rekog/mcp-nest-auth).
  • Progress reporting (ctx.reportProgress) reaches a 2026-07-28 client as-is; a 2025-era client needs a session-aware transport (statefulMode: true or StdioTransport).
Platforms: macOS · Linux · Windows
Documentation ↗

Reviewed 2026-08-07

Topics

llmllmsmcpmcp-nestmodel-context-protocolmodelcontextprotocolnestjs
View on GitHub ↗
Stars
690★
Forks
110
Language
TypeScript
License
MIT
Created
2025-01-26
Last push
2026-08-05