NestJS MCP Server Module
by rekog-labs
NestJS MCP Server Module
A NestJS module for exposing your services as an MCP (Model Context Protocol) server with Server-Sent Events (SSE) transport. This package simplifies exposing tools that clients can discover and execute via SSE.
Features
- SSE Transport: Built-in
/sse
endpoint for streaming and/messages
for handling tool execution - Tool Discovery: Automatically discover and register tools using decorators
- Tool Request Validation: Define Zod schemas to validate tool requests.
- Progress Notifications: Send continuous progress updates from tools to clients.
Installation
Copy
Quick Start
1. Import Module
Copy
2. Define Tools
Copy
3. Start Server
Copy
Client Connection
Clients can connect using the MCP SDK:
Copy
API Endpoints
GET /sse
: SSE connection endpointPOST /messages
: Tool execution endpoint
Configuration Reference
McpOptions
Property | Type | Description | Default Value |
---|---|---|---|
name | string | Server name | - |
version | string | Server version | - |
capabilities | Record<string, any> | Server capabilities, defines what the server can do. | {} |
sseEndpoint | string (optional) | Endpoint for SSE connections. | 'sse' |
messagesEndpoint | string (optional) | Endpoint for handling tool execution. | 'messages' |
globalApiPrefix | string (optional) | Global API prefix for all endpoints. | '' |
Tool Decorator
The @Tool
decorator is used to define a method as an MCP tool.
Copy
name
: The name of the tool. This will be used to list it in thelistTools
request.description
: A description of the tool.parameters
: (Optional) A Zod schema defining the expected structure of the tool's input arguments.
This server cannot be installed
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.