UNPKG

@nestia/core

Version:

Super-fast validation decorators of NestJS

58 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.McpRoute = McpRoute; const validate_request_body_1 = require("./internal/validate_request_body"); function McpRoute(input) { const config = typeof input === "string" ? { name: input } : input; return function McpRoute(_target, _propertyKey, descriptor) { var _a; Reflect.defineMetadata("nestia/McpRoute", { name: config.name, title: config.title, description: config.description, inputSchema: (_a = config.inputSchema) !== null && _a !== void 0 ? _a : { type: "object", properties: {} }, outputSchema: config.outputSchema, annotations: config.annotations, }, descriptor.value); return descriptor; }; } (function (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(validator) { const validate = (0, validate_request_body_1.validate_request_body)("McpRoute.Params")(validator); return function McpRouteParams(target, propertyKey, parameterIndex) { emplace(target, propertyKey !== null && propertyKey !== void 0 ? propertyKey : "", { category: "params", index: parameterIndex, validate, }); }; } McpRoute.Params = Params; /** @internal */ const emplace = (target, propertyKey, value) => { const array = Reflect.getOwnMetadata("nestia/McpRoute/Parameters", target, propertyKey); if (array !== undefined) array.push(value); else Reflect.defineMetadata("nestia/McpRoute/Parameters", [value], target, propertyKey); }; })(McpRoute || (exports.McpRoute = McpRoute = {})); //# sourceMappingURL=McpRoute.js.map