$git clone https://github.com/rekog-labs/MCP-Nest[![CI][ci-image]][ci-url] [![Code Coverage][code-coverage-image]][code-coverage-url] [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![NPM License][npm-license-image]][npm-url]
| 1 | # NestJS MCP Server Module |
| 2 | |
| 3 | <div align="center"> |
| 4 | <img src="https://raw.githubusercontent.com/rekog-labs/MCP-Nest/main/image.png" height="200"> |
| 5 | |
| 6 | [![CI][ci-image]][ci-url] |
| 7 | [![Code Coverage][code-coverage-image]][code-coverage-url] |
| 8 | [![NPM Version][npm-version-image]][npm-url] |
| 9 | [![NPM Downloads][npm-downloads-image]][npm-url] |
| 10 | [![NPM License][npm-license-image]][npm-url] |
| 11 | |
| 12 | </div> |
| 13 | |
| 14 | A NestJS module to effortlessly expose tools, resources, and prompts for AI, from your NestJS applications using the **Model Context Protocol (MCP)**. |
| 15 | |
| 16 | With `@rekog/mcp-nest` you define tools, resources, and prompts in a way that's familiar in NestJS and leverage the full power of dependency injection to utilize your existing codebase in building complex enterprise ready MCP servers. |
| 17 | |
| 18 | ## Features |
| 19 | |
| 20 | - 🧩 **[NestJS Microservice Strategy](docs/migration-to-strategy.md)**: MCP runs as a `CustomTransportStrategy`, so tools/resources/prompts are real `@MessagePattern` handlers — **guards, pipes, interceptors, and exception filters apply to them natively** |
| 21 | - 🚀 **[Multi-Transport Support](docs/server-examples.md#multiple-transport-types)**: Streamable HTTP and STDIO — selected via the `transports` array |
| 22 | - 🔧 **[Tools](docs/tools.md)**: Expose NestJS methods as MCP tools with automatic discovery and Zod validation |
| 23 | - 🛠️ **[Elicitation](docs/tools.md#interactive-tool-calls)**: Interactive tool calls with user input elicitation |
| 24 | - 🌐 **[HTTP Request Access](docs/tools.md#understanding-tool-method-parameters)**: Full access to request context within MCP handlers |
| 25 | - 🔐 **[Per-Tool Authorization](docs/per-tool-authorization.md)**: Implement fine-grained authorization for tools |
| 26 | - 📁 **[Resources](docs/resources.md)**: Serve content and data through MCP resource system |
| 27 | - 📚 **[Resource Templates](docs/resource-templates.md)**: Dynamic resources with parameterized URIs |
| 28 | - 💬 **[Prompts](docs/prompts.md)**: Define reusable prompt templates for AI interactions |
| 29 | - 🔐 **[Guard-based Authentication](docs/server-examples.md#server-with-authentication)**: Guard-based security with OAuth support |
| 30 | - 🏠 **[Built-in Authorization Server](docs/built-in-authorization-server.md)** — Using the built-in Authorization Server for easy setups. **(Beta)** |
| 31 | - 🌐 **[External Authorization Server](docs/external-authorization-server/README.md)** — Securing your MCP server with an external authorization server (Keycloak, Auth0, etc). |
| 32 | - 💉 **[Dependency Injection](docs/dependency-injection.md)**: Leverage NestJS DI system throughout MCP components |
| 33 | - 🔍 **[Server mutation and instrumentation](docs/server-mutation.md)** — Mutate the underlying mcp server for custom logic or instrumentation purposes. |
| 34 | |
| 35 | **Are you interested to build ChatGPT widgets (with the OpenAI SDK) or MCP apps?** |
| 36 | Find out how to do that with `@rekog/MCP-Nest` in this repository [MCP-Nest-Samples](https://github.com/rinormaloku/MCP-Nest-Samples) |
| 37 | |
| 38 | |
| 39 | > [!TIP] |
| 40 | > You can easily learn about this package using the `chat` tab in [Context7](https://context7.com/rekog-labs/mcp-nest?tab=chat). Better yet, connect the [Context7 MCP server](https://github.com/upstash/context7#installation) to allow your AI agents to access the documentation and implement MCP-Nest for you. |
| 41 | |
| 42 | ## Installation |
| 43 | |
| 44 | ```bash |
| 45 | npm install @rekog/mcp-nest @modelcontextprotocol/server @modelcontextprotocol/core @modelcontextprotocol/node zod@^4 |
| 46 | ``` |
| 47 | |
| 48 | ### Optional dependencies |
| 49 | |
| 50 | The built-in authorization server now lives in a separate package. If you use it, install it alongside `@rekog/mcp-nest`: |
| 51 | |
| 52 | ```bash |
| 53 | npm install @rekog/mcp-nest-auth |
| 54 | ``` |
| 55 | |
| 56 | If you additionally use the TypeORM store for the authorization server, install the following optional peer dependencies as well: |
| 57 | |
| 58 | ```bash |
| 59 | npm install @nestjs/typeorm typeorm |
| 60 | ``` |
| 61 | |
| 62 | ## Quick Start |
| 63 | |
| 64 | MCP-Nest runs as a **NestJS microservice transport strategy**. Tools, resources, |
| 65 | and prompts live on `@McpController()` classes (so NestJS guards, pipes, |
| 66 | interceptors, and exception filters apply to them), and the strategy serves them |
| 67 | over one or |