npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nestjs-mcp-decorators

v1.0.0

Published

NestJS decorators for automatic MCP tool exposure over HTTP with streamable responses

Readme

NestJS MCP Decorators

A NestJS package that automatically exposes controller methods as MCP (Model Context Protocol) tools over HTTP with streamable responses.

Features

  • 🎯 Automatic MCP Tool Registration: Decorate controller methods with @McpTool() to expose them as MCP tools
  • 🔄 Streamable HTTP: Built-in support for NDJSON streaming responses
  • 🧠 Auto Schema Inference: Automatically generates Zod schemas from TypeScript parameter types
  • 🚀 Zero Configuration: Works out of the box with any NestJS application
  • 🔌 AI Client Ready: Compatible with Cursor, Claude Desktop, and other MCP clients

Installation

npm install nestjs-mcp-decorators

Quick Start

  1. Import the controller in your app module:
import { Module } from '@nestjs/common';
import { McpHttpController } from 'nestjs-mcp-decorators';

@Module({
  controllers: [McpHttpController],
  // ... other imports
})
export class AppModule {}
  1. Decorate your controller methods:
import { Controller, Get, Query } from '@nestjs/common';
import { McpTool, Streamable } from 'nestjs-mcp-decorators';

@Controller('calculator')
export class CalculatorController {
  @Get('add')
  @Streamable()
  @McpTool()
  add(@Query('a') a: number, @Query('b') b: number) {
    return a + b;
  }

  @Get('multiply')
  @Streamable()
  @McpTool()
  multiply(@Query('a') a: number, @Query('b') b: number) {
    return a * b;
  }
}
  1. Configure your AI client:

For Cursor, add to ~/.cursor/mcp.json:

{
  "mcpServers": {
    "my-service": {
      "url": "http://localhost:3000/mcp",
      "transport": "streamable"
    }
  }
}

API Reference

Decorators

@McpTool()

Registers a controller method as an MCP tool. The tool name will be the method name.

@McpTool()
add(@Query('a') a: number, @Query('b') b: number) {
  return a + b;
}

@Streamable()

Applies NDJSON headers and enables chunked transfer encoding for streaming responses.

@Streamable()
@McpTool()
getData() {
  return { result: 'data' };
}

Controller

McpHttpController

Automatically exposes all @McpTool() decorated methods at the /mcp endpoint.

  • GET /mcp - SSE endpoint for MCP clients
  • POST /mcp - RPC endpoint for tool calls

Registry

McpToolRegistry

Static registry that stores tool metadata.

import { McpToolRegistry } from 'nestjs-mcp-decorators';

// Get all registered tools
const tools = McpToolRegistry.getAll();

// Clear registry (useful for testing)
McpToolRegistry.clear();

Supported Parameter Types

The package automatically infers Zod schemas for these TypeScript types:

  • numberz.number()
  • stringz.string()
  • booleanz.boolean()
  • anyz.any() (fallback)

Example Usage

Calculator Service

import { Controller, Get, Query } from '@nestjs/common';
import { McpTool, Streamable } from 'nestjs-mcp-decorators';

@Controller('calculator')
export class CalculatorController {
  @Get('add')
  @Streamable()
  @McpTool()
  add(@Query('a') a: number, @Query('b') b: number) {
    return a + b;
  }

  @Get('subtract')
  @Streamable()
  @McpTool()
  subtract(@Query('a') a: number, @Query('b') b: number) {
    return a - b;
  }

  @Get('multiply')
  @Streamable()
  @McpTool()
  multiply(@Query('a') a: number, @Query('b') b: number) {
    return a * b;
  }

  @Get('divide')
  @Streamable()
  @McpTool()
  divide(@Query('a') a: number, @Query('b') b: number) {
    if (b === 0) throw new Error('Division by zero');
    return a / b;
  }
}

Weather Service

import { Controller, Get, Query } from '@nestjs/common';
import { McpTool, Streamable } from 'nestjs-mcp-decorators';

@Controller('weather')
export class WeatherController {
  @Get('temperature')
  @Streamable()
  @McpTool()
  getTemperature(@Query('city') city: string) {
    // Simulate weather API call
    return { city, temperature: 22, unit: 'celsius' };
  }

  @Get('forecast')
  @Streamable()
  @McpTool()
  getForecast(@Query('city') city: string, @Query('days') days: number) {
    return { city, forecast: 'sunny', days };
  }
}

Testing

import { Test, TestingModule } from '@nestjs/testing';
import { McpHttpController } from 'nestjs-mcp-decorators';

describe('MCP Integration', () => {
  let controller: McpHttpController;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [McpHttpController],
    }).compile();

    controller = module.get<McpHttpController>(McpHttpController);
  });

  it('should be defined', () => {
    expect(controller).toBeDefined();
  });
});

Troubleshooting

Tool Not Found

Ensure your controller is properly registered in a module that's imported by your AppModule.

Schema Inference Issues

For complex types, the package falls back to z.any(). Consider using explicit Zod schemas for better type safety.

Cursor Configuration

Make sure your ~/.cursor/mcp.json points to the correct URL and uses "transport": "streamable".

License

MIT