@nestjs-mcp/server 0.1.0-alpha.4
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/.copilotignore +38 -0
- package/.devcontainer/Dockerfile.dev +28 -0
- package/.devcontainer/devcontainer.json +56 -0
- package/.devcontainer/docker-compose.yml +15 -0
- package/.dockerignore +37 -0
- package/.github/codeql-config.yml +4 -0
- package/.github/copilot-instructions.md +138 -0
- package/.github/prompts/memory.prompt.md +120 -0
- package/.github/workflows/auto-tag-release.yml +84 -0
- package/.github/workflows/codeql-analysis.yml +56 -0
- package/.github/workflows/npm-publish.yml +58 -0
- package/.github/workflows/pr-branch-validation.yml +78 -0
- package/.github/workflows/run-tests.yml +41 -0
- package/.github/workflows/sync-main-to-develop.yml +53 -0
- package/.handbook/GIT_GUIDELINES.md +250 -0
- package/.handbook/PACKAGE_VERSIONING.md +140 -0
- package/.handbook/STACK.md +75 -0
- package/.prettierrc +4 -0
- package/.vscode/extensions.json +44 -0
- package/.vscode/settings.json +40 -0
- package/CONTRIBUTING.md +261 -0
- package/LICENSE +21 -0
- package/README.md +490 -0
- package/dist/examples/async-import/app.module.d.ts +2 -0
- package/dist/examples/async-import/app.module.js +33 -0
- package/dist/examples/async-import/app.module.js.map +1 -0
- package/dist/examples/async-import/main.d.ts +1 -0
- package/dist/examples/async-import/main.js +17 -0
- package/dist/examples/async-import/main.js.map +1 -0
- package/dist/examples/guards/app.module.d.ts +6 -0
- package/dist/examples/guards/app.module.js +48 -0
- package/dist/examples/guards/app.module.js.map +1 -0
- package/dist/examples/guards/guards.resolver.d.ts +13 -0
- package/dist/examples/guards/guards.resolver.js +61 -0
- package/dist/examples/guards/guards.resolver.js.map +1 -0
- package/dist/examples/guards/main.d.ts +1 -0
- package/dist/examples/guards/main.js +11 -0
- package/dist/examples/guards/main.js.map +1 -0
- package/dist/examples/mixed/app.module.d.ts +2 -0
- package/dist/examples/mixed/app.module.js +31 -0
- package/dist/examples/mixed/app.module.js.map +1 -0
- package/dist/examples/mixed/main.d.ts +1 -0
- package/dist/examples/mixed/main.js +11 -0
- package/dist/examples/mixed/main.js.map +1 -0
- package/dist/examples/mixed/mixed.resolver.d.ts +6 -0
- package/dist/examples/mixed/mixed.resolver.js +78 -0
- package/dist/examples/mixed/mixed.resolver.js.map +1 -0
- package/dist/examples/prompts/app.module.d.ts +2 -0
- package/dist/examples/prompts/app.module.js +31 -0
- package/dist/examples/prompts/app.module.js.map +1 -0
- package/dist/examples/prompts/main.d.ts +1 -0
- package/dist/examples/prompts/main.js +11 -0
- package/dist/examples/prompts/main.js.map +1 -0
- package/dist/examples/prompts/prompts.resolver.d.ts +14 -0
- package/dist/examples/prompts/prompts.resolver.js +165 -0
- package/dist/examples/prompts/prompts.resolver.js.map +1 -0
- package/dist/examples/resources/app.module.d.ts +2 -0
- package/dist/examples/resources/app.module.js +31 -0
- package/dist/examples/resources/app.module.js.map +1 -0
- package/dist/examples/resources/main.d.ts +1 -0
- package/dist/examples/resources/main.js +11 -0
- package/dist/examples/resources/main.js.map +1 -0
- package/dist/examples/resources/resources.resolver.d.ts +12 -0
- package/dist/examples/resources/resources.resolver.js +114 -0
- package/dist/examples/resources/resources.resolver.js.map +1 -0
- package/dist/examples/tools/app.module.d.ts +2 -0
- package/dist/examples/tools/app.module.js +31 -0
- package/dist/examples/tools/app.module.js.map +1 -0
- package/dist/examples/tools/main.d.ts +1 -0
- package/dist/examples/tools/main.js +11 -0
- package/dist/examples/tools/main.js.map +1 -0
- package/dist/examples/tools/tools.resolver.d.ts +23 -0
- package/dist/examples/tools/tools.resolver.js +175 -0
- package/dist/examples/tools/tools.resolver.js.map +1 -0
- package/dist/src/controllers/sse/index.d.ts +2 -0
- package/dist/src/controllers/sse/index.js +19 -0
- package/dist/src/controllers/sse/index.js.map +1 -0
- package/dist/src/controllers/sse/sse.controller.d.ts +8 -0
- package/dist/src/controllers/sse/sse.controller.js +51 -0
- package/dist/src/controllers/sse/sse.controller.js.map +1 -0
- package/dist/src/controllers/sse/sse.service.d.ts +16 -0
- package/dist/src/controllers/sse/sse.service.js +78 -0
- package/dist/src/controllers/sse/sse.service.js.map +1 -0
- package/dist/src/controllers/streamable/index.d.ts +2 -0
- package/dist/src/controllers/streamable/index.js +19 -0
- package/dist/src/controllers/streamable/index.js.map +1 -0
- package/dist/src/controllers/streamable/streamable.controller.d.ts +9 -0
- package/dist/src/controllers/streamable/streamable.controller.js +62 -0
- package/dist/src/controllers/streamable/streamable.controller.js.map +1 -0
- package/dist/src/controllers/streamable/streamable.service.d.ts +24 -0
- package/dist/src/controllers/streamable/streamable.service.js +117 -0
- package/dist/src/controllers/streamable/streamable.service.js.map +1 -0
- package/dist/src/decorators/capabilities.constants.d.ts +4 -0
- package/dist/src/decorators/capabilities.constants.js +8 -0
- package/dist/src/decorators/capabilities.constants.js.map +1 -0
- package/dist/src/decorators/capabilities.decorators.d.ts +8 -0
- package/dist/src/decorators/capabilities.decorators.js +49 -0
- package/dist/src/decorators/capabilities.decorators.js.map +1 -0
- package/dist/src/decorators/index.d.ts +2 -0
- package/dist/src/decorators/index.js +19 -0
- package/dist/src/decorators/index.js.map +1 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.js +21 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/interfaces/capabilities.interface.d.ts +52 -0
- package/dist/src/interfaces/capabilities.interface.js +3 -0
- package/dist/src/interfaces/capabilities.interface.js.map +1 -0
- package/dist/src/interfaces/guards.interface.d.ts +4 -0
- package/dist/src/interfaces/guards.interface.js +3 -0
- package/dist/src/interfaces/guards.interface.js.map +1 -0
- package/dist/src/interfaces/index.d.ts +2 -0
- package/dist/src/interfaces/index.js +19 -0
- package/dist/src/interfaces/index.js.map +1 -0
- package/dist/src/interfaces/mcp-server-options.interface.d.ts +42 -0
- package/dist/src/interfaces/mcp-server-options.interface.js +3 -0
- package/dist/src/interfaces/mcp-server-options.interface.js.map +1 -0
- package/dist/src/mcp.module.d.ts +13 -0
- package/dist/src/mcp.module.js +176 -0
- package/dist/src/mcp.module.js.map +1 -0
- package/dist/src/registry/discovery.service.d.ts +16 -0
- package/dist/src/registry/discovery.service.js +85 -0
- package/dist/src/registry/discovery.service.js.map +1 -0
- package/dist/src/registry/index.d.ts +2 -0
- package/dist/src/registry/index.js +19 -0
- package/dist/src/registry/index.js.map +1 -0
- package/dist/src/registry/logger.service.d.ts +16 -0
- package/dist/src/registry/logger.service.js +97 -0
- package/dist/src/registry/logger.service.js.map +1 -0
- package/dist/src/registry/registry.service.d.ts +14 -0
- package/dist/src/registry/registry.service.js +165 -0
- package/dist/src/registry/registry.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/eslint.config.mjs +40 -0
- package/examples/README.md +56 -0
- package/examples/async-import/app.module.ts +22 -0
- package/examples/async-import/main.ts +15 -0
- package/examples/guards/app.module.ts +44 -0
- package/examples/guards/guards.resolver.ts +52 -0
- package/examples/guards/main.ts +11 -0
- package/examples/mixed/app.module.ts +20 -0
- package/examples/mixed/main.ts +11 -0
- package/examples/mixed/mixed.resolver.ts +56 -0
- package/examples/prompts/app.module.ts +20 -0
- package/examples/prompts/main.ts +11 -0
- package/examples/prompts/prompts.resolver.ts +184 -0
- package/examples/resources/app.module.ts +19 -0
- package/examples/resources/main.ts +11 -0
- package/examples/resources/resources.resolver.ts +123 -0
- package/examples/tools/app.module.ts +20 -0
- package/examples/tools/main.ts +11 -0
- package/examples/tools/tools.resolver.ts +205 -0
- package/nest-cli.json +8 -0
- package/package.json +106 -0
- package/scripts/npm-publish.js +301 -0
- package/src/controllers/sse/index.ts +2 -0
- package/src/controllers/sse/sse.controller.ts +19 -0
- package/src/controllers/sse/sse.service.ts +90 -0
- package/src/controllers/streamable/index.ts +2 -0
- package/src/controllers/streamable/streamable.controller.ts +24 -0
- package/src/controllers/streamable/streamable.service.ts +168 -0
- package/src/decorators/capabilities.constants.ts +7 -0
- package/src/decorators/capabilities.decorators.ts +150 -0
- package/src/decorators/index.ts +2 -0
- package/src/index.ts +11 -0
- package/src/interfaces/capabilities.interface.ts +95 -0
- package/src/interfaces/guards.interface.ts +13 -0
- package/src/interfaces/index.ts +2 -0
- package/src/interfaces/mcp-server-options.interface.ts +105 -0
- package/src/mcp.module.ts +233 -0
- package/src/mcp.service.spec.ts +28 -0
- package/src/registry/discovery.service.ts +116 -0
- package/src/registry/index.ts +2 -0
- package/src/registry/logger.service.ts +143 -0
- package/src/registry/registry.service.ts +281 -0
- package/test/base.e2e-spec.ts +74 -0
- package/test/jest-e2e.json +9 -0
- package/tsconfig.build.json +4 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.StreamableService = void 0;
|
|
16
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
17
|
+
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
18
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const crypto_1 = require("crypto");
|
|
21
|
+
const logger_service_1 = require("../../registry/logger.service");
|
|
22
|
+
const registry_service_1 = require("../../registry/registry.service");
|
|
23
|
+
let StreamableService = class StreamableService {
|
|
24
|
+
options;
|
|
25
|
+
transportOptions;
|
|
26
|
+
registry;
|
|
27
|
+
logger;
|
|
28
|
+
server;
|
|
29
|
+
transports = {};
|
|
30
|
+
constructor(options, transportOptions, registry, logger) {
|
|
31
|
+
this.options = options;
|
|
32
|
+
this.transportOptions = transportOptions;
|
|
33
|
+
this.registry = registry;
|
|
34
|
+
this.logger = logger;
|
|
35
|
+
this.server = new mcp_js_1.McpServer(this.options.serverInfo, this.options.options);
|
|
36
|
+
}
|
|
37
|
+
async onModuleInit() {
|
|
38
|
+
await this.registry.registerAll(this.server);
|
|
39
|
+
this.logger.log('MCP STREAMEABLE initialization completed');
|
|
40
|
+
}
|
|
41
|
+
async handlePostRequest(req, res) {
|
|
42
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
43
|
+
let transport;
|
|
44
|
+
const { options } = this.transportOptions?.streamable || {};
|
|
45
|
+
if (sessionId && this.transports[sessionId]) {
|
|
46
|
+
transport = this.transports[sessionId];
|
|
47
|
+
}
|
|
48
|
+
else if (!sessionId && (0, types_js_1.isInitializeRequest)(req.body)) {
|
|
49
|
+
transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
|
50
|
+
sessionIdGenerator: () => options?.sessionIdGenerator?.() || (0, crypto_1.randomUUID)(),
|
|
51
|
+
onsessioninitialized: (sessionId) => {
|
|
52
|
+
this.transports[sessionId] = transport;
|
|
53
|
+
},
|
|
54
|
+
enableJsonResponse: options?.enableJsonResponse,
|
|
55
|
+
eventStore: options?.eventStore,
|
|
56
|
+
});
|
|
57
|
+
transport.onclose = () => {
|
|
58
|
+
if (transport.sessionId) {
|
|
59
|
+
delete this.transports[transport.sessionId];
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
res.status(400).json({
|
|
65
|
+
jsonrpc: '2.0',
|
|
66
|
+
error: {
|
|
67
|
+
code: -32000,
|
|
68
|
+
message: 'Bad Request: No valid session ID provided',
|
|
69
|
+
},
|
|
70
|
+
id: null,
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await transport.handleRequest(req, res, req.body);
|
|
75
|
+
}
|
|
76
|
+
async handleGetRequest(req, res) {
|
|
77
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
78
|
+
if (!sessionId || !this.transports[sessionId]) {
|
|
79
|
+
res.status(400).send('Invalid or missing session ID');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const transport = this.transports[sessionId];
|
|
83
|
+
await transport.handleRequest(req, res);
|
|
84
|
+
}
|
|
85
|
+
async handleDeleteRequest(req, res) {
|
|
86
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
87
|
+
if (!sessionId) {
|
|
88
|
+
res.status(400).json({ error: 'Missing sessionId' });
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const transport = this.transports[sessionId];
|
|
92
|
+
if (transport) {
|
|
93
|
+
this.logger.debug(`Closing streamable transport for sessionId: ${sessionId}`, 'STREAMABLE');
|
|
94
|
+
await transport.close();
|
|
95
|
+
const uuidV4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
96
|
+
if (!uuidV4Regex.test(sessionId)) {
|
|
97
|
+
res.status(400).json({ error: 'Invalid sessionId format' });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
delete this.transports[sessionId];
|
|
101
|
+
res.status(200).json({ success: true, sessionId });
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.logger.debug(`No streamable transport found for sessionId: ${sessionId}`, 'STREAMABLE');
|
|
105
|
+
res.status(404).json({ error: 'Transport not found', sessionId });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
exports.StreamableService = StreamableService;
|
|
110
|
+
exports.StreamableService = StreamableService = __decorate([
|
|
111
|
+
(0, common_1.Injectable)(),
|
|
112
|
+
__param(0, (0, common_1.Inject)('MCP_SERVER_OPTIONS')),
|
|
113
|
+
__param(1, (0, common_1.Inject)('MCP_TRANSPORT_OPTIONS')),
|
|
114
|
+
__metadata("design:paramtypes", [Object, Object, registry_service_1.RegistryService,
|
|
115
|
+
logger_service_1.McpLoggerService])
|
|
116
|
+
], StreamableService);
|
|
117
|
+
//# sourceMappingURL=streamable.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamable.service.js","sourceRoot":"","sources":["../../../../src/controllers/streamable/streamable.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oEAAoE;AACpE,0FAAmG;AACnG,iEAAyE;AACzE,2CAAkE;AAClE,mCAAoC;AAOpC,kEAAiE;AACjE,sEAAkE;AAK3D,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAOT;IAEA;IACA;IACA;IAVX,MAAM,CAAY;IAElB,UAAU,GAAG,EAAmD,CAAC;IAEzE,YAEmB,OAAyB,EAEzB,gBAA2C,EAC3C,QAAyB,EACzB,MAAwB;QAJxB,YAAO,GAAP,OAAO,CAAkB;QAEzB,qBAAgB,GAAhB,gBAAgB,CAA2B;QAC3C,aAAQ,GAAR,QAAQ,CAAiB;QACzB,WAAM,GAAN,MAAM,CAAkB;QAEzC,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7E,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE7C,IAA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IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBACjC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,0BAA0B,EAAE,CAAC,CAAC;gBAC5D,OAAO;YACT,CAAC;YAED,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YAElC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;QACrD,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,gDAAgD,SAAS,EAAE,EAC3D,YAAY,CACb,CAAC;YACF,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,SAAS,EAAE,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;CACF,CAAA;AAtJY,8CAAiB;4BAAjB,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,oBAAoB,CAAC,CAAA;IAE5B,WAAA,IAAA,eAAM,EAAC,uBAAuB,CAAC,CAAA;qDAEL,kCAAe;QACjB,iCAAgB;GAXhC,iBAAiB,CAsJ7B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_RESOURCE = exports.MCP_PROMPT = exports.MCP_TOOL = exports.PREFIX = void 0;
|
|
4
|
+
exports.PREFIX = 'MCP';
|
|
5
|
+
exports.MCP_TOOL = `${exports.PREFIX}:tool`;
|
|
6
|
+
exports.MCP_PROMPT = `${exports.PREFIX}:prompt`;
|
|
7
|
+
exports.MCP_RESOURCE = `${exports.PREFIX}:resource`;
|
|
8
|
+
//# sourceMappingURL=capabilities.constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.constants.js","sourceRoot":"","sources":["../../../src/decorators/capabilities.constants.ts"],"names":[],"mappings":";;;AACa,QAAA,MAAM,GAAG,KAAK,CAAC;AAGf,QAAA,QAAQ,GAAG,GAAG,cAAM,OAAO,CAAC;AAC5B,QAAA,UAAU,GAAG,GAAG,cAAM,SAAS,CAAC;AAChC,QAAA,YAAY,GAAG,GAAG,cAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PromptOptions, ResourceOptions, ToolOptions } from '../interfaces/capabilities.interface';
|
|
2
|
+
export declare const MCP_RESOLVER = "__mcp_resolver__";
|
|
3
|
+
export declare const MCP_GUARDS = "__mcp_guards__";
|
|
4
|
+
export declare function Resolver(workspace?: string): ClassDecorator;
|
|
5
|
+
export declare function UseGuards(...guards: any[]): ClassDecorator & MethodDecorator;
|
|
6
|
+
export declare function Tool(options: ToolOptions): (target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
7
|
+
export declare function Prompt(options: PromptOptions): (target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
8
|
+
export declare function Resource(options: ResourceOptions): (target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_GUARDS = exports.MCP_RESOLVER = void 0;
|
|
4
|
+
exports.Resolver = Resolver;
|
|
5
|
+
exports.UseGuards = UseGuards;
|
|
6
|
+
exports.Tool = Tool;
|
|
7
|
+
exports.Prompt = Prompt;
|
|
8
|
+
exports.Resource = Resource;
|
|
9
|
+
const common_1 = require("@nestjs/common");
|
|
10
|
+
const capabilities_constants_1 = require("./capabilities.constants");
|
|
11
|
+
exports.MCP_RESOLVER = '__mcp_resolver__';
|
|
12
|
+
exports.MCP_GUARDS = '__mcp_guards__';
|
|
13
|
+
function Resolver(workspace) {
|
|
14
|
+
return function (target) {
|
|
15
|
+
(0, common_1.Injectable)()(target);
|
|
16
|
+
(0, common_1.SetMetadata)(exports.MCP_RESOLVER, workspace || true)(target);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function UseGuards(...guards) {
|
|
20
|
+
return (0, common_1.SetMetadata)(exports.MCP_GUARDS, guards);
|
|
21
|
+
}
|
|
22
|
+
function Tool(options) {
|
|
23
|
+
return function (target, propertyKey, descriptor) {
|
|
24
|
+
(0, common_1.SetMetadata)(capabilities_constants_1.MCP_TOOL, {
|
|
25
|
+
...options,
|
|
26
|
+
methodName: propertyKey,
|
|
27
|
+
})(target, propertyKey, descriptor);
|
|
28
|
+
return descriptor;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function Prompt(options) {
|
|
32
|
+
return function (target, propertyKey, descriptor) {
|
|
33
|
+
(0, common_1.SetMetadata)(capabilities_constants_1.MCP_PROMPT, {
|
|
34
|
+
...options,
|
|
35
|
+
methodName: propertyKey,
|
|
36
|
+
})(target, propertyKey, descriptor);
|
|
37
|
+
return descriptor;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function Resource(options) {
|
|
41
|
+
return function (target, propertyKey, descriptor) {
|
|
42
|
+
(0, common_1.SetMetadata)(capabilities_constants_1.MCP_RESOURCE, {
|
|
43
|
+
...options,
|
|
44
|
+
methodName: propertyKey,
|
|
45
|
+
})(target, propertyKey, descriptor);
|
|
46
|
+
return descriptor;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=capabilities.decorators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.decorators.js","sourceRoot":"","sources":["../../../src/decorators/capabilities.decorators.ts"],"names":[],"mappings":";;;AA4BA,4BAKC;AAYD,8BAEC;AAkBD,oBAaC;AAqBD,wBAaC;AAyBD,4BAYC;AArJD,2CAAyD;AAOzD,qEAA8E;AAKjE,QAAA,YAAY,GAAG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
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./capabilities.constants"), exports);
|
|
18
|
+
__exportStar(require("./capabilities.decorators"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,4DAA0C"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./mcp.module"), exports);
|
|
18
|
+
__exportStar(require("./interfaces"), exports);
|
|
19
|
+
__exportStar(require("./registry"), exports);
|
|
20
|
+
__exportStar(require("./decorators"), exports);
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,+CAA6B;AAG7B,+CAA6B;AAG7B,6CAA2B;AAG3B,+CAA6B"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { CompleteResourceTemplateCallback, ListResourcesCallback } from '@modelcontextprotocol/sdk/server/mcp';
|
|
2
|
+
import { ZodOptional, ZodRawShape, ZodType, ZodTypeDef } from 'zod';
|
|
3
|
+
export interface ResourceBaseOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ResourceUriOptions extends ResourceBaseOptions {
|
|
7
|
+
uri: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ResourceUriWithMetadataOptions extends ResourceUriOptions {
|
|
10
|
+
metadata: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
export interface ResourceTemplateOptions extends ResourceBaseOptions {
|
|
13
|
+
template: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ResourceTemplateWithMetadataOptions extends ResourceTemplateOptions {
|
|
16
|
+
metadata: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export type ResourceOptions = ResourceUriOptions | ResourceUriWithMetadataOptions | ResourceTemplateOptions | ResourceTemplateWithMetadataOptions;
|
|
19
|
+
export interface ToolNameOptions {
|
|
20
|
+
name: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ToolWithDescriptionOptions extends ToolNameOptions {
|
|
23
|
+
description: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ToolWithParamSchemaOptions extends ToolNameOptions {
|
|
26
|
+
paramSchema: ZodRawShape;
|
|
27
|
+
}
|
|
28
|
+
export interface ToolWithDescriptionAndParamSchemaOptions extends ToolWithDescriptionOptions, ToolWithParamSchemaOptions {
|
|
29
|
+
}
|
|
30
|
+
export type ToolOptions = ToolNameOptions | ToolWithDescriptionOptions | ToolWithParamSchemaOptions | ToolWithDescriptionAndParamSchemaOptions;
|
|
31
|
+
export interface PromptBaseOptions {
|
|
32
|
+
name: string;
|
|
33
|
+
}
|
|
34
|
+
export interface PromptWithDescriptionOptions extends PromptBaseOptions {
|
|
35
|
+
description: string;
|
|
36
|
+
}
|
|
37
|
+
type PromptArgsRawShape = {
|
|
38
|
+
[k: string]: ZodType<string, ZodTypeDef, string> | ZodOptional<ZodType<string, ZodTypeDef, string>>;
|
|
39
|
+
};
|
|
40
|
+
export interface PromptWithArgsSchemaOptions extends PromptBaseOptions {
|
|
41
|
+
argsSchema: PromptArgsRawShape;
|
|
42
|
+
}
|
|
43
|
+
export interface PromptWithDescriptionAndArgsSchemaOptions extends PromptWithDescriptionOptions, PromptWithArgsSchemaOptions {
|
|
44
|
+
}
|
|
45
|
+
export type PromptOptions = PromptBaseOptions | PromptWithDescriptionOptions | PromptWithArgsSchemaOptions | PromptWithDescriptionAndArgsSchemaOptions;
|
|
46
|
+
export interface TemplateCallbacks {
|
|
47
|
+
list: ListResourcesCallback | undefined;
|
|
48
|
+
complete?: {
|
|
49
|
+
[variable: string]: CompleteResourceTemplateCallback;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.interface.js","sourceRoot":"","sources":["../../../src/interfaces/capabilities.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.interface.js","sourceRoot":"","sources":["../../../src/interfaces/guards.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./guards.interface"), exports);
|
|
18
|
+
__exportStar(require("./mcp-server-options.interface"), exports);
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,iEAA+C"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { StreamableHTTPServerTransportOptions } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
2
|
+
import { ProtocolOptions } from '@modelcontextprotocol/sdk/shared/protocol';
|
|
3
|
+
import { Implementation, ServerCapabilities } from '@modelcontextprotocol/sdk/types';
|
|
4
|
+
import { Provider, Type } from '@nestjs/common';
|
|
5
|
+
export type ServerOptions = {
|
|
6
|
+
instructions?: string;
|
|
7
|
+
capabilities?: ServerCapabilities;
|
|
8
|
+
protocolOptions?: ProtocolOptions;
|
|
9
|
+
};
|
|
10
|
+
export type McpServerOptions = {
|
|
11
|
+
serverInfo: Implementation;
|
|
12
|
+
options?: ServerOptions;
|
|
13
|
+
logging?: McpLoggingOptions;
|
|
14
|
+
};
|
|
15
|
+
export interface McpLoggingOptions {
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
level?: 'debug' | 'verbose' | 'log' | 'warn' | 'error';
|
|
18
|
+
}
|
|
19
|
+
export interface McpModuleOptions {
|
|
20
|
+
imports?: Type<any>[];
|
|
21
|
+
providers?: Provider[];
|
|
22
|
+
name: string;
|
|
23
|
+
version: string;
|
|
24
|
+
instructions?: string;
|
|
25
|
+
capabilities?: ServerCapabilities;
|
|
26
|
+
protocolOptions?: ProtocolOptions;
|
|
27
|
+
logging?: McpLoggingOptions;
|
|
28
|
+
transports?: McpModuleTransportOptions;
|
|
29
|
+
}
|
|
30
|
+
export type McpModuleTransportOptions = {
|
|
31
|
+
streamable?: {
|
|
32
|
+
enabled: boolean;
|
|
33
|
+
options?: Omit<StreamableHTTPServerTransportOptions, 'onsessioninitialized' | 'sessionIdGenerator'> & {
|
|
34
|
+
sessionIdGenerator?: () => string | undefined;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
sse?: {
|
|
38
|
+
enabled: boolean;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export interface McpFeatureOptions {
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-server-options.interface.js","sourceRoot":"","sources":["../../../src/interfaces/mcp-server-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { McpFeatureOptions, McpModuleOptions } from './interfaces/mcp-server-options.interface';
|
|
3
|
+
export declare class McpModule {
|
|
4
|
+
private static getActiveTransportControllersAndProviders;
|
|
5
|
+
private static buildServerConfig;
|
|
6
|
+
static forRoot(options: McpModuleOptions): DynamicModule;
|
|
7
|
+
static forRootAsync(options: {
|
|
8
|
+
imports?: any[];
|
|
9
|
+
useFactory: (...args: unknown[]) => Promise<McpModuleOptions> | McpModuleOptions;
|
|
10
|
+
inject?: any[];
|
|
11
|
+
}): DynamicModule;
|
|
12
|
+
static forFeature(_options?: McpFeatureOptions): DynamicModule;
|
|
13
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var McpModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.McpModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const core_1 = require("@nestjs/core");
|
|
13
|
+
const sse_1 = require("./controllers/sse");
|
|
14
|
+
const streamable_1 = require("./controllers/streamable");
|
|
15
|
+
const discovery_service_1 = require("./registry/discovery.service");
|
|
16
|
+
const logger_service_1 = require("./registry/logger.service");
|
|
17
|
+
const registry_service_1 = require("./registry/registry.service");
|
|
18
|
+
let McpModule = McpModule_1 = class McpModule {
|
|
19
|
+
static getActiveTransportControllersAndProviders(transports) {
|
|
20
|
+
const controllers = new Set();
|
|
21
|
+
const providers = new Set();
|
|
22
|
+
const STREAMABLE_TRANSPORT = {
|
|
23
|
+
controller: streamable_1.StreamableController,
|
|
24
|
+
service: streamable_1.StreamableService,
|
|
25
|
+
};
|
|
26
|
+
const SSE_TRANSPORT = {
|
|
27
|
+
controller: sse_1.SseController,
|
|
28
|
+
service: sse_1.SseService,
|
|
29
|
+
};
|
|
30
|
+
const defaultTransports = {
|
|
31
|
+
streamable: { enabled: true },
|
|
32
|
+
sse: { enabled: true },
|
|
33
|
+
};
|
|
34
|
+
const config = {
|
|
35
|
+
streamable: {
|
|
36
|
+
...defaultTransports.streamable,
|
|
37
|
+
...(transports?.streamable ?? {}),
|
|
38
|
+
},
|
|
39
|
+
sse: {
|
|
40
|
+
...defaultTransports.sse,
|
|
41
|
+
...(transports?.sse ?? {}),
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
if (config.streamable.enabled) {
|
|
45
|
+
controllers.add(STREAMABLE_TRANSPORT.controller);
|
|
46
|
+
providers.add(STREAMABLE_TRANSPORT.service);
|
|
47
|
+
}
|
|
48
|
+
if (config.sse.enabled) {
|
|
49
|
+
controllers.add(SSE_TRANSPORT.controller);
|
|
50
|
+
providers.add(SSE_TRANSPORT.service);
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
controllers: Array.from(controllers),
|
|
54
|
+
providers: Array.from(providers),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
static buildServerConfig(options) {
|
|
58
|
+
const serverInfo = {
|
|
59
|
+
name: options.name,
|
|
60
|
+
version: options.version,
|
|
61
|
+
};
|
|
62
|
+
const serverOptions = {
|
|
63
|
+
instructions: options?.instructions,
|
|
64
|
+
capabilities: options?.capabilities,
|
|
65
|
+
...(options?.protocolOptions || {}),
|
|
66
|
+
};
|
|
67
|
+
const loggingOptions = {
|
|
68
|
+
enabled: options.logging?.enabled !== false,
|
|
69
|
+
level: options.logging?.level || 'verbose',
|
|
70
|
+
};
|
|
71
|
+
return { serverInfo, serverOptions, loggingOptions };
|
|
72
|
+
}
|
|
73
|
+
static forRoot(options) {
|
|
74
|
+
const imports = options.imports || [];
|
|
75
|
+
const { controllers, providers } = this.getActiveTransportControllersAndProviders(options.transports);
|
|
76
|
+
const allProviders = [...(options.providers || []), ...providers];
|
|
77
|
+
const { serverInfo, serverOptions, loggingOptions } = this.buildServerConfig(options);
|
|
78
|
+
return {
|
|
79
|
+
module: McpModule_1,
|
|
80
|
+
imports,
|
|
81
|
+
controllers,
|
|
82
|
+
providers: [
|
|
83
|
+
...allProviders,
|
|
84
|
+
{
|
|
85
|
+
provide: 'MCP_SERVER_OPTIONS',
|
|
86
|
+
useValue: {
|
|
87
|
+
serverInfo,
|
|
88
|
+
options: serverOptions,
|
|
89
|
+
logging: loggingOptions,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
provide: 'MCP_LOGGING_OPTIONS',
|
|
94
|
+
useValue: loggingOptions,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
provide: 'MCP_TRANSPORT_OPTIONS',
|
|
98
|
+
useValue: options.transports,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
global: true,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
static forRootAsync(options) {
|
|
105
|
+
const { imports = [], useFactory, inject = [] } = options;
|
|
106
|
+
const safeInject = Array.isArray(inject) ? inject : [];
|
|
107
|
+
const safeImports = Array.isArray(imports) ? imports : [];
|
|
108
|
+
const providers = [
|
|
109
|
+
{
|
|
110
|
+
provide: 'MCP_SERVER_OPTIONS',
|
|
111
|
+
useFactory: async (...args) => {
|
|
112
|
+
const mcpOptions = await useFactory(...args);
|
|
113
|
+
const { serverInfo, serverOptions, loggingOptions } = this.buildServerConfig(mcpOptions);
|
|
114
|
+
return {
|
|
115
|
+
serverInfo,
|
|
116
|
+
options: serverOptions,
|
|
117
|
+
logging: loggingOptions,
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
inject: safeInject,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
provide: 'MCP_LOGGING_OPTIONS',
|
|
124
|
+
useFactory: async (...args) => {
|
|
125
|
+
const mcpOptions = await useFactory(...args);
|
|
126
|
+
return {
|
|
127
|
+
enabled: mcpOptions.logging?.enabled !== false,
|
|
128
|
+
level: mcpOptions.logging?.level || 'verbose',
|
|
129
|
+
};
|
|
130
|
+
},
|
|
131
|
+
inject: safeInject,
|
|
132
|
+
},
|
|
133
|
+
];
|
|
134
|
+
const asyncControllersFactory = async (...args) => {
|
|
135
|
+
const mcpOptions = await useFactory(...args);
|
|
136
|
+
return this.getActiveTransportControllersAndProviders(mcpOptions.transports).controllers;
|
|
137
|
+
};
|
|
138
|
+
const asyncProvidersFactory = async (...args) => {
|
|
139
|
+
const mcpOptions = await useFactory(...args);
|
|
140
|
+
const { providers } = this.getActiveTransportControllersAndProviders(mcpOptions.transports);
|
|
141
|
+
return [...(mcpOptions.providers || []), ...providers];
|
|
142
|
+
};
|
|
143
|
+
return {
|
|
144
|
+
module: McpModule_1,
|
|
145
|
+
imports: safeImports,
|
|
146
|
+
controllers: [],
|
|
147
|
+
providers: [
|
|
148
|
+
...providers,
|
|
149
|
+
{
|
|
150
|
+
provide: '__MCP_ASYNC_CONTROLLERS__',
|
|
151
|
+
useFactory: asyncControllersFactory,
|
|
152
|
+
inject: safeInject,
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
provide: '__MCP_ASYNC_PROVIDERS__',
|
|
156
|
+
useFactory: asyncProvidersFactory,
|
|
157
|
+
inject: safeInject,
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
global: true,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
static forFeature(_options) {
|
|
164
|
+
return {
|
|
165
|
+
module: McpModule_1,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
exports.McpModule = McpModule;
|
|
170
|
+
exports.McpModule = McpModule = McpModule_1 = __decorate([
|
|
171
|
+
(0, common_1.Module)({
|
|
172
|
+
imports: [core_1.DiscoveryModule],
|
|
173
|
+
providers: [registry_service_1.RegistryService, discovery_service_1.DiscoveryService, logger_service_1.McpLoggerService],
|
|
174
|
+
})
|
|
175
|
+
], McpModule);
|
|
176
|
+
//# sourceMappingURL=mcp.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.module.js","sourceRoot":"","sources":["../../src/mcp.module.ts"],"names":[],"mappings":";;;;;;;;;;AACA,2CAAuE;AACvE,uCAA+C;AAE/C,2CAA8D;AAC9D,yDAGkC;AAQlC,oEAAgE;AAChE,8DAA6D;AAC7D,kEAA8D;AAMvD,IAAM,SAAS,iBAAf,MAAM,SAAS;IAIZ,MAAM,CAAC,yCAAyC,CACtD,UAAsC;QAEtC,MAAM,WAAW,GAAG,IAAI,GAAG,EAAa,CAAC;QACzC,MAAM,SAAS,GAAG,IAAI,GAAG,EAAY,CAAC;QAGtC,MAAM,oBAAoB,GAAG;YAC3B,UAAU,EAAE,iCAAoB;YAChC,OAAO,EAAE,8BAAiB;SAC3B,CAAC;QAEF,MAAM,aAAa,GAAG;YACpB,UAAU,EAAE,mBAAa;YACzB,OAAO,EAAE,gBAAU;SACpB,CAAC;QAGF,MAAM,iBAAiB,GAA8B;YACnD,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;YAC7B,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;SACvB,CAAC;QAGF,MAAM,MAAM,GAAG;YACb,UAAU,EAAE;gBACV,GAAG,iBAAiB,CAAC,UAAU;gBAC/B,GAAG,CAAC,UAAU,EAAE,UAAU,IAAI,EAAE,CAAC;aAClC;YACD,GAAG,EAAE;gBACH,GAAG,iBAAiB,CAAC,GAAG;gBACxB,GAAG,CAAC,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC;aAC3B;SACF,CAAC;QAGF,IAAI,MAAM,CAAC,UAAU,CAAC,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,OAAO,EAAE,2BAA2B;oBACpC,UAAU,EAAE,uBAAuB;oBACnC,MAAM,EAAE,UAAU;iBACnB;gBACD;oBACE,OAAO,EAAE,yBAAyB;oBAClC,UAAU,EAAE,qBAAqB;oBACjC,MAAM,EAAE,UAAU;iBACnB;aACF;YACD,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;IAWD,MAAM,CAAC,UAAU,CAAC,QAA4B;QAC5C,OAAO;YACL,MAAM,EAAE,WAAS;SAClB,CAAC;IACJ,CAAC;CACF,CAAA;AAhNY,8BAAS;oBAAT,SAAS;IAJrB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,sBAAe,CAAC;QAC1B,SAAS,EAAE,CAAC,kCAAe,EAAE,oCAAgB,EAAE,iCAAgB,CAAC;KACjE,CAAC;GACW,SAAS,CAgNrB"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { MetadataScanner, DiscoveryService as NestDiscoveryService, Reflector } from '@nestjs/core';
|
|
2
|
+
import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper';
|
|
3
|
+
export interface MethodWithMetadata<T = unknown> {
|
|
4
|
+
method: string;
|
|
5
|
+
metadata: T;
|
|
6
|
+
handler: (...args: any[]) => any;
|
|
7
|
+
instance: object;
|
|
8
|
+
}
|
|
9
|
+
export declare class DiscoveryService {
|
|
10
|
+
private readonly discoveryService;
|
|
11
|
+
private readonly metadataScanner;
|
|
12
|
+
private readonly reflector;
|
|
13
|
+
constructor(discoveryService: NestDiscoveryService, metadataScanner: MetadataScanner, reflector: Reflector);
|
|
14
|
+
getAllMethodsWithMetadata<T = unknown>(metadataKey: string): MethodWithMetadata<T>[];
|
|
15
|
+
getMethodsWithMetadataFromProvider<T = unknown>(provider: InstanceWrapper, metadataKey: string): MethodWithMetadata<T>[];
|
|
16
|
+
}
|