@rekog/mcp-nest 1.0.17 → 1.0.19

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.
Files changed (37) hide show
  1. package/dist/controllers/sse.controller.factory.d.ts +12 -0
  2. package/dist/controllers/sse.controller.factory.d.ts.map +1 -0
  3. package/dist/controllers/sse.controller.factory.js +59 -0
  4. package/dist/controllers/sse.controller.factory.js.map +1 -0
  5. package/dist/decorators/constants.d.ts +2 -0
  6. package/dist/decorators/constants.d.ts.map +1 -0
  7. package/dist/decorators/constants.js +5 -0
  8. package/dist/decorators/constants.js.map +1 -0
  9. package/dist/decorators/index.d.ts +3 -0
  10. package/dist/decorators/index.d.ts.map +1 -0
  11. package/dist/decorators/index.js +19 -0
  12. package/dist/decorators/index.js.map +1 -0
  13. package/dist/decorators/tool.decorator.d.ts +7 -0
  14. package/dist/decorators/tool.decorator.d.ts.map +1 -0
  15. package/dist/decorators/tool.decorator.js +10 -0
  16. package/dist/decorators/tool.decorator.js.map +1 -0
  17. package/dist/index.d.ts +4 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +20 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/interfaces/index.d.ts +2 -0
  22. package/dist/interfaces/index.d.ts.map +1 -0
  23. package/dist/interfaces/index.js +18 -0
  24. package/dist/interfaces/index.js.map +1 -0
  25. package/dist/interfaces/mcp-options.interface.d.ts +19 -0
  26. package/dist/interfaces/mcp-options.interface.d.ts.map +1 -0
  27. package/dist/interfaces/mcp-options.interface.js +3 -0
  28. package/dist/interfaces/mcp-options.interface.js.map +1 -0
  29. package/dist/mcp.module.d.ts +9 -0
  30. package/dist/mcp.module.d.ts.map +1 -0
  31. package/dist/mcp.module.js +105 -0
  32. package/dist/mcp.module.js.map +1 -0
  33. package/dist/mcp.module.spec.d.ts +13 -0
  34. package/dist/mcp.module.spec.d.ts.map +1 -0
  35. package/dist/mcp.module.spec.js +87 -0
  36. package/dist/mcp.module.spec.js.map +1 -0
  37. package/package.json +1 -1
@@ -0,0 +1,12 @@
1
+ import type { Request, Response } from 'express';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
4
+ export declare function createSseController(sseEndpoint: string, messagesEndpoint: string, globalApiPrefix: string): {
5
+ new (mcpServer: McpServer): {
6
+ transport: SSEServerTransport | null;
7
+ readonly mcpServer: McpServer;
8
+ sse(res: Response): Promise<void>;
9
+ messages(req: Request, res: Response, body: unknown): Promise<Response<any, Record<string, any>> | undefined>;
10
+ };
11
+ };
12
+ //# sourceMappingURL=sse.controller.factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.controller.factory.d.ts","sourceRoot":"","sources":["../../src/controllers/sse.controller.factory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEjD,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAE7E,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,EACxB,eAAe,EAAE,MAAM;oBAMwC,SAAS;mBAFpD,kBAAkB,GAAG,IAAI;4BAEkB,SAAS;iBAGhD,QAAQ;sBAMH,OAAO,OAAc,QAAQ,QAAgB,OAAO;;EASlF"}
@@ -0,0 +1,59 @@
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.createSseController = createSseController;
16
+ const common_1 = require("@nestjs/common");
17
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
18
+ const sse_js_1 = require("@modelcontextprotocol/sdk/server/sse.js");
19
+ function createSseController(sseEndpoint, messagesEndpoint, globalApiPrefix) {
20
+ let SseController = class SseController {
21
+ constructor(mcpServer) {
22
+ this.mcpServer = mcpServer;
23
+ this.transport = null;
24
+ }
25
+ async sse(res) {
26
+ this.transport = new sse_js_1.SSEServerTransport(`${globalApiPrefix}/${messagesEndpoint}`, res);
27
+ await this.mcpServer.connect(this.transport);
28
+ }
29
+ async messages(req, res, body) {
30
+ if (!this.transport) {
31
+ return res.status(500).send('No active SSE connection');
32
+ }
33
+ await this.transport.handlePostMessage(req, res, body);
34
+ }
35
+ };
36
+ __decorate([
37
+ (0, common_1.Get)(sseEndpoint),
38
+ __param(0, (0, common_1.Res)()),
39
+ __metadata("design:type", Function),
40
+ __metadata("design:paramtypes", [Object]),
41
+ __metadata("design:returntype", Promise)
42
+ ], SseController.prototype, "sse", null);
43
+ __decorate([
44
+ (0, common_1.Post)(messagesEndpoint),
45
+ __param(0, (0, common_1.Req)()),
46
+ __param(1, (0, common_1.Res)()),
47
+ __param(2, (0, common_1.Body)()),
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", [Object, Object, Object]),
50
+ __metadata("design:returntype", Promise)
51
+ ], SseController.prototype, "messages", null);
52
+ SseController = __decorate([
53
+ (0, common_1.Controller)(),
54
+ __param(0, (0, common_1.Inject)('MCP_SERVER')),
55
+ __metadata("design:paramtypes", [mcp_js_1.McpServer])
56
+ ], SseController);
57
+ return SseController;
58
+ }
59
+ //# sourceMappingURL=sse.controller.factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sse.controller.factory.js","sourceRoot":"","sources":["../../src/controllers/sse.controller.factory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAMA,kDA2BC;AAjCD,2CAA+E;AAG/E,oEAAoE;AACpE,oEAA6E;AAE7E,SAAgB,mBAAmB,CACjC,WAAmB,EACnB,gBAAwB,EACxB,eAAuB;IAEvB,IACM,aAAa,GADnB,MACM,aAAa;QAGjB,YAAkC,SAAoC;YAApB,cAAS,GAAT,SAAS,CAAW;YAF/D,cAAS,GAA8B,IAAI,CAAC;QAEsB,CAAC;QAGpE,AAAN,KAAK,CAAC,GAAG,CAAQ,GAAa;YAC5B,IAAI,CAAC,SAAS,GAAG,IAAI,2BAAkB,CAAC,GAAG,eAAe,IAAI,gBAAgB,EAAE,EAAE,GAAG,CAAC,CAAC;YACvF,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC/C,CAAC;QAGK,AAAN,KAAK,CAAC,QAAQ,CAAQ,GAAY,EAAS,GAAa,EAAU,IAAa;YAC7E,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;gBACpB,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC;YAC1D,CAAC;YACD,MAAM,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACzD,CAAC;KACF,CAAA;IAZO;QADL,IAAA,YAAG,EAAC,WAAW,CAAC;QACN,WAAA,IAAA,YAAG,GAAE,CAAA;;;;4CAGf;IAGK;QADL,IAAA,aAAI,EAAC,gBAAgB,CAAC;QACP,WAAA,IAAA,YAAG,GAAE,CAAA;QAAgB,WAAA,IAAA,YAAG,GAAE,CAAA;QAAiB,WAAA,IAAA,aAAI,GAAE,CAAA;;;;iDAKhE;IAjBG,aAAa;QADlB,IAAA,mBAAU,GAAE;QAIE,WAAA,IAAA,eAAM,EAAC,YAAY,CAAC,CAAA;yCAA4B,kBAAS;OAHlE,aAAa,CAkBlB;IAED,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const MCP_TOOL_METADATA_KEY = "mcp:tool";
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/decorators/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCP_TOOL_METADATA_KEY = void 0;
4
+ exports.MCP_TOOL_METADATA_KEY = 'mcp:tool';
5
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/decorators/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,UAAU,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './tool.decorator';
2
+ export * from './constants';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC"}
@@ -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("./tool.decorator"), exports);
18
+ __exportStar(require("./constants"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAiC;AACjC,8CAA4B"}
@@ -0,0 +1,7 @@
1
+ export interface ToolMetadata {
2
+ name: string;
3
+ description: string;
4
+ schema?: any;
5
+ }
6
+ export declare const Tool: (name: string, description: string, schema?: any) => MethodDecorator;
7
+ //# sourceMappingURL=tool.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,eAAO,MAAM,IAAI,SAAU,MAAM,eAAe,MAAM,WAAW,GAAG,KAAG,eAEtE,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tool = void 0;
4
+ const common_1 = require("@nestjs/common");
5
+ const constants_1 = require("./constants");
6
+ const Tool = (name, description, schema) => {
7
+ return (0, common_1.SetMetadata)(constants_1.MCP_TOOL_METADATA_KEY, { name, description, schema });
8
+ };
9
+ exports.Tool = Tool;
10
+ //# sourceMappingURL=tool.decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.decorator.js","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,2CAAoD;AAQ7C,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,WAAmB,EAAE,MAAY,EAAmB,EAAE;IACvF,OAAO,IAAA,oBAAW,EAAC,iCAAqB,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3E,CAAC,CAAC;AAFW,QAAA,IAAI,QAEf"}
@@ -0,0 +1,4 @@
1
+ export * from './decorators';
2
+ export * from './interfaces';
3
+ export * from './mcp.module';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
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("./decorators"), exports);
18
+ __exportStar(require("./interfaces"), exports);
19
+ __exportStar(require("./mcp.module"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B;AAC7B,+CAA6B;AAC7B,+CAA6B"}
@@ -0,0 +1,2 @@
1
+ export * from './mcp-options.interface';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC"}
@@ -0,0 +1,18 @@
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-options.interface"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0DAAwC"}
@@ -0,0 +1,19 @@
1
+ import { ModuleMetadata, Type } from '@nestjs/common';
2
+ export interface McpOptions {
3
+ name: string;
4
+ version: string;
5
+ sseEndpoint?: string;
6
+ messagesEndpoint?: string;
7
+ globalApiPrefix?: string;
8
+ capabilities?: Record<string, any>;
9
+ }
10
+ export interface McpOptionsFactory {
11
+ createMcpOptions(): Promise<McpOptions> | McpOptions;
12
+ }
13
+ export interface McpAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
14
+ useExisting?: Type<McpOptionsFactory>;
15
+ useClass?: Type<McpOptionsFactory>;
16
+ useFactory?: (...args: any[]) => Promise<McpOptions> | McpOptions;
17
+ inject?: any[];
18
+ }
19
+ //# sourceMappingURL=mcp-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-options.interface.d.ts","sourceRoot":"","sources":["../../src/interfaces/mcp-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,gBAAgB,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;CACtD;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC;IACtE,WAAW,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACtC,QAAQ,CAAC,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACnC,UAAU,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAClE,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;CAChB"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=mcp-options.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/mcp-options.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import { DynamicModule } from '@nestjs/common';
2
+ import { McpOptions, McpAsyncOptions } from './interfaces/mcp-options.interface';
3
+ export declare class McpModule {
4
+ static forRoot(options: McpOptions): DynamicModule;
5
+ static forRootAsync(options: McpAsyncOptions): DynamicModule;
6
+ private static createAsyncProviders;
7
+ private static createAsyncOptionsProvider;
8
+ }
9
+ //# sourceMappingURL=mcp.module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.module.d.ts","sourceRoot":"","sources":["../src/mcp.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoB,MAAM,gBAAgB,CAAC;AAGjE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAqB,MAAM,oCAAoC,CAAC;AAKpG,qBACa,SAAS;IACpB,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,GAAG,aAAa;IAkClD,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,GAAG,aAAa;IA2B5D,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAkBnC,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAsB1C"}
@@ -0,0 +1,105 @@
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 mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
14
+ const mcp_tools_discovery_1 = require("./services/mcp-tools.discovery");
15
+ const sse_controller_factory_1 = require("./controllers/sse.controller.factory");
16
+ let McpModule = McpModule_1 = class McpModule {
17
+ static forRoot(options) {
18
+ const sseEndpoint = options.sseEndpoint ?? 'sse';
19
+ const messagesEndpoint = options.messagesEndpoint ?? 'messages';
20
+ const globalApiPrefix = options.globalApiPrefix ?? '';
21
+ const SseController = (0, sse_controller_factory_1.createSseController)(sseEndpoint, messagesEndpoint, globalApiPrefix);
22
+ return {
23
+ module: McpModule_1,
24
+ imports: [core_1.DiscoveryModule],
25
+ controllers: [SseController],
26
+ providers: [
27
+ {
28
+ provide: 'MCP_OPTIONS',
29
+ useValue: options,
30
+ },
31
+ {
32
+ provide: 'MCP_SERVER',
33
+ useFactory: (mcpOptions, toolsDiscovery) => {
34
+ const server = new mcp_js_1.McpServer({ name: mcpOptions.name, version: mcpOptions.version }, { capabilities: mcpOptions.capabilities || { tools: {} } });
35
+ toolsDiscovery.registerTools(server);
36
+ return server;
37
+ },
38
+ inject: ['MCP_OPTIONS', mcp_tools_discovery_1.McpToolsDiscovery],
39
+ },
40
+ mcp_tools_discovery_1.McpToolsDiscovery,
41
+ ],
42
+ exports: ['MCP_SERVER'],
43
+ };
44
+ }
45
+ static forRootAsync(options) {
46
+ const providers = this.createAsyncProviders(options);
47
+ return {
48
+ module: McpModule_1,
49
+ imports: [...(options.imports || []), core_1.DiscoveryModule],
50
+ controllers: [],
51
+ providers: [
52
+ ...providers,
53
+ mcp_tools_discovery_1.McpToolsDiscovery,
54
+ {
55
+ provide: 'MCP_SERVER',
56
+ useFactory: (mcpOptions, toolsDiscovery) => {
57
+ const server = new mcp_js_1.McpServer({ name: mcpOptions.name, version: mcpOptions.version }, { capabilities: mcpOptions.capabilities || { tools: {} } });
58
+ toolsDiscovery.registerTools(server);
59
+ return server;
60
+ },
61
+ inject: ['MCP_OPTIONS', mcp_tools_discovery_1.McpToolsDiscovery],
62
+ },
63
+ ],
64
+ exports: ['MCP_SERVER'],
65
+ };
66
+ }
67
+ static createAsyncProviders(options) {
68
+ if (options.useExisting || options.useFactory) {
69
+ return [this.createAsyncOptionsProvider(options)];
70
+ }
71
+ if (!options.useClass) {
72
+ throw new Error('useClass must be defined when not using useExisting or useFactory');
73
+ }
74
+ return [
75
+ this.createAsyncOptionsProvider(options),
76
+ {
77
+ provide: options.useClass,
78
+ useClass: options.useClass,
79
+ },
80
+ ];
81
+ }
82
+ static createAsyncOptionsProvider(options) {
83
+ if (options.useFactory) {
84
+ return {
85
+ provide: 'MCP_OPTIONS',
86
+ useFactory: options.useFactory,
87
+ inject: options.inject || [],
88
+ };
89
+ }
90
+ const injectionToken = options.useExisting || options.useClass;
91
+ if (!injectionToken) {
92
+ throw new Error('Either useExisting or useClass must be defined when not using useFactory');
93
+ }
94
+ return {
95
+ provide: 'MCP_OPTIONS',
96
+ useFactory: async (optionsFactory) => await optionsFactory.createMcpOptions(),
97
+ inject: [injectionToken],
98
+ };
99
+ }
100
+ };
101
+ exports.McpModule = McpModule;
102
+ exports.McpModule = McpModule = McpModule_1 = __decorate([
103
+ (0, common_1.Module)({})
104
+ ], McpModule);
105
+ //# sourceMappingURL=mcp.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.module.js","sourceRoot":"","sources":["../src/mcp.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,uCAA+C;AAC/C,oEAAoE;AAEpE,wEAAmE;AAEnE,iFAA2E;AAGpE,IAAM,SAAS,iBAAf,MAAM,SAAS;IACpB,MAAM,CAAC,OAAO,CAAC,OAAmB;QAChC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,KAAK,CAAC;QACjD,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,IAAI,UAAU,CAAC;QAChE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;QAEtD,MAAM,aAAa,GAAG,IAAA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,CAAC;QAC9F,CAAC;QAED,OAAO;YACL,OAAO,EAAE,aAAa;YACtB,UAAU,EAAE,KAAK,EAAE,cAAiC,EAAE,EAAE,CACtD,MAAM,cAAc,CAAC,gBAAgB,EAAE;YACzC,MAAM,EAAE,CAAC,cAAc,CAAC;SACzB,CAAC;IACJ,CAAC;CAEF,CAAA;AAtGY,8BAAS;oBAAT,SAAS;IADrB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,SAAS,CAsGrB"}
@@ -0,0 +1,13 @@
1
+ import 'reflect-metadata';
2
+ export declare class GreetingTool {
3
+ constructor();
4
+ sayHello({ name }: {
5
+ name: any;
6
+ }): {
7
+ content: {
8
+ type: string;
9
+ text: string;
10
+ }[];
11
+ };
12
+ }
13
+ //# sourceMappingURL=mcp.module.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.module.spec.d.ts","sourceRoot":"","sources":["../src/mcp.module.spec.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAY1B,qBACa,YAAY;;IAMvB,QAAQ,CAAC,EAAE,IAAI,EAAE;;KAAA;;;;;;CAYlB"}
@@ -0,0 +1,87 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GreetingTool = void 0;
13
+ require("reflect-metadata");
14
+ const testing_1 = require("@nestjs/testing");
15
+ const mcp_module_1 = require("./mcp.module");
16
+ const common_1 = require("@nestjs/common");
17
+ const zod_1 = require("zod");
18
+ const decorators_1 = require("./decorators");
19
+ let GreetingTool = class GreetingTool {
20
+ constructor() { }
21
+ sayHello({ name }) {
22
+ const greeting = `Hello, ${name}!`;
23
+ return {
24
+ content: [
25
+ {
26
+ type: 'text',
27
+ text: greeting,
28
+ },
29
+ ],
30
+ };
31
+ }
32
+ };
33
+ exports.GreetingTool = GreetingTool;
34
+ __decorate([
35
+ (0, decorators_1.Tool)('hello-world', 'A sample tool that returns a greeting', {
36
+ name: zod_1.z.string().default('World'),
37
+ }),
38
+ __metadata("design:type", Function),
39
+ __metadata("design:paramtypes", [Object]),
40
+ __metadata("design:returntype", void 0)
41
+ ], GreetingTool.prototype, "sayHello", null);
42
+ exports.GreetingTool = GreetingTool = __decorate([
43
+ (0, common_1.Injectable)(),
44
+ __metadata("design:paramtypes", [])
45
+ ], GreetingTool);
46
+ describe('McpModule', () => {
47
+ let app;
48
+ let mcpServer;
49
+ const testOptions = {
50
+ name: 'test-mcp-server',
51
+ version: '0.0.1',
52
+ capabilities: {
53
+ tools: {
54
+ 'hello-world': {
55
+ description: 'A sample tool that returns a greeting',
56
+ input: {
57
+ name: {
58
+ type: 'string',
59
+ default: 'World',
60
+ },
61
+ },
62
+ },
63
+ },
64
+ },
65
+ };
66
+ beforeAll(async () => {
67
+ const moduleFixture = await testing_1.Test.createTestingModule({
68
+ imports: [mcp_module_1.McpModule.forRoot(testOptions)],
69
+ providers: [GreetingTool],
70
+ }).compile();
71
+ app = moduleFixture.createNestApplication();
72
+ await app.init();
73
+ mcpServer = moduleFixture.get('MCP_SERVER');
74
+ });
75
+ afterAll(async () => {
76
+ await app.close();
77
+ });
78
+ it('should compile and inject MCP_SERVER', async () => {
79
+ expect(mcpServer).toBeDefined();
80
+ });
81
+ it('should discover and register the GreetingTool on the McpServer', async () => {
82
+ const tools = await mcpServer._registeredTools;
83
+ expect(tools).toBeDefined();
84
+ expect(tools).toHaveProperty('hello-world');
85
+ });
86
+ });
87
+ //# sourceMappingURL=mcp.module.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.module.spec.js","sourceRoot":"","sources":["../src/mcp.module.spec.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4BAA0B;AAC1B,6CAAsD;AAKtD,6CAAyC;AAEzC,2CAA4C;AAC5C,6BAAwB;AACxB,6CAAoC;AAG7B,IAAM,YAAY,GAAlB,MAAM,YAAY;IACvB,gBAAe,CAAC;IAKhB,QAAQ,CAAC,EAAE,IAAI,EAAE;QACf,MAAM,QAAQ,GAAG,UAAU,IAAI,GAAG,CAAC;QAEnC,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,QAAQ;iBACf;aACF;SACF,CAAC;IACJ,CAAC;CACF,CAAA;AAlBY,oCAAY;AAMvB;IAHC,IAAA,iBAAI,EAAC,aAAa,EAAE,uCAAuC,EAAE;QAC5D,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;KAClC,CAAC;;;;4CAYD;uBAjBU,YAAY;IADxB,IAAA,mBAAU,GAAE;;GACA,YAAY,CAkBxB;AAGD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,GAAqB,CAAC;IAC1B,IAAI,SAAoB,CAAC;IAEzB,MAAM,WAAW,GAAe;QAC9B,IAAI,EAAE,iBAAiB;QACvB,OAAO,EAAE,OAAO;QAChB,YAAY,EAAE;YACZ,KAAK,EAAE;gBACL,aAAa,EAAE;oBACb,WAAW,EAAE,uCAAuC;oBACpD,KAAK,EAAE;wBACL,IAAI,EAAE;4BACJ,IAAI,EAAE,QAAQ;4BACd,OAAO,EAAE,OAAO;yBACjB;qBACF;iBACF;aACF;SACF;KACF,CAAC;IAEF,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,aAAa,GAAkB,MAAM,cAAI,CAAC,mBAAmB,CAAC;YAClE,OAAO,EAAE,CAAC,sBAAS,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YACzC,SAAS,EAAE,CAAC,YAAY,CAAC;SAC1B,CAAC,CAAC,OAAO,EAAE,CAAC;QAEb,GAAG,GAAG,aAAa,CAAC,qBAAqB,EAAE,CAAC;QAC5C,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAEjB,SAAS,GAAG,aAAa,CAAC,GAAG,CAAY,YAAY,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,KAAK,IAAI,EAAE;QAClB,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE,KAAK,IAAI,EAAE;QACpD,MAAM,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gEAAgE,EAAE,KAAK,IAAI,EAAE;QAC9E,MAAM,KAAK,GAAG,MAAO,SAAiB,CAAC,gBAAgB,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;QAC5B,MAAM,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rekog/mcp-nest",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "NestJS module for creating Model Context Protocol (MCP) servers and exposing tools using SSE",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",