Integrations
Provides a module for NestJS to create an MCP (Model Context Protocol) server with Server-Sent Events (SSE) transport, allowing services to be exposed as tools that clients can discover and execute.
Enables sending continuous progress updates from tools to clients, allowing for tracking of long-running operations with percentage completion indicators.
Integrates Zod schema validation for tool requests, enabling type-safe parameter validation for tools exposed through the MCP server.
NestJS MCP Server Module
A NestJS module to effortlessly expose tools, resources, and prompts for AI, from your NestJS applications using the Model Context Protocol (MCP).
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.
Features
- 🚀 Support for all Transport Types:
- Streamable HTTP
- HTTP+SSE
- STDIO
- 🔍 Automatic
tool
,resource
, andprompt
discovery and registration - 💯 Zod-based tool call validation
- 📊 Progress notifications
- 🔒 Guard-based authentication
Installation
Quick Start
1. Import Module
2. Define Tools and Resource
You are done!
Quick Start for STDIO
The main difference is that you need to provide the transport
option when importing the module.
The rest is the same, you can define tools, resources, and prompts as usual. An example of a standalone NestJS application using the STDIO transport is the following:
Next, you can use the MCP server with an MCP Stdio Client (see example), or after building your project you can use it with the following MCP Client configuration:
API Endpoints
HTTP+SSE transport exposes two endpoints:
GET /sse
: SSE connection endpoint (Protected by guards if configured)POST /messages
: Tool execution endpoint (Protected by guards if configured)
Streamable HTTP transport exposes the following endpoints:
POST /mcp
: Main endpoint for all MCP operations (tool execution, resource access, etc.). In stateful mode, this creates and maintains sessions.GET /mcp
: Establishes Server-Sent Events (SSE) streams for real-time updates and progress notifications. Only available in stateful mode.DELETE /mcp
: Terminates MCP sessions. Only available in stateful mode.
Tips
It's possible to use the module with global prefix, but the recommended way is to exclude those endpoints with:
Authentication
You can secure your MCP endpoints using standard NestJS Guards.
1. Create a Guard
Implement the CanActivate
interface. The guard should handle request validation (e.g., checking JWTs, API keys) and optionally attach user information to the request object.
Nothing special, check the NestJS documentation for more details.
2. Apply the Guard
Pass your guard(s) to the McpModule.forRoot
configuration. The guard(s) will be applied to both the /sse
and /messages
endpoints.
That's it! The rest is the same as NestJS Guards.
Playground
The playground
directory contains examples to quickly test MCP and @rekog/mcp-nest
features.
Refer to the playground/README.md
for more details.
Configuration
The McpModule.forRoot()
method accepts an McpOptions
object to configure the server. Here are the available options:
Option | Description | Default |
---|---|---|
name | Required. The name of your MCP server. | - |
version | Required. The version of your MCP server. | - |
capabilities | Optional MCP server capabilities to advertise. See @modelcontextprotocol/sdk. | undefined |
instructions | Optional instructions for the client on how to interact with the server. | undefined |
transport | Specifies the transport type(s) to enable. | [McpTransportType.SSE, McpTransportType.STREAMABLE_HTTP, McpTransportType.STDIO] |
sseEndpoint | The endpoint path for the SSE connection (used with SSE transport). | 'sse' |
messagesEndpoint | The endpoint path for sending messages (used with SSE transport). | 'messages' |
mcpEndpoint | The base endpoint path for MCP operations (used with STREAMABLE_HTTP transport). | 'mcp' |
globalApiPrefix | A global prefix for all MCP endpoints. Useful if integrating into an existing application. | '' |
guards | An array of NestJS Guards to apply to the MCP endpoints for authentication/authorization. | [] |
decorators | An array of NestJS Class Decorators to apply to the generated MCP controllers. | [] |
sse | Configuration specific to the SSE transport. | { pingEnabled: true, pingIntervalMs: 30000 } |
sse.pingEnabled | Whether to enable periodic SSE ping messages to keep the connection alive. | true |
sse.pingIntervalMs | The interval (in milliseconds) for sending SSE ping messages. | 30000 |
streamableHttp | Configuration specific to the STREAMABLE_HTTP transport. | { enableJsonResponse: true, sessionIdGenerator: undefined, statelessMode: true } |
streamableHttp.enableJsonResponse | If true , allows the /mcp endpoint to return JSON responses for non-streaming requests (like listTools ). | true |
streamableHttp.sessionIdGenerator | A function to generate unique session IDs when running in stateful mode. Required if statelessMode is false . | undefined |
streamableHttp.statelessMode | If true , the STREAMABLE_HTTP transport operates statelessly (no sessions). If false , it operates statefully, requiring a sessionIdGenerator . | true |
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
A NestJS module that allows services to be exposed as an MCP server with Server-Sent Events transport, facilitating tool discovery and execution by clients.
- Features
- Installation
- Quick Start
- Quick Start for STDIO
- API Endpoints
- Authentication
- Playground
- Configuration
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityA comprehensive Model Context Protocol server that provides advanced Node.js development tooling for automating project creation, component generation, package management, and documentation with AI-powered assistance.Last updated -72JavaScriptMIT License
- AsecurityFlicenseAqualityAn MCP server implementation that enables interaction with the Unstructured API, providing tools to list, create, update, and manage sources, destinations, and workflows.Last updated -3925
- -securityFlicense-qualityA server that connects MCP clients (Claude, Cursor, Windsurf, etc.) to EventCatalog instances, allowing users to ask questions about their event-driven architecture and get insights about domains, services, and message schemas directly within their development tools.Last updated -2113TypeScript
- -securityFlicense-qualityA TypeScript framework for building Model Context Protocol (MCP) servers with automatic discovery and loading of tools, resources, and prompts.Last updated -67TypeScript