@nestia/core
Version:
Super-fast validation decorators of NestJS
70 lines (69 loc) • 2.82 kB
TypeScript
import { IRequestBodyValidator } from "../options/IRequestBodyValidator";
/**
* MCP (Model Context Protocol) route decorator.
*
* `@McpRoute()` marks a controller method as a callable MCP tool. When the
* application bootstraps, every method annotated with this decorator is
* registered on the MCP server built by {@link McpAdaptor.upgrade}, making it
* reachable by LLM clients through the standard Streamable HTTP transport.
*
* The public form takes only the tool's `name` (string). Human-readable
* `description` and `title` are read from the method's JSDoc:
*
* - `description`: the JSDoc comment body.
* - `title`: the value of an optional `@title` JSDoc tag.
*
* For type-safe tool inputs, decorate exactly one parameter of the method with
* {@link McpRoute.Params}. The parameter type `T` is analyzed at compile time by
* the nestia transformer, which generates both a runtime validator and the JSON
* Schema attached to `inputSchema` in `tools/list` responses.
*
* For the MCP endpoint to actually be served, call {@link McpAdaptor.upgrade} on
* the {@link INestApplication} instance at bootstrap. The decorator alone only
* stores reflection metadata.
*
* @author wildduck - https://github.com/wildduck2
* @example
* ```typescript
* import core from "@nestia/core";
*
* @Controller()
* export class WeatherController {
* /**
* * Return current weather for a city.
* *
* * @title Get weather
* *\/
* @core.McpRoute("get_weather")
* public async get(
* @core.McpRoute.Params() params: { city: string },
* ): Promise<{ temp: number }> {
* return { temp: 22 };
* }
* }
* ```;
*
* @param name Unique tool identifier exposed to MCP clients via `tools/list`.
* @returns Method decorator.
*/
export declare function McpRoute(name: string): MethodDecorator;
export declare namespace McpRoute {
/**
* Parameter decorator for an MCP tool's input arguments.
*
* `@McpRoute.Params<T>()` validates the `arguments` object from a
* `tools/call` request against the TypeScript type `T` using typia. A failed
* validation surfaces to the client as a JSON-RPC `-32602` (`InvalidParams`)
* error with structured diagnostics, giving the LLM precise feedback to
* self-correct.
*
* MCP tools accept exactly one arguments object; applying this decorator more
* than once on a single method is a compile-time error. The decorated type
* `T` must be an object type without dynamic properties.
*
* @author wildduck - https://github.com/wildduck2
* @param validator Optional custom validator. Default is `typia.assert()`.
* @returns Parameter decorator.
*/
function Params<T>(validator?: IRequestBodyValidator<T>): ParameterDecorator;
}