@nest-mcp/client
v0.2.5
Published
NestJS MCP Client - Connect to and consume MCP servers from NestJS
Readme
@nest-mcp/client
NestJS module for connecting to and consuming Model Context Protocol (MCP) servers with typed injection, notifications, health checks, and reconnection support.
Installation
npm install @nest-mcp/client @modelcontextprotocol/sdk zod@^4
npm install @nestjs/common @nestjs/core reflect-metadata rxjsQuick start
// app.module.ts
import { Module } from '@nestjs/common';
import { McpClientModule } from '@nest-mcp/client';
import { McpTransportType } from '@nest-mcp/client';
@Module({
imports: [
McpClientModule.forRoot({
connections: [
{
name: 'my-server',
transport: {
type: McpTransportType.STREAMABLE_HTTP,
url: 'http://localhost:3000/mcp',
},
},
],
}),
],
})
export class AppModule {}// my.service.ts
import { Injectable } from '@nestjs/common';
import { InjectMcpClient, McpClient } from '@nest-mcp/client';
@Injectable()
export class MyService {
constructor(@InjectMcpClient('my-server') private client: McpClient) {}
async greet(name: string) {
return this.client.callTool({ name: 'greet', arguments: { name } });
}
}Features
@InjectMcpClient(name)— inject a named client into any serviceMcpClientsService— programmatic access to all clients by name@OnMcpNotification(method)— subscribe to server-sent notificationsMcpClientHealthIndicator— health check integration (NestJS Terminus)- Automatic reconnection with configurable backoff
- OAuth support for authenticated servers
Transports
- Streamable HTTP (
McpTransportType.STREAMABLE_HTTP) - SSE (
McpTransportType.SSE) - STDIO (
McpTransportType.STDIO)
Documentation
Full documentation: github.com/btwld/nest-mcp/docs/client
License
BSD-3-Clause
