@rekog/mcp-nest 1.6.0-beta.0 → 1.6.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/decorators/resource.decorator.d.ts +0 -7
- package/dist/decorators/resource.decorator.d.ts.map +1 -1
- package/dist/decorators/resource.decorator.js +0 -7
- package/dist/decorators/resource.decorator.js.map +1 -1
- package/dist/decorators/tool.decorator.d.ts +0 -9
- package/dist/decorators/tool.decorator.d.ts.map +1 -1
- package/dist/decorators/tool.decorator.js +0 -9
- package/dist/decorators/tool.decorator.js.map +1 -1
- package/dist/interfaces/mcp-options.interface.d.ts +0 -3
- package/dist/interfaces/mcp-options.interface.d.ts.map +1 -1
- package/dist/interfaces/mcp-options.interface.js.map +1 -1
- package/dist/interfaces/mcp-tool.interface.d.ts +0 -3
- package/dist/interfaces/mcp-tool.interface.d.ts.map +1 -1
- package/dist/mcp.module.d.ts.map +1 -1
- package/dist/mcp.module.js +6 -5
- package/dist/mcp.module.js.map +1 -1
- package/dist/services/handlers/mcp-handler.base.js +0 -6
- package/dist/services/handlers/mcp-handler.base.js.map +1 -1
- package/dist/services/handlers/mcp-prompts.handler.js +0 -1
- package/dist/services/handlers/mcp-prompts.handler.js.map +1 -1
- package/dist/services/handlers/mcp-resources.handler.js +0 -1
- package/dist/services/handlers/mcp-resources.handler.js.map +1 -1
- package/dist/services/handlers/mcp-tools.handler.js +0 -5
- package/dist/services/handlers/mcp-tools.handler.js.map +1 -1
- package/dist/services/mcp-executor.service.d.ts +0 -8
- package/dist/services/mcp-executor.service.d.ts.map +1 -1
- package/dist/services/mcp-executor.service.js +0 -8
- package/dist/services/mcp-executor.service.js.map +1 -1
- package/dist/services/mcp-registry.service.d.ts +0 -34
- package/dist/services/mcp-registry.service.d.ts.map +1 -1
- package/dist/services/mcp-registry.service.js +0 -31
- package/dist/services/mcp-registry.service.js.map +1 -1
- package/dist/services/sse-ping.service.d.ts +0 -22
- package/dist/services/sse-ping.service.d.ts.map +1 -1
- package/dist/services/sse-ping.service.js +0 -27
- package/dist/services/sse-ping.service.js.map +1 -1
- package/dist/transport/custom-decorator.spec.js +4 -15
- package/dist/transport/custom-decorator.spec.js.map +1 -1
- package/dist/transport/sse.controller.factory.d.ts +4 -15
- package/dist/transport/sse.controller.factory.d.ts.map +1 -1
- package/dist/transport/sse.controller.factory.js +10 -33
- package/dist/transport/sse.controller.factory.js.map +1 -1
- package/dist/transport/stdio.service.js +0 -3
- package/dist/transport/stdio.service.js.map +1 -1
- package/dist/transport/streamable-http.controller.factory.d.ts +1 -22
- package/dist/transport/streamable-http.controller.factory.d.ts.map +1 -1
- package/dist/transport/streamable-http.controller.factory.js +4 -50
- package/dist/transport/streamable-http.controller.factory.js.map +1 -1
- package/dist/utils/capabilities-builder.d.ts +0 -4
- package/dist/utils/capabilities-builder.d.ts.map +1 -1
- package/dist/utils/capabilities-builder.js +8 -14
- package/dist/utils/capabilities-builder.js.map +1 -1
- package/dist/utils/normalize-endpoint.d.ts +2 -0
- package/dist/utils/normalize-endpoint.d.ts.map +1 -0
- package/dist/utils/normalize-endpoint.js +8 -0
- package/dist/utils/normalize-endpoint.js.map +1 -0
- package/package.json +2 -2
- package/src/interfaces/mcp-options.interface.ts +3 -0
- package/src/mcp.module.ts +6 -4
- package/src/transport/custom-decorator.spec.ts +2 -7
- package/src/transport/sse.controller.factory.ts +7 -4
- package/src/transport/streamable-http.controller.factory.ts +5 -6
- package/src/utils/capabilities-builder.ts +9 -7
- package/src/utils/normalize-endpoint.ts +7 -0
package/README.md
CHANGED
|
@@ -238,7 +238,6 @@ The `McpModule.forRoot()` method accepts an `McpOptions` object to configure the
|
|
|
238
238
|
| `sseEndpoint` | The endpoint path for the SSE connection (used with `SSE` transport). | `'sse'` |
|
|
239
239
|
| `messagesEndpoint` | The endpoint path for sending messages (used with `SSE` transport). | `'messages'` |
|
|
240
240
|
| `mcpEndpoint` | The base endpoint path for MCP operations (used with `STREAMABLE_HTTP` transport). | `'mcp'` |
|
|
241
|
-
| `globalApiPrefix` | A global prefix for all MCP endpoints. Useful if integrating into an existing application. | `''` |
|
|
242
241
|
| `guards` | An array of NestJS Guards to apply to the MCP endpoints for authentication/authorization. | `[]` |
|
|
243
242
|
| `decorators` | An array of NestJS Class Decorators to apply to the generated MCP controllers. | `[]` |
|
|
244
243
|
| `sse` | Configuration specific to the `SSE` transport. | `{ pingEnabled: true, pingIntervalMs: 30000 }` |
|
|
@@ -10,12 +10,5 @@ export interface ResourceMetadata {
|
|
|
10
10
|
description?: string;
|
|
11
11
|
mimeType?: string;
|
|
12
12
|
}
|
|
13
|
-
/**
|
|
14
|
-
* Decorator that marks a controller method as an MCP resource.
|
|
15
|
-
* @param {Object} options - The options for the decorator
|
|
16
|
-
* @param {string} options.name - The name of the resource
|
|
17
|
-
* @param {string} options.uri - The URI of the resource
|
|
18
|
-
* @returns {MethodDecorator} - The decorator
|
|
19
|
-
*/
|
|
20
13
|
export declare const Resource: (options: ResourceOptions) => import("@nestjs/common").CustomDecorator<string>;
|
|
21
14
|
//# sourceMappingURL=resource.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/resource.decorator.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAEzB;IACE,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEJ,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;
|
|
1
|
+
{"version":3,"file":"resource.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/resource.decorator.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,eAAe,GAEzB;IACE,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEJ,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AASD,eAAO,MAAM,QAAQ,YAAa,eAAe,qDAEhD,CAAC"}
|
|
@@ -3,13 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Resource = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
-
/**
|
|
7
|
-
* Decorator that marks a controller method as an MCP resource.
|
|
8
|
-
* @param {Object} options - The options for the decorator
|
|
9
|
-
* @param {string} options.name - The name of the resource
|
|
10
|
-
* @param {string} options.uri - The URI of the resource
|
|
11
|
-
* @returns {MethodDecorator} - The decorator
|
|
12
|
-
*/
|
|
13
6
|
const Resource = (options) => {
|
|
14
7
|
return (0, common_1.SetMetadata)(constants_1.MCP_RESOURCE_METADATA_KEY, options);
|
|
15
8
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource.decorator.js","sourceRoot":"","sources":["../../src/decorators/resource.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,2CAAwD;
|
|
1
|
+
{"version":3,"file":"resource.decorator.js","sourceRoot":"","sources":["../../src/decorators/resource.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,2CAAwD;AAyBjD,MAAM,QAAQ,GAAG,CAAC,OAAwB,EAAE,EAAE;IACnD,OAAO,IAAA,oBAAW,EAAC,qCAAyB,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC,CAAC;AAFW,QAAA,QAAQ,YAEnB","sourcesContent":["import { SetMetadata } from '@nestjs/common';\nimport { MCP_RESOURCE_METADATA_KEY } from './constants';\n\nexport type ResourceOptions =\n // https://modelcontextprotocol.io/docs/concepts/resources#direct-resources\n {\n uri: string; // Unique identifier for the resource\n name?: string; // Human-readable name\n description?: string; // Optional description\n mimeType?: string; // Optional MIME type\n };\n\nexport interface ResourceMetadata {\n uri: string; // Unique identifier for the resource\n name: string; // Human-readable name\n description?: string; // Optional description\n mimeType?: string; // Optional MIME type\n}\n\n/**\n * Decorator that marks a controller method as an MCP resource.\n * @param {Object} options - The options for the decorator\n * @param {string} options.name - The name of the resource\n * @param {string} options.uri - The URI of the resource\n * @returns {MethodDecorator} - The decorator\n */\nexport const Resource = (options: ResourceOptions) => {\n return SetMetadata(MCP_RESOURCE_METADATA_KEY, options);\n};\n"]}
|
|
@@ -20,14 +20,5 @@ export interface ToolOptions {
|
|
|
20
20
|
outputSchema?: z.ZodTypeAny;
|
|
21
21
|
annotations?: ToolAnnotations;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Decorator that marks a controller method as an MCP tool.
|
|
25
|
-
* @param {Object} options - The options for the decorator
|
|
26
|
-
* @param {string} options.name - The name of the tool
|
|
27
|
-
* @param {string} options.description - The description of the tool
|
|
28
|
-
* @param {z.ZodTypeAny} [options.parameters] - The parameters of the tool
|
|
29
|
-
* @param {z.ZodTypeAny} [options.outputSchema] - The output schema of the tool
|
|
30
|
-
* @returns {MethodDecorator} - The decorator
|
|
31
|
-
*/
|
|
32
23
|
export declare const Tool: (options: ToolOptions) => import("@nestjs/common").CustomDecorator<string>;
|
|
33
24
|
//# sourceMappingURL=tool.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CA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AC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC;IAC5B,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAWD,eAAO,MAAM,IAAI,YAAa,WAAW,qDAQxC,CAAC"}
|
|
@@ -4,15 +4,6 @@ exports.Tool = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
|
-
/**
|
|
8
|
-
* Decorator that marks a controller method as an MCP tool.
|
|
9
|
-
* @param {Object} options - The options for the decorator
|
|
10
|
-
* @param {string} options.name - The name of the tool
|
|
11
|
-
* @param {string} options.description - The description of the tool
|
|
12
|
-
* @param {z.ZodTypeAny} [options.parameters] - The parameters of the tool
|
|
13
|
-
* @param {z.ZodTypeAny} [options.outputSchema] - The output schema of the tool
|
|
14
|
-
* @returns {MethodDecorator} - The decorator
|
|
15
|
-
*/
|
|
16
7
|
const Tool = (options) => {
|
|
17
8
|
if (options.parameters === undefined) {
|
|
18
9
|
options.parameters = zod_1.z.object({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.decorator.js","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,2CAAoD;AACpD,6BAAwB;
|
|
1
|
+
{"version":3,"file":"tool.decorator.js","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,2CAAoD;AACpD,6BAAwB;AAmCjB,MAAM,IAAI,GAAG,CAAC,OAAoB,EAAE,EAAE;IAC3C,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,CAAC,UAAU,GAAG,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IACD,IAAI,OAAO,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;QACvC,OAAO,CAAC,YAAY,GAAG,OAAC,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;IACD,OAAO,IAAA,oBAAW,EAAC,iCAAqB,EAAE,OAAO,CAAC,CAAC;AACrD,CAAC,CAAC;AARW,QAAA,IAAI,QAQf","sourcesContent":["import { SetMetadata } from '@nestjs/common';\nimport { MCP_TOOL_METADATA_KEY } from './constants';\nimport { z } from 'zod';\n\nexport interface ToolMetadata {\n name: string;\n description: string;\n parameters?: z.ZodTypeAny;\n outputSchema?: z.ZodTypeAny;\n annotations?: ToolAnnotations;\n}\n\nexport interface ToolAnnotations {\n title?: string;\n readOnlyHint?: boolean;\n destructiveHint?: boolean;\n idempotentHint?: boolean;\n openWorldHint?: boolean;\n}\n\nexport interface ToolOptions {\n name?: string;\n description?: string;\n parameters?: z.ZodTypeAny;\n outputSchema?: z.ZodTypeAny;\n annotations?: ToolAnnotations;\n}\n\n/**\n * Decorator that marks a controller method as an MCP tool.\n * @param {Object} options - The options for the decorator\n * @param {string} options.name - The name of the tool\n * @param {string} options.description - The description of the tool\n * @param {z.ZodTypeAny} [options.parameters] - The parameters of the tool\n * @param {z.ZodTypeAny} [options.outputSchema] - The output schema of the tool\n * @returns {MethodDecorator} - The decorator\n */\nexport const Tool = (options: ToolOptions) => {\n if (options.parameters === undefined) {\n options.parameters = z.object({});\n }\n if (options.outputSchema === undefined) {\n options.outputSchema = z.any();\n }\n return SetMetadata(MCP_TOOL_METADATA_KEY, options);\n};\n"]}
|
|
@@ -24,9 +24,6 @@ export interface McpOptions {
|
|
|
24
24
|
streamableHttp?: {
|
|
25
25
|
enableJsonResponse?: boolean;
|
|
26
26
|
sessionIdGenerator?: () => string;
|
|
27
|
-
/**
|
|
28
|
-
* @experimental: The current implementation does not fully comply with the MCP Specification.
|
|
29
|
-
*/
|
|
30
27
|
statelessMode?: boolean;
|
|
31
28
|
};
|
|
32
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/mcp-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEnD,oBAAY,gBAAgB;IAC1B,GAAG,QAAQ;IACX,eAAe,oBAAoB;IACnC,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,UAAU;IAGzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,SAAS,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAAC;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/mcp-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEnD,oBAAY,gBAAgB;IAC1B,GAAG,QAAQ;IACX,eAAe,oBAAoB;IACnC,KAAK,UAAU;CAChB;AAED,MAAM,WAAW,UAAU;IAGzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,SAAS,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,EAAE,CAAC;IAClD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IAIrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;IAC7B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,GAAG,CAAC,EAAE;QACJ,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,cAAc,CAAC,EAAE;QACf,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,kBAAkB,CAAC,EAAE,MAAM,MAAM,CAAC;QAIlC,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/mcp-options.interface.ts"],"names":[],"mappings":";;;AAGA,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,uDAAmC,CAAA;IACnC,mCAAe,CAAA;AACjB,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B","sourcesContent":["import { ServerCapabilities } from '@modelcontextprotocol/sdk/types.js';\nimport { CanActivate, Type } from '@nestjs/common';\n\nexport enum McpTransportType {\n SSE = 'sse',\n STREAMABLE_HTTP = 'streamable-http',\n STDIO = 'stdio',\n}\n\nexport interface McpOptions {\n // When and if, additional properties are introduced in ServerOptions or ServerInfo,\n // consider deprecating these fields in favor of using ServerOptions and ServerInfo directly.\n name: string;\n version: string;\n capabilities?: ServerCapabilities;\n instructions?: string;\n\n transport?: McpTransportType | McpTransportType[];\n sseEndpoint?: string;\n messagesEndpoint?: string;\n mcpEndpoint?: string;\n globalApiPrefix?: string;\n guards?: Type<CanActivate>[];\n decorators?: ClassDecorator[];\n sse?: {\n pingEnabled?: boolean;\n pingIntervalMs?: number;\n };\n streamableHttp?: {\n enableJsonResponse?: boolean;\n sessionIdGenerator?: () => string;\n /**\n * @experimental: The current implementation does not fully comply with the MCP Specification.\n */\n statelessMode?: boolean;\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/mcp-options.interface.ts"],"names":[],"mappings":";;;AAGA,IAAY,gBAIX;AAJD,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,uDAAmC,CAAA;IACnC,mCAAe,CAAA;AACjB,CAAC,EAJW,gBAAgB,gCAAhB,gBAAgB,QAI3B","sourcesContent":["import { ServerCapabilities } from '@modelcontextprotocol/sdk/types.js';\nimport { CanActivate, Type } from '@nestjs/common';\n\nexport enum McpTransportType {\n SSE = 'sse',\n STREAMABLE_HTTP = 'streamable-http',\n STDIO = 'stdio',\n}\n\nexport interface McpOptions {\n // When and if, additional properties are introduced in ServerOptions or ServerInfo,\n // consider deprecating these fields in favor of using ServerOptions and ServerInfo directly.\n name: string;\n version: string;\n capabilities?: ServerCapabilities;\n instructions?: string;\n\n transport?: McpTransportType | McpTransportType[];\n sseEndpoint?: string;\n messagesEndpoint?: string;\n mcpEndpoint?: string;\n /**\n * @deprecated Use `app.setGlobalPrefix()` instead.\n */\n globalApiPrefix?: string;\n guards?: Type<CanActivate>[];\n decorators?: ClassDecorator[];\n sse?: {\n pingEnabled?: boolean;\n pingIntervalMs?: number;\n };\n streamableHttp?: {\n enableJsonResponse?: boolean;\n sessionIdGenerator?: () => string;\n /**\n * @experimental: The current implementation does not fully comply with the MCP Specification.\n */\n statelessMode?: boolean;\n };\n}\n"]}
|
|
@@ -7,9 +7,6 @@ export type SerializableValue = Literal | SerializableValue[] | {
|
|
|
7
7
|
};
|
|
8
8
|
export type McpRequestSchema = typeof CallToolRequestSchema | typeof ReadResourceRequestSchema | typeof GetPromptRequestSchema;
|
|
9
9
|
export type McpRequest = z.infer<McpRequestSchema>;
|
|
10
|
-
/**
|
|
11
|
-
* Enhanced execution context that includes user information
|
|
12
|
-
*/
|
|
13
10
|
export type Context = {
|
|
14
11
|
reportProgress: (progress: Progress) => Promise<void>;
|
|
15
12
|
log: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tool.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/mcp-tool.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,QAAQ,EACR,yBAAyB,EAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnE,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP,iBAAiB,EAAE,GACnB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAE,CAAC;AAEzC,MAAM,MAAM,gBAAgB,GACxB,OAAO,qBAAqB,GAC5B,OAAO,yBAAyB,GAChC,OAAO,sBAAsB,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-tool.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/mcp-tool.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,QAAQ,EACR,yBAAyB,EAC1B,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,MAAM,MAAM,OAAO,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnE,MAAM,MAAM,iBAAiB,GACzB,OAAO,GACP,iBAAiB,EAAE,GACnB;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAE,CAAC;AAEzC,MAAM,MAAM,gBAAgB,GACxB,OAAO,qBAAqB,GAC5B,OAAO,yBAAyB,GAChC,OAAO,sBAAsB,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAKnD,MAAM,MAAM,OAAO,GAAG;IACpB,cAAc,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtD,GAAG,EAAE;QACH,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;QAC3D,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;QAC3D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;QAC1D,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;KAC3D,CAAC;IACF,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC"}
|
package/dist/mcp.module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.module.d.ts","sourceRoot":"","sources":["../src/mcp.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA0B,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAoB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp.module.d.ts","sourceRoot":"","sources":["../src/mcp.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA0B,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EAAE,UAAU,EAAoB,MAAM,cAAc,CAAC;AAS5D,qBAIa,SAAS;IACpB,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,aAAa;IAuClD,OAAO,CAAC,MAAM,CAAC,4BAA4B;IAuC3C,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAwB1C"}
|
package/dist/mcp.module.js
CHANGED
|
@@ -17,6 +17,7 @@ const sse_ping_service_1 = require("./services/sse-ping.service");
|
|
|
17
17
|
const sse_controller_factory_1 = require("./transport/sse.controller.factory");
|
|
18
18
|
const stdio_service_1 = require("./transport/stdio.service");
|
|
19
19
|
const streamable_http_controller_factory_1 = require("./transport/streamable-http.controller.factory");
|
|
20
|
+
const normalize_endpoint_1 = require("./utils/normalize-endpoint");
|
|
20
21
|
let McpModule = McpModule_1 = class McpModule {
|
|
21
22
|
static forRoot(options) {
|
|
22
23
|
const defaultOptions = {
|
|
@@ -28,7 +29,6 @@ let McpModule = McpModule_1 = class McpModule {
|
|
|
28
29
|
sseEndpoint: 'sse',
|
|
29
30
|
messagesEndpoint: 'messages',
|
|
30
31
|
mcpEndpoint: 'mcp',
|
|
31
|
-
globalApiPrefix: '',
|
|
32
32
|
guards: [],
|
|
33
33
|
decorators: [],
|
|
34
34
|
streamableHttp: {
|
|
@@ -42,6 +42,9 @@ let McpModule = McpModule_1 = class McpModule {
|
|
|
42
42
|
},
|
|
43
43
|
};
|
|
44
44
|
const mergedOptions = { ...defaultOptions, ...options };
|
|
45
|
+
mergedOptions.sseEndpoint = (0, normalize_endpoint_1.normalizeEndpoint)(mergedOptions.sseEndpoint);
|
|
46
|
+
mergedOptions.messagesEndpoint = (0, normalize_endpoint_1.normalizeEndpoint)(mergedOptions.messagesEndpoint);
|
|
47
|
+
mergedOptions.mcpEndpoint = (0, normalize_endpoint_1.normalizeEndpoint)(mergedOptions.mcpEndpoint);
|
|
45
48
|
const providers = this.createProvidersFromOptions(mergedOptions);
|
|
46
49
|
const controllers = this.createControllersFromOptions(mergedOptions);
|
|
47
50
|
return {
|
|
@@ -55,7 +58,6 @@ let McpModule = McpModule_1 = class McpModule {
|
|
|
55
58
|
const sseEndpoint = options.sseEndpoint ?? 'sse';
|
|
56
59
|
const messagesEndpoint = options.messagesEndpoint ?? 'messages';
|
|
57
60
|
const mcpEndpoint = options.mcpEndpoint ?? 'mcp';
|
|
58
|
-
const globalApiPrefix = options.globalApiPrefix ?? '';
|
|
59
61
|
const guards = options.guards ?? [];
|
|
60
62
|
const transports = Array.isArray(options.transport)
|
|
61
63
|
? options.transport
|
|
@@ -63,15 +65,14 @@ let McpModule = McpModule_1 = class McpModule {
|
|
|
63
65
|
const controllers = [];
|
|
64
66
|
const decorators = options.decorators ?? [];
|
|
65
67
|
if (transports.includes(interfaces_1.McpTransportType.SSE)) {
|
|
66
|
-
const sseController = (0, sse_controller_factory_1.createSseController)(sseEndpoint, messagesEndpoint,
|
|
68
|
+
const sseController = (0, sse_controller_factory_1.createSseController)(sseEndpoint, messagesEndpoint, guards, decorators);
|
|
67
69
|
controllers.push(sseController);
|
|
68
70
|
}
|
|
69
71
|
if (transports.includes(interfaces_1.McpTransportType.STREAMABLE_HTTP)) {
|
|
70
|
-
const streamableHttpController = (0, streamable_http_controller_factory_1.createStreamableHttpController)(mcpEndpoint,
|
|
72
|
+
const streamableHttpController = (0, streamable_http_controller_factory_1.createStreamableHttpController)(mcpEndpoint, guards, decorators);
|
|
71
73
|
controllers.push(streamableHttpController);
|
|
72
74
|
}
|
|
73
75
|
if (transports.includes(interfaces_1.McpTransportType.STDIO)) {
|
|
74
|
-
// STDIO transport is handled by injectable StdioService, no controller
|
|
75
76
|
}
|
|
76
77
|
return controllers;
|
|
77
78
|
}
|
package/dist/mcp.module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.module.js","sourceRoot":"","sources":["../src/mcp.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuE;AACvE,uCAA+C;AAC/C,6CAA4D;AAC5D,0EAAqE;AACrE,0EAAqE;AACrE,kEAA6D;AAC7D,+EAAyE;AACzE,6DAAyD;AACzD,uGAAgG;
|
|
1
|
+
{"version":3,"file":"mcp.module.js","sourceRoot":"","sources":["../src/mcp.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuE;AACvE,uCAA+C;AAC/C,6CAA4D;AAC5D,0EAAqE;AACrE,0EAAqE;AACrE,kEAA6D;AAC7D,+EAAyE;AACzE,6DAAyD;AACzD,uGAAgG;AAChG,mEAA+D;AAMxD,IAAM,SAAS,iBAAf,MAAM,SAAS;IACpB,MAAM,CAAC,OAAO,CAAC,OAAmB;QAChC,MAAM,cAAc,GAAwB;YAC1C,SAAS,EAAE;gBACT,6BAAgB,CAAC,GAAG;gBACpB,6BAAgB,CAAC,eAAe;gBAChC,6BAAgB,CAAC,KAAK;aACvB;YACD,WAAW,EAAE,KAAK;YAClB,gBAAgB,EAAE,UAAU;YAC5B,WAAW,EAAE,KAAK;YAClB,MAAM,EAAE,EAAE;YACV,UAAU,EAAE,EAAE;YACd,cAAc,EAAE;gBACd,kBAAkB,EAAE,IAAI;gBACxB,kBAAkB,EAAE,SAAS;gBAC7B,aAAa,EAAE,IAAI;aACpB;YACD,GAAG,EAAE;gBACH,WAAW,EAAE,IAAI;gBACjB,cAAc,EAAE,KAAK;aACtB;SACF,CAAC;QACF,MAAM,aAAa,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAgB,CAAC;QACtE,aAAa,CAAC,WAAW,GAAG,IAAA,sCAAiB,EAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QACzE,aAAa,CAAC,gBAAgB,GAAG,IAAA,sCAAiB,EAChD,aAAa,CAAC,gBAAgB,CAC/B,CAAC;QACF,aAAa,CAAC,WAAW,GAAG,IAAA,sCAAiB,EAAC,aAAa,CAAC,WAAW,CAAC,CAA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F,WAAW,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QAC7C,CAAC;QAED,IAAI,UAAU,CAAC,QAAQ,CAAC,6BAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;QAElD,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,MAAM,CAAC,0BAA0B,CAAC,OAAmB;QAC3D,MAAM,SAAS,GAAe;YAC5B;gBACE,OAAO,EAAE,aAAa;gBACtB,QAAQ,EAAE,OAAO;aAClB;YACD,yCAAkB;YAClB,yCAAkB;SACnB,CAAC;QAEF,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC;YACjD,CAAC,CAAC,OAAO,CAAC,SAAS;YACnB,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,IAAI,6BAAgB,CAAC,GAAG,CAAC,CAAC;QAEhD,IAAI,UAAU,CAAC,QAAQ,CAAC,6BAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;YAC9C,SAAS,CAAC,IAAI,CAAC,iCAAc,CAAC,CAAC;QACjC,CAAC;QAED,IAAI,UAAU,CAAC,QAAQ,CAAC,6BAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChD,SAAS,CAAC,IAAI,CAAC,4BAAY,CAAC,CAAC;QAC/B,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF,CAAA;AAvGY,8BAAS;oBAAT,SAAS;IAJrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAe,CAAC;QAC1B,SAAS,EAAE,CAAC,yCAAkB,EAAE,yCAAkB,CAAC;KACpD,CAAC;GACW,SAAS,CAuGrB","sourcesContent":["import { DynamicModule, Module, Provider, Type } from '@nestjs/common';\nimport { DiscoveryModule } from '@nestjs/core';\nimport { McpOptions, McpTransportType } from './interfaces';\nimport { McpExecutorService } from './services/mcp-executor.service';\nimport { McpRegistryService } from './services/mcp-registry.service';\nimport { SsePingService } from './services/sse-ping.service';\nimport { createSseController } from './transport/sse.controller.factory';\nimport { StdioService } from './transport/stdio.service';\nimport { createStreamableHttpController } from './transport/streamable-http.controller.factory';\nimport { normalizeEndpoint } from './utils/normalize-endpoint';\n\n@Module({\n imports: [DiscoveryModule],\n providers: [McpRegistryService, McpExecutorService],\n})\nexport class McpModule {\n static forRoot(options: McpOptions): DynamicModule {\n const defaultOptions: Partial<McpOptions> = {\n transport: [\n McpTransportType.SSE,\n McpTransportType.STREAMABLE_HTTP,\n McpTransportType.STDIO,\n ],\n sseEndpoint: 'sse',\n messagesEndpoint: 'messages',\n mcpEndpoint: 'mcp',\n guards: [],\n decorators: [],\n streamableHttp: {\n enableJsonResponse: true,\n sessionIdGenerator: undefined,\n statelessMode: true,\n },\n sse: {\n pingEnabled: true,\n pingIntervalMs: 30000,\n },\n };\n const mergedOptions = { ...defaultOptions, ...options } as McpOptions;\n mergedOptions.sseEndpoint = normalizeEndpoint(mergedOptions.sseEndpoint);\n mergedOptions.messagesEndpoint = normalizeEndpoint(\n mergedOptions.messagesEndpoint,\n );\n mergedOptions.mcpEndpoint = normalizeEndpoint(mergedOptions.mcpEndpoint);\n const providers = this.createProvidersFromOptions(mergedOptions);\n const controllers = this.createControllersFromOptions(mergedOptions);\n\n return {\n module: McpModule,\n controllers,\n providers,\n exports: [McpRegistryService],\n };\n }\n\n private static createControllersFromOptions(\n options: McpOptions,\n ): Type<any>[] {\n const sseEndpoint = options.sseEndpoint ?? 'sse';\n const messagesEndpoint = options.messagesEndpoint ?? 'messages';\n const mcpEndpoint = options.mcpEndpoint ?? 'mcp';\n const guards = options.guards ?? [];\n const transports = Array.isArray(options.transport)\n ? options.transport\n : [options.transport ?? McpTransportType.SSE];\n const controllers: Type<any>[] = [];\n const decorators = options.decorators ?? [];\n\n if (transports.includes(McpTransportType.SSE)) {\n const sseController = createSseController(\n sseEndpoint,\n messagesEndpoint,\n guards,\n decorators,\n );\n controllers.push(sseController);\n }\n\n if (transports.includes(McpTransportType.STREAMABLE_HTTP)) {\n const streamableHttpController = createStreamableHttpController(\n mcpEndpoint,\n guards,\n decorators,\n );\n controllers.push(streamableHttpController);\n }\n\n if (transports.includes(McpTransportType.STDIO)) {\n // STDIO transport is handled by injectable StdioService, no controller\n }\n\n return controllers;\n }\n\n private static createProvidersFromOptions(options: McpOptions): Provider[] {\n const providers: Provider[] = [\n {\n provide: 'MCP_OPTIONS',\n useValue: options,\n },\n McpRegistryService,\n McpExecutorService,\n ];\n\n const transports = Array.isArray(options.transport)\n ? options.transport\n : [options.transport ?? McpTransportType.SSE];\n\n if (transports.includes(McpTransportType.SSE)) {\n providers.push(SsePingService);\n }\n\n if (transports.includes(McpTransportType.STDIO)) {\n providers.push(StdioService);\n }\n\n return providers;\n }\n}\n"]}
|
|
@@ -9,7 +9,6 @@ class McpHandlerBase {
|
|
|
9
9
|
this.logger = new common_1.Logger(loggerContext);
|
|
10
10
|
}
|
|
11
11
|
createContext(mcpServer, mcpRequest) {
|
|
12
|
-
// handless stateless traffic where notifications and progress are not supported
|
|
13
12
|
if (mcpServer.server.transport.sessionId === undefined) {
|
|
14
13
|
return this.createStatelessContext(mcpServer, mcpRequest);
|
|
15
14
|
}
|
|
@@ -61,24 +60,19 @@ class McpHandlerBase {
|
|
|
61
60
|
this.logger.warn(`Stateless context: '${fn}' is not supported.`);
|
|
62
61
|
};
|
|
63
62
|
return {
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/require-await,@typescript-eslint/no-unused-vars
|
|
65
63
|
reportProgress: async (_progress) => {
|
|
66
64
|
warn('reportProgress not supported in stateless');
|
|
67
65
|
},
|
|
68
66
|
log: {
|
|
69
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
67
|
debug: (_message, _data) => {
|
|
71
68
|
warn('server report logging not supported in stateless');
|
|
72
69
|
},
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
74
70
|
error: (_message, _data) => {
|
|
75
71
|
warn('server report logging not supported in stateless');
|
|
76
72
|
},
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
78
73
|
info: (_message, _data) => {
|
|
79
74
|
warn('server report logging not supported in stateless');
|
|
80
75
|
},
|
|
81
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
82
76
|
warn: (_message, _data) => {
|
|
83
77
|
warn('server report logging not supported in stateless');
|
|
84
78
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-handler.base.js","sourceRoot":"","sources":["../../../src/services/handlers/mcp-handler.base.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAOxC,MAAsB,cAAc;IAGlC,YACqB,SAAoB,EACpB,QAA4B,EAC/C,aAAqB;QAFF,cAAS,GAAT,SAAS,CAAW;QACpB,aAAQ,GAAR,QAAQ,CAAoB;QAG/C,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,aAAa,CAAC,CAAC;IAC1C,CAAC;IAES,aAAa,CACrB,SAAoB,EACpB,UAAsB;
|
|
1
|
+
{"version":3,"file":"mcp-handler.base.js","sourceRoot":"","sources":["../../../src/services/handlers/mcp-handler.base.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AAOxC,MAAsB,cAAc;IAGlC,YACqB,SAAoB,EACpB,QAA4B,EAC/C,aAAqB;QAFF,cAAS,GAAT,SAAS,CAAW;QACpB,aAAQ,GAAR,QAAQ,CAAoB;QAG/C,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,aAAa,CAAC,CAAC;IAC1C,CAAC;IAES,aAAa,CACrB,SAAoB,EACpB,UAAsB;QAGtB,IAAK,SAAS,CAAC,MAAM,CAAC,SAAiB,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;YAChE,OAAO,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QAC5D,CAAC;QAED,MAAM,aAAa,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,aAAa,CAAC;QAC9D,OAAO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AI,GAAG,CAAC,EAAU,EAAE,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,EAAE,qBAAqB,CAAC,CAAC;QACnE,CAAC,CAAC;QACF,OAAO;YAEL,cAAc,EAAE,KAAK,EAAE,SAAmB,EAAE,EAAE;gBAC5C,IAAI,CAAC,2CAA2C,CAAC,CAAC;YACpD,CAAC;YACD,GAAG,EAAE;gBAEH,KAAK,EAAE,CAAC,QAAgB,EAAE,KAAyB,EAAE,EAAE;oBACrD,IAAI,CAAC,kDAAkD,CAAC,CAAC;gBAC3D,CAAC;gBAED,KAAK,EAAE,CAAC,QAAgB,EAAE,KAAyB,EAAE,EAAE;oBACrD,IAAI,CAAC,kDAAkD,CAAC,CAAC;gBAC3D,CAAC;gBAED,IAAI,EAAE,CAAC,QAAgB,EAAE,KAAyB,EAAE,EAAE;oBACpD,IAAI,CAAC,kDAAkD,CAAC,CAAC;gBAC3D,CAAC;gBAED,IAAI,EAAE,CAAC,QAAgB,EAAE,KAAyB,EAAE,EAAE;oBACpD,IAAI,CAAC,kDAAkD,CAAC,CAAC;gBAC3D,CAAC;aACF;YACD,SAAS;YACT,UAAU;SACX,CAAC;IACJ,CAAC;CACF;AAlGD,wCAkGC","sourcesContent":["import { Logger } from '@nestjs/common';\nimport { ModuleRef } from '@nestjs/core';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { Progress } from '@modelcontextprotocol/sdk/types.js';\nimport { Context, McpRequest, SerializableValue } from '../../interfaces';\nimport { McpRegistryService } from '../mcp-registry.service';\n\nexport abstract class McpHandlerBase {\n protected logger: Logger;\n\n constructor(\n protected readonly moduleRef: ModuleRef,\n protected readonly registry: McpRegistryService,\n loggerContext: string,\n ) {\n this.logger = new Logger(loggerContext);\n }\n\n protected createContext(\n mcpServer: McpServer,\n mcpRequest: McpRequest,\n ): Context {\n // handless stateless traffic where notifications and progress are not supported\n if ((mcpServer.server.transport as any).sessionId === undefined) {\n return this.createStatelessContext(mcpServer, mcpRequest);\n }\n\n const progressToken = mcpRequest.params?._meta?.progressToken;\n return {\n reportProgress: async (progress: Progress) => {\n if (progressToken) {\n await mcpServer.server.notification({\n method: 'notifications/progress',\n params: {\n ...progress,\n progressToken,\n } as Progress,\n });\n }\n },\n log: {\n debug: (message: string, context?: SerializableValue) => {\n void mcpServer.server.sendLoggingMessage({\n level: 'debug',\n data: { message, context },\n });\n },\n error: (message: string, context?: SerializableValue) => {\n void mcpServer.server.sendLoggingMessage({\n level: 'error',\n data: { message, context },\n });\n },\n info: (message: string, context?: SerializableValue) => {\n void mcpServer.server.sendLoggingMessage({\n level: 'info',\n data: { message, context },\n });\n },\n warn: (message: string, context?: SerializableValue) => {\n void mcpServer.server.sendLoggingMessage({\n level: 'warning',\n data: { message, context },\n });\n },\n },\n mcpServer,\n mcpRequest,\n };\n }\n\n protected createStatelessContext(\n mcpServer: McpServer,\n mcpRequest: McpRequest,\n ): Context {\n const warn = (fn: string) => {\n this.logger.warn(`Stateless context: '${fn}' is not supported.`);\n };\n return {\n // eslint-disable-next-line @typescript-eslint/require-await,@typescript-eslint/no-unused-vars\n reportProgress: async (_progress: Progress) => {\n warn('reportProgress not supported in stateless');\n },\n log: {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n debug: (_message: string, _data?: SerializableValue) => {\n warn('server report logging not supported in stateless');\n },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n error: (_message: string, _data?: SerializableValue) => {\n warn('server report logging not supported in stateless');\n },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n info: (_message: string, _data?: SerializableValue) => {\n warn('server report logging not supported in stateless');\n },\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n warn: (_message: string, _data?: SerializableValue) => {\n warn('server report logging not supported in stateless');\n },\n },\n mcpServer,\n mcpRequest,\n };\n }\n}\n"]}
|
|
@@ -60,7 +60,6 @@ let McpPromptsHandler = McpPromptsHandler_1 = class McpPromptsHandler extends mc
|
|
|
60
60
|
const methodName = promptInfo.methodName;
|
|
61
61
|
const result = await promptInstance[methodName].call(promptInstance, request.params.arguments, context, httpRequest);
|
|
62
62
|
this.logger.debug(result, 'GetPromptRequestSchema result');
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
64
63
|
return result;
|
|
65
64
|
}
|
|
66
65
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-prompts.handler.js","sourceRoot":"","sources":["../../../src/services/handlers/mcp-prompts.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAmD;AACnD,uCAA2D;AAE3D,iEAM4C;AAE5C,kEAA6D;AAC7D,yDAAoD;AAG7C,IAAM,iBAAiB,yBAAvB,MAAM,iBAAkB,SAAQ,iCAAc;IACnD,YAAY,SAAoB,EAAE,QAA4B;QAC5D,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,mBAAiB,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,gBAAgB,CAAC,SAAoB,EAAE,WAAoB;QACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACrE,OAAO;QACT,CAAC;QACD,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,mCAAwB,EAAE,GAAG,EAAE;YAChE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;YAE9D,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;gBAC1D,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,IAAI;gBAC1B,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW;gBACxC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,UAAU;oBAC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AU,CAAC,aAAa,EACxB,SAAS,EACT,EAAE,MAAM,EAAE,KAAK,EAAE,CAClB,CAAC;gBAEF,IAAI,CAAC,cAAc,EAAE,CAAC;oBACpB,MAAM,IAAI,mBAAQ,CAChB,oBAAS,CAAC,cAAc,EACxB,mBAAmB,IAAI,EAAE,CAC1B,CAAC;gBACJ,CAAC;gBAED,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;gBACvD,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;gBAEzC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,UAAU,CAAC,CAAC,IAAI,CAClD,cAAc,EACd,OAAO,CAAC,MAAM,CAAC,SAAS,EACxB,OAAO,EACP,WAAW,CACZ,CAAC;gBAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC;gBAG3D,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACzB,OAAO;oBACL,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;oBAC3D,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF,CAAA;AAxFY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;qCAEZ,gBAAS,EAAY,yCAAkB;GADnD,iBAAiB,CAwF7B","sourcesContent":["import { Injectable, Scope } from '@nestjs/common';\nimport { ContextIdFactory, ModuleRef } from '@nestjs/core';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport {\n ErrorCode,\n GetPromptRequestSchema,\n ListPromptsRequestSchema,\n McpError,\n PromptArgument,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { Request } from 'express';\nimport { McpRegistryService } from '../mcp-registry.service';\nimport { McpHandlerBase } from './mcp-handler.base';\n\n@Injectable({ scope: Scope.REQUEST })\nexport class McpPromptsHandler extends McpHandlerBase {\n constructor(moduleRef: ModuleRef, registry: McpRegistryService) {\n super(moduleRef, registry, McpPromptsHandler.name);\n }\n\n registerHandlers(mcpServer: McpServer, httpRequest: Request) {\n if (this.registry.getPrompts().length === 0) {\n this.logger.debug('No prompts registered, skipping prompt handlers');\n return;\n }\n mcpServer.server.setRequestHandler(ListPromptsRequestSchema, () => {\n this.logger.debug('ListPromptsRequestSchema is being called');\n\n const prompts = this.registry.getPrompts().map((prompt) => ({\n name: prompt.metadata.name,\n description: prompt.metadata.description,\n arguments: prompt.metadata.parameters\n ? Object.entries(prompt.metadata.parameters.shape).map(\n ([name, field]): PromptArgument => ({\n name,\n description: field.description,\n required: !field.isOptional(),\n }),\n )\n : [],\n }));\n\n return {\n prompts,\n };\n });\n\n mcpServer.server.setRequestHandler(\n GetPromptRequestSchema,\n async (request) => {\n this.logger.debug('GetPromptRequestSchema is being called');\n\n try {\n const name = request.params.name;\n const promptInfo = this.registry.findPrompt(name);\n\n if (!promptInfo) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown prompt: ${name}`,\n );\n }\n\n const contextId = ContextIdFactory.getByRequest(httpRequest);\n this.moduleRef.registerRequestByContextId(httpRequest, contextId);\n\n const promptInstance = await this.moduleRef.resolve(\n promptInfo.providerClass,\n contextId,\n { strict: false },\n );\n\n if (!promptInstance) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown prompt: ${name}`,\n );\n }\n\n const context = this.createContext(mcpServer, request);\n const methodName = promptInfo.methodName;\n\n const result = await promptInstance[methodName].call(\n promptInstance,\n request.params.arguments,\n context,\n httpRequest,\n );\n\n this.logger.debug(result, 'GetPromptRequestSchema result');\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n } catch (error) {\n this.logger.error(error);\n return {\n contents: [{ mimeType: 'text/plain', text: error.message }],\n isError: true,\n };\n }\n },\n );\n }\n}\n"]}
|
|
@@ -55,7 +55,6 @@ let McpResourcesHandler = McpResourcesHandler_1 = class McpResourcesHandler exte
|
|
|
55
55
|
const methodName = resourceInfo.resource.methodName;
|
|
56
56
|
const result = await resourceInstance[methodName].call(resourceInstance, requestParams, context, httpRequest);
|
|
57
57
|
this.logger.debug(result, 'ReadResourceRequestSchema result');
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
59
58
|
return result;
|
|
60
59
|
}
|
|
61
60
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-resources.handler.js","sourceRoot":"","sources":["../../../src/services/handlers/mcp-resources.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAmD;AACnD,uCAA2D;AAE3D,iEAK4C;AAE5C,kEAA6D;AAC7D,yDAAoD;AAG7C,IAAM,mBAAmB,2BAAzB,MAAM,mBAAoB,SAAQ,iCAAc;IACrD,YAAY,SAAoB,EAAE,QAA4B;QAC5D,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,qBAAmB,CAAC,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,gBAAgB,CAAC,SAAoB,EAAE,WAAoB;QACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;YACzE,OAAO;QACT,CAAC;QAED,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,qCAA0B,EAAE,GAAG,EAAE;YAClE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,4CAA4C,CAAC,CAAC;YAChE,OAAO;gBACL,SAAS,EAAE,IAAI,CAAC,QAAQ;qBACrB,YAAY,EAAE;qBACd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C,CAAC,CAAC;gBAG9D,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACzB,OAAO;oBACL,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;oBAChE,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF,CAAA;AAlFY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;qCAEZ,gBAAS,EAAY,yCAAkB;GADnD,mBAAmB,CAkF/B","sourcesContent":["import { Injectable, Scope } from '@nestjs/common';\nimport { ContextIdFactory, ModuleRef } from '@nestjs/core';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport {\n ErrorCode,\n ListResourcesRequestSchema,\n McpError,\n ReadResourceRequestSchema,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { Request } from 'express';\nimport { McpRegistryService } from '../mcp-registry.service';\nimport { McpHandlerBase } from './mcp-handler.base';\n\n@Injectable({ scope: Scope.REQUEST })\nexport class McpResourcesHandler extends McpHandlerBase {\n constructor(moduleRef: ModuleRef, registry: McpRegistryService) {\n super(moduleRef, registry, McpResourcesHandler.name);\n }\n\n registerHandlers(mcpServer: McpServer, httpRequest: Request) {\n if (this.registry.getResources().length === 0) {\n this.logger.debug('No resources registered, skipping resource handlers');\n return;\n }\n\n mcpServer.server.setRequestHandler(ListResourcesRequestSchema, () => {\n this.logger.debug('ListResourcesRequestSchema is being called');\n return {\n resources: this.registry\n .getResources()\n .map((resources) => resources.metadata),\n };\n });\n\n mcpServer.server.setRequestHandler(\n ReadResourceRequestSchema,\n async (request) => {\n this.logger.debug('ReadResourceRequestSchema is being called');\n\n const uri = request.params.uri;\n const resourceInfo = this.registry.findResourceByUri(uri);\n\n if (!resourceInfo) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown resource: ${uri}`,\n );\n }\n\n try {\n const contextId = ContextIdFactory.getByRequest(httpRequest);\n this.moduleRef.registerRequestByContextId(httpRequest, contextId);\n\n const resourceInstance = await this.moduleRef.resolve(\n resourceInfo.resource.providerClass,\n contextId,\n { strict: false },\n );\n\n if (!resourceInstance) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown resource: ${uri}`,\n );\n }\n\n const context = this.createContext(mcpServer, request);\n\n const requestParams = {\n ...resourceInfo.params,\n ...request.params,\n };\n\n const methodName = resourceInfo.resource.methodName;\n\n const result = await resourceInstance[methodName].call(\n resourceInstance,\n requestParams,\n context,\n httpRequest,\n );\n\n this.logger.debug(result, 'ReadResourceRequestSchema result');\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n } catch (error) {\n this.logger.error(error);\n return {\n contents: [{ uri, mimeType: 'text/plain', text: error.message }],\n isError: true,\n };\n }\n },\n );\n }\n}\n"]}
|
|
@@ -28,20 +28,16 @@ let McpToolsHandler = McpToolsHandler_1 = class McpToolsHandler extends mcp_hand
|
|
|
28
28
|
}
|
|
29
29
|
mcpServer.server.setRequestHandler(types_js_1.ListToolsRequestSchema, () => {
|
|
30
30
|
const tools = this.registry.getTools().map((tool) => {
|
|
31
|
-
// Create base schema
|
|
32
31
|
const toolSchema = {
|
|
33
32
|
name: tool.metadata.name,
|
|
34
33
|
description: tool.metadata.description,
|
|
35
34
|
annotations: tool.metadata.annotations,
|
|
36
35
|
};
|
|
37
|
-
// Add input schema if defined
|
|
38
36
|
if (tool.metadata.parameters) {
|
|
39
37
|
toolSchema['inputSchema'] = (0, zod_to_json_schema_1.zodToJsonSchema)(tool.metadata.parameters);
|
|
40
38
|
}
|
|
41
|
-
// Add output schema if defined, ensuring it has type: 'object'
|
|
42
39
|
if (tool.metadata.outputSchema) {
|
|
43
40
|
const outputSchema = (0, zod_to_json_schema_1.zodToJsonSchema)(tool.metadata.outputSchema);
|
|
44
|
-
// Create a new object that explicitly includes type: 'object'
|
|
45
41
|
const jsonSchema = {
|
|
46
42
|
...outputSchema,
|
|
47
43
|
type: 'object',
|
|
@@ -70,7 +66,6 @@ let McpToolsHandler = McpToolsHandler_1 = class McpToolsHandler extends mcp_hand
|
|
|
70
66
|
}
|
|
71
67
|
const result = await toolInstance[toolInfo.methodName].call(toolInstance, request.params.arguments, context, httpRequest);
|
|
72
68
|
this.logger.debug(result, 'CallToolRequestSchema result');
|
|
73
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
74
69
|
return result;
|
|
75
70
|
}
|
|
76
71
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tools.handler.js","sourceRoot":"","sources":["../../../src/services/handlers/mcp-tools.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,iEAK4C;AAC5C,2CAAmD;AACnD,uCAA2D;AAE3D,2DAAqD;AACrD,kEAA6D;AAC7D,yDAAoD;AAG7C,IAAM,eAAe,uBAArB,MAAM,eAAgB,SAAQ,iCAAc;IACjD,YAAY,SAAoB,EAAE,QAA4B;QAC5D,KAAK,CAAC,SAAS,EAAE,QAAQ,EAAE,iBAAe,CAAC,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,gBAAgB,CAAC,SAAoB,EAAE,WAAoB;QACzD,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,6CAA6C,CAAC,CAAC;YACjE,OAAO;QACT,CAAC;QAED,SAAS,CAAC,MAAM,CAAC,iBAAiB,CAAC,iCAAsB,EAAE,GAAG,EAAE;YAC9D,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,CA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BAAiB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CACvC,CAAC;gBACJ,CAAC;gBAED,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,IAAI,CACzD,YAAY,EACZ,OAAO,CAAC,MAAM,CAAC,SAAS,EACxB,OAAO,EACP,WAAW,CACZ,CAAC;gBAEF,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,8BAA8B,CAAC,CAAC;gBAG1D,OAAO,MAAM,CAAC;YAChB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBACzB,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;oBAChD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF,CAAA;AApGY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;qCAEZ,gBAAS,EAAY,yCAAkB;GADnD,eAAe,CAoG3B","sourcesContent":["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport {\n CallToolRequestSchema,\n ErrorCode,\n ListToolsRequestSchema,\n McpError,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { Injectable, Scope } from '@nestjs/common';\nimport { ContextIdFactory, ModuleRef } from '@nestjs/core';\nimport { Request } from 'express';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport { McpRegistryService } from '../mcp-registry.service';\nimport { McpHandlerBase } from './mcp-handler.base';\n\n@Injectable({ scope: Scope.REQUEST })\nexport class McpToolsHandler extends McpHandlerBase {\n constructor(moduleRef: ModuleRef, registry: McpRegistryService) {\n super(moduleRef, registry, McpToolsHandler.name);\n }\n\n registerHandlers(mcpServer: McpServer, httpRequest: Request) {\n if (this.registry.getTools().length === 0) {\n this.logger.debug('No tools registered, skipping tool handlers');\n return;\n }\n\n mcpServer.server.setRequestHandler(ListToolsRequestSchema, () => {\n const tools = this.registry.getTools().map((tool) => {\n // Create base schema\n const toolSchema = {\n name: tool.metadata.name,\n description: tool.metadata.description,\n annotations: tool.metadata.annotations,\n };\n\n // Add input schema if defined\n if (tool.metadata.parameters) {\n toolSchema['inputSchema'] = zodToJsonSchema(tool.metadata.parameters);\n }\n\n // Add output schema if defined, ensuring it has type: 'object'\n if (tool.metadata.outputSchema) {\n const outputSchema = zodToJsonSchema(tool.metadata.outputSchema);\n\n // Create a new object that explicitly includes type: 'object'\n const jsonSchema = {\n ...outputSchema,\n type: 'object',\n };\n\n toolSchema['outputSchema'] = jsonSchema;\n }\n\n return toolSchema;\n });\n\n return {\n tools,\n };\n });\n\n mcpServer.server.setRequestHandler(\n CallToolRequestSchema,\n async (request) => {\n this.logger.debug('CallToolRequestSchema is being called');\n\n const toolInfo = this.registry.findTool(request.params.name);\n\n if (!toolInfo) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown tool: ${request.params.name}`,\n );\n }\n\n try {\n const contextId = ContextIdFactory.getByRequest(httpRequest);\n this.moduleRef.registerRequestByContextId(httpRequest, contextId);\n\n const toolInstance = await this.moduleRef.resolve(\n toolInfo.providerClass,\n contextId,\n { strict: false },\n );\n\n const context = this.createContext(mcpServer, request);\n\n if (!toolInstance) {\n throw new McpError(\n ErrorCode.MethodNotFound,\n `Unknown tool: ${request.params.name}`,\n );\n }\n\n const result = await toolInstance[toolInfo.methodName].call(\n toolInstance,\n request.params.arguments,\n context,\n httpRequest,\n );\n\n this.logger.debug(result, 'CallToolRequestSchema result');\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return result;\n } catch (error) {\n this.logger.error(error);\n return {\n content: [{ type: 'text', text: error.message }],\n isError: true,\n };\n }\n },\n );\n }\n}\n"]}
|
|
@@ -2,20 +2,12 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
|
2
2
|
import { ModuleRef } from '@nestjs/core';
|
|
3
3
|
import { Request } from 'express';
|
|
4
4
|
import { McpRegistryService } from './mcp-registry.service';
|
|
5
|
-
/**
|
|
6
|
-
* Request-scoped service for executing MCP tools
|
|
7
|
-
*/
|
|
8
5
|
export declare class McpExecutorService {
|
|
9
6
|
private logger;
|
|
10
7
|
private toolsHandler;
|
|
11
8
|
private resourcesHandler;
|
|
12
9
|
private promptsHandler;
|
|
13
10
|
constructor(moduleRef: ModuleRef, registry: McpRegistryService);
|
|
14
|
-
/**
|
|
15
|
-
* Register tool-related request handlers with the MCP server
|
|
16
|
-
* @param mcpServer - The MCP server instance
|
|
17
|
-
* @param request - The current HTTP request object
|
|
18
|
-
*/
|
|
19
11
|
registerRequestHandlers(mcpServer: McpServer, httpRequest: Request): void;
|
|
20
12
|
}
|
|
21
13
|
//# sourceMappingURL=mcp-executor.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-executor.service.d.ts","sourceRoot":"","sources":["../../src/services/mcp-executor.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-executor.service.d.ts","sourceRoot":"","sources":["../../src/services/mcp-executor.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAQ5D,qBACa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,YAAY,CAAkB;IACtC,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,cAAc,CAAoB;gBAE9B,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB;IAW9D,uBAAuB,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO;CAKnE"}
|
|
@@ -17,9 +17,6 @@ const mcp_registry_service_1 = require("./mcp-registry.service");
|
|
|
17
17
|
const mcp_tools_handler_1 = require("./handlers/mcp-tools.handler");
|
|
18
18
|
const mcp_resources_handler_1 = require("./handlers/mcp-resources.handler");
|
|
19
19
|
const mcp_prompts_handler_1 = require("./handlers/mcp-prompts.handler");
|
|
20
|
-
/**
|
|
21
|
-
* Request-scoped service for executing MCP tools
|
|
22
|
-
*/
|
|
23
20
|
let McpExecutorService = McpExecutorService_1 = class McpExecutorService {
|
|
24
21
|
constructor(moduleRef, registry) {
|
|
25
22
|
this.logger = new common_1.Logger(McpExecutorService_1.name);
|
|
@@ -27,11 +24,6 @@ let McpExecutorService = McpExecutorService_1 = class McpExecutorService {
|
|
|
27
24
|
this.resourcesHandler = new mcp_resources_handler_1.McpResourcesHandler(moduleRef, registry);
|
|
28
25
|
this.promptsHandler = new mcp_prompts_handler_1.McpPromptsHandler(moduleRef, registry);
|
|
29
26
|
}
|
|
30
|
-
/**
|
|
31
|
-
* Register tool-related request handlers with the MCP server
|
|
32
|
-
* @param mcpServer - The MCP server instance
|
|
33
|
-
* @param request - The current HTTP request object
|
|
34
|
-
*/
|
|
35
27
|
registerRequestHandlers(mcpServer, httpRequest) {
|
|
36
28
|
this.toolsHandler.registerHandlers(mcpServer, httpRequest);
|
|
37
29
|
this.resourcesHandler.registerHandlers(mcpServer, httpRequest);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-executor.service.js","sourceRoot":"","sources":["../../src/services/mcp-executor.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,2CAA2D;AAC3D,uCAAyC;AAEzC,iEAA4D;AAC5D,oEAA+D;AAC/D,4EAAuE;AACvE,wEAAmE;
|
|
1
|
+
{"version":3,"file":"mcp-executor.service.js","sourceRoot":"","sources":["../../src/services/mcp-executor.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,2CAA2D;AAC3D,uCAAyC;AAEzC,iEAA4D;AAC5D,oEAA+D;AAC/D,4EAAuE;AACvE,wEAAmE;AAM5D,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAM7B,YAAY,SAAoB,EAAE,QAA4B;QALtD,WAAM,GAAG,IAAI,eAAM,CAAC,oBAAkB,CAAC,IAAI,CAAC,CAAC;QAMnD,IAAI,CAAC,YAAY,GAAG,IAAI,mCAAe,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC7D,IAAI,CAAC,gBAAgB,GAAG,IAAI,2CAAmB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACrE,IAAI,CAAC,cAAc,GAAG,IAAI,uCAAiB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACnE,CAAC;IAOD,uBAAuB,CAAC,SAAoB,EAAE,WAAoB;QAChE,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC3D,IAAI,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAC/D,IAAI,CAAC,cAAc,CAAC,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAC/D,CAAC;CACF,CAAA;AAtBY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,EAAC,EAAE,KAAK,EAAE,cAAK,CAAC,OAAO,EAAE,CAAC;qCAOZ,gBAAS,EAAY,yCAAkB;GANnD,kBAAkB,CAsB9B","sourcesContent":["import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { Injectable, Logger, Scope } from '@nestjs/common';\nimport { ModuleRef } from '@nestjs/core';\nimport { Request } from 'express';\nimport { McpRegistryService } from './mcp-registry.service';\nimport { McpToolsHandler } from './handlers/mcp-tools.handler';\nimport { McpResourcesHandler } from './handlers/mcp-resources.handler';\nimport { McpPromptsHandler } from './handlers/mcp-prompts.handler';\n\n/**\n * Request-scoped service for executing MCP tools\n */\n@Injectable({ scope: Scope.REQUEST })\nexport class McpExecutorService {\n private logger = new Logger(McpExecutorService.name);\n private toolsHandler: McpToolsHandler;\n private resourcesHandler: McpResourcesHandler;\n private promptsHandler: McpPromptsHandler;\n\n constructor(moduleRef: ModuleRef, registry: McpRegistryService) {\n this.toolsHandler = new McpToolsHandler(moduleRef, registry);\n this.resourcesHandler = new McpResourcesHandler(moduleRef, registry);\n this.promptsHandler = new McpPromptsHandler(moduleRef, registry);\n }\n\n /**\n * Register tool-related request handlers with the MCP server\n * @param mcpServer - The MCP server instance\n * @param request - The current HTTP request object\n */\n registerRequestHandlers(mcpServer: McpServer, httpRequest: Request) {\n this.toolsHandler.registerHandlers(mcpServer, httpRequest);\n this.resourcesHandler.registerHandlers(mcpServer, httpRequest);\n this.promptsHandler.registerHandlers(mcpServer, httpRequest);\n }\n}\n"]}
|
|
@@ -3,18 +3,12 @@ import { DiscoveryService, MetadataScanner } from '@nestjs/core';
|
|
|
3
3
|
import { ToolMetadata } from '../decorators';
|
|
4
4
|
import { ResourceMetadata } from '../decorators/resource.decorator';
|
|
5
5
|
import { PromptMetadata } from '../decorators/prompt.decorator';
|
|
6
|
-
/**
|
|
7
|
-
* Interface representing a discovered tool
|
|
8
|
-
*/
|
|
9
6
|
export type DiscoveredTool<T extends object> = {
|
|
10
7
|
type: 'tool' | 'resource' | 'prompt';
|
|
11
8
|
metadata: T;
|
|
12
9
|
providerClass: InjectionToken;
|
|
13
10
|
methodName: string;
|
|
14
11
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Singleton service that discovers and registers tools during application bootstrap
|
|
17
|
-
*/
|
|
18
12
|
export declare class McpRegistryService implements OnApplicationBootstrap {
|
|
19
13
|
private readonly discovery;
|
|
20
14
|
private readonly metadataScanner;
|
|
@@ -22,47 +16,19 @@ export declare class McpRegistryService implements OnApplicationBootstrap {
|
|
|
22
16
|
private discoveredTools;
|
|
23
17
|
constructor(discovery: DiscoveryService, metadataScanner: MetadataScanner);
|
|
24
18
|
onApplicationBootstrap(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Scans all providers and controllers for @Tool decorators
|
|
27
|
-
*/
|
|
28
19
|
private discoverTools;
|
|
29
|
-
/**
|
|
30
|
-
* Adds a discovered tool to the registry
|
|
31
|
-
*/
|
|
32
20
|
private addDiscovery;
|
|
33
21
|
private addDiscoveryPrompt;
|
|
34
22
|
private addDiscoveryTool;
|
|
35
23
|
private addDiscoveryResource;
|
|
36
|
-
/**
|
|
37
|
-
* Get all discovered tools
|
|
38
|
-
*/
|
|
39
24
|
getTools(): DiscoveredTool<ToolMetadata>[];
|
|
40
|
-
/**
|
|
41
|
-
* Find a tool by name
|
|
42
|
-
*/
|
|
43
25
|
findTool(name: string): DiscoveredTool<ToolMetadata> | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* Get all discovered resources
|
|
46
|
-
*/
|
|
47
26
|
getResources(): DiscoveredTool<ResourceMetadata>[];
|
|
48
|
-
/**
|
|
49
|
-
* Find a resource by name
|
|
50
|
-
*/
|
|
51
27
|
findResource(name: string): DiscoveredTool<ResourceMetadata> | undefined;
|
|
52
|
-
/**
|
|
53
|
-
* Get all discovered prompts
|
|
54
|
-
*/
|
|
55
28
|
getPrompts(): DiscoveredTool<PromptMetadata>[];
|
|
56
|
-
/**
|
|
57
|
-
* Find a prompt by name
|
|
58
|
-
*/
|
|
59
29
|
findPrompt(name: string): DiscoveredTool<PromptMetadata> | undefined;
|
|
60
30
|
private convertTemplate;
|
|
61
31
|
private convertUri;
|
|
62
|
-
/**
|
|
63
|
-
* Find a resource by uri
|
|
64
|
-
* @returns An object containing the found resource and extracted parameters, or undefined if no resource is found
|
|
65
|
-
*/
|
|
66
32
|
findResourceByUri(uri: string): {
|
|
67
33
|
resource: DiscoveredTool<ResourceMetadata>;
|
|
68
34
|
params: Record<string, string>;
|