@iludolf/mcp-adapter 1.0.0
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 +168 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +9 -0
- package/dist/constants.js.map +1 -0
- package/dist/decorators/base.decorator.d.ts +1 -0
- package/dist/decorators/base.decorator.js +15 -0
- package/dist/decorators/base.decorator.js.map +1 -0
- package/dist/decorators/constants.d.ts +3 -0
- package/dist/decorators/constants.js +7 -0
- package/dist/decorators/constants.js.map +1 -0
- package/dist/decorators/index.d.ts +5 -0
- package/dist/decorators/index.js +22 -0
- package/dist/decorators/index.js.map +1 -0
- package/dist/decorators/mcp-prompt.decorator.d.ts +2 -0
- package/dist/decorators/mcp-prompt.decorator.js +8 -0
- package/dist/decorators/mcp-prompt.decorator.js.map +1 -0
- package/dist/decorators/mcp-resource.decorator.d.ts +2 -0
- package/dist/decorators/mcp-resource.decorator.js +8 -0
- package/dist/decorators/mcp-resource.decorator.js.map +1 -0
- package/dist/decorators/mcp-tool.decorator.d.ts +2 -0
- package/dist/decorators/mcp-tool.decorator.js +8 -0
- package/dist/decorators/mcp-tool.decorator.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +2 -0
- package/dist/interfaces/index.js +19 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/interfaces/mcp-logger.interface.d.ts +12 -0
- package/dist/interfaces/mcp-logger.interface.js +22 -0
- package/dist/interfaces/mcp-logger.interface.js.map +1 -0
- package/dist/interfaces/mcp-module-options.interface.d.ts +49 -0
- package/dist/interfaces/mcp-module-options.interface.js +11 -0
- package/dist/interfaces/mcp-module-options.interface.js.map +1 -0
- package/dist/mcp.controller.d.ts +13 -0
- package/dist/mcp.controller.js +85 -0
- package/dist/mcp.controller.js.map +1 -0
- package/dist/mcp.module.d.ts +16 -0
- package/dist/mcp.module.js +168 -0
- package/dist/mcp.module.js.map +1 -0
- package/dist/services/explorer.service.d.ts +22 -0
- package/dist/services/explorer.service.js +71 -0
- package/dist/services/explorer.service.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +20 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/mcp-http.service.d.ts +12 -0
- package/dist/services/mcp-http.service.js +93 -0
- package/dist/services/mcp-http.service.js.map +1 -0
- package/dist/services/mcp.service.d.ts +21 -0
- package/dist/services/mcp.service.js +134 -0
- package/dist/services/mcp.service.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# @iludolf/mcp-adapter
|
|
2
|
+
|
|
3
|
+
NestJS module for Model Context Protocol (MCP) integration. Enables your NestJS application to act as an MCP server, exposing tools, resources, and prompts to AI assistants.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @iludolf/mcp-adapter
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @iludolf/mcp-adapter
|
|
11
|
+
# or
|
|
12
|
+
yarn add @iludolf/mcp-adapter
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Peer Dependencies
|
|
16
|
+
|
|
17
|
+
Make sure you have these peer dependencies installed:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @modelcontextprotocol/sdk @nestjs/common @nestjs/core reflect-metadata rxjs zod
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
### 1. Import the module
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { Module } from "@nestjs/common"
|
|
29
|
+
import { McpModule, TransportType } from "@iludolf/mcp-adapter"
|
|
30
|
+
|
|
31
|
+
@Module({
|
|
32
|
+
imports: [
|
|
33
|
+
McpModule.forRoot({
|
|
34
|
+
serverInfo: {
|
|
35
|
+
name: "my-mcp-server",
|
|
36
|
+
version: "1.0.0",
|
|
37
|
+
},
|
|
38
|
+
transport: TransportType.SSE, // or TransportType.STDIO
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
})
|
|
42
|
+
export class AppModule {}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 2. Create MCP handlers
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Injectable } from "@nestjs/common"
|
|
49
|
+
import { McpTool, McpResource, McpPrompt } from "@iludolf/mcp-adapter"
|
|
50
|
+
import { z } from "zod"
|
|
51
|
+
|
|
52
|
+
@Injectable()
|
|
53
|
+
export class MyMcpHandlers {
|
|
54
|
+
@McpTool({
|
|
55
|
+
name: "calculator",
|
|
56
|
+
description: "Performs basic arithmetic",
|
|
57
|
+
paramsSchema: {
|
|
58
|
+
operation: z.enum(["add", "subtract"]),
|
|
59
|
+
a: z.number(),
|
|
60
|
+
b: z.number(),
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
async calculate(args: { operation: string; a: number; b: number }) {
|
|
64
|
+
const result = args.operation === "add"
|
|
65
|
+
? args.a + args.b
|
|
66
|
+
: args.a - args.b
|
|
67
|
+
return { content: [{ type: "text", text: String(result) }] }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@McpResource({
|
|
71
|
+
name: "config",
|
|
72
|
+
uri: "config://app",
|
|
73
|
+
description: "Application configuration",
|
|
74
|
+
})
|
|
75
|
+
async getConfig() {
|
|
76
|
+
return {
|
|
77
|
+
contents: [{
|
|
78
|
+
uri: "config://app",
|
|
79
|
+
mimeType: "application/json",
|
|
80
|
+
text: JSON.stringify({ version: "1.0.0" }),
|
|
81
|
+
}],
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@McpPrompt({
|
|
86
|
+
name: "greeting",
|
|
87
|
+
description: "Generate a greeting",
|
|
88
|
+
arguments: [{ name: "name", required: true }],
|
|
89
|
+
})
|
|
90
|
+
async generateGreeting(params: { arguments: { name: string } }) {
|
|
91
|
+
return {
|
|
92
|
+
messages: [{
|
|
93
|
+
role: "assistant",
|
|
94
|
+
content: { type: "text", text: `Hello, ${params.arguments.name}!` },
|
|
95
|
+
}],
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 3. Register the handlers provider
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
@Module({
|
|
105
|
+
imports: [McpModule.forRoot({ /* ... */ })],
|
|
106
|
+
providers: [MyMcpHandlers],
|
|
107
|
+
})
|
|
108
|
+
export class AppModule {}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Configuration Options
|
|
112
|
+
|
|
113
|
+
### McpModuleOptions
|
|
114
|
+
|
|
115
|
+
| Option | Type | Default | Description |
|
|
116
|
+
|--------|------|---------|-------------|
|
|
117
|
+
| `serverInfo` | `Implementation` | required | Server name and version |
|
|
118
|
+
| `serverOptions` | `ServerOptions` | - | MCP SDK server options |
|
|
119
|
+
| `transport` | `TransportType` | `STDIO` | Transport type (STDIO, SSE, HTTP, NONE) |
|
|
120
|
+
| `logger` | `McpLogger` | `DefaultMcpLogger` | Custom logger |
|
|
121
|
+
| `basePath` | `string` | `"mcp"` | Base path for HTTP endpoints |
|
|
122
|
+
| `global` | `boolean` | `false` | Register module globally |
|
|
123
|
+
|
|
124
|
+
### Async Configuration
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
McpModule.forRootAsync({
|
|
128
|
+
imports: [ConfigModule],
|
|
129
|
+
useFactory: (config: ConfigService) => ({
|
|
130
|
+
serverInfo: {
|
|
131
|
+
name: config.get("MCP_NAME"),
|
|
132
|
+
version: config.get("MCP_VERSION"),
|
|
133
|
+
},
|
|
134
|
+
transport: TransportType.SSE,
|
|
135
|
+
}),
|
|
136
|
+
inject: [ConfigService],
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## HTTP Endpoints (SSE/HTTP transport)
|
|
141
|
+
|
|
142
|
+
When using SSE or HTTP transport, the following endpoints are available:
|
|
143
|
+
|
|
144
|
+
- `GET /{basePath}/sse` - SSE connection endpoint
|
|
145
|
+
- `POST /{basePath}/messages` - Message handling endpoint
|
|
146
|
+
- `GET /{basePath}/health` - Health check endpoint
|
|
147
|
+
|
|
148
|
+
## Custom Logger
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import { McpLogger } from "@iludolf/mcp-adapter"
|
|
152
|
+
|
|
153
|
+
class MyLogger implements McpLogger {
|
|
154
|
+
info(message: string, context?: string) { /* ... */ }
|
|
155
|
+
warn(message: string, context?: string) { /* ... */ }
|
|
156
|
+
error(message: string, context?: string, trace?: string) { /* ... */ }
|
|
157
|
+
debug(message: string, context?: string) { /* ... */ }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
McpModule.forRoot({
|
|
161
|
+
serverInfo: { name: "my-server", version: "1.0.0" },
|
|
162
|
+
logger: new MyLogger(),
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
MIT
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const MCP_MODULE_OPTIONS = "MCP_MODULE_OPTIONS";
|
|
2
|
+
export declare const MCP_LOGGER = "MCP_LOGGER";
|
|
3
|
+
export declare const MCP_SERVER_INSTANCE = "MCP_SERVER_INSTANCE";
|
|
4
|
+
export declare const DEFAULT_MCP_PATH = "mcp";
|
|
5
|
+
export declare const MCP_LOGGER_CONTEXT = "Mcp-server";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_LOGGER_CONTEXT = exports.DEFAULT_MCP_PATH = exports.MCP_SERVER_INSTANCE = exports.MCP_LOGGER = exports.MCP_MODULE_OPTIONS = void 0;
|
|
4
|
+
exports.MCP_MODULE_OPTIONS = "MCP_MODULE_OPTIONS";
|
|
5
|
+
exports.MCP_LOGGER = "MCP_LOGGER";
|
|
6
|
+
exports.MCP_SERVER_INSTANCE = "MCP_SERVER_INSTANCE";
|
|
7
|
+
exports.DEFAULT_MCP_PATH = "mcp";
|
|
8
|
+
exports.MCP_LOGGER_CONTEXT = "Mcp-server";
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAGa,QAAA,kBAAkB,GAAG,oBAAoB,CAAA;AAKzC,QAAA,UAAU,GAAG,YAAY,CAAA;AAKzB,QAAA,mBAAmB,GAAG,qBAAqB,CAAA;AAK3C,QAAA,gBAAgB,GAAG,KAAK,CAAA;AAKxB,QAAA,kBAAkB,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createMcpDecorator: <T = any>(metadataKey: string, options?: T) => MethodDecorator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMcpDecorator = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const createMcpDecorator = (metadataKey, options) => {
|
|
6
|
+
return (target, key, descriptor) => {
|
|
7
|
+
const metadata = {
|
|
8
|
+
methodName: key,
|
|
9
|
+
options,
|
|
10
|
+
};
|
|
11
|
+
(0, common_1.SetMetadata)(metadataKey, metadata)(target, key, descriptor);
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.createMcpDecorator = createMcpDecorator;
|
|
15
|
+
//# sourceMappingURL=base.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.decorator.js","sourceRoot":"","sources":["../../src/decorators/base.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA4C;AAWrC,MAAM,kBAAkB,GAAG,CAChC,WAAmB,EACnB,OAAW,EACM,EAAE;IACnB,OAAO,CACL,MAAc,EACd,GAAoB,EACpB,UAA8B,EAC9B,EAAE;QACF,MAAM,QAAQ,GAAkB;YAC9B,UAAU,EAAE,GAAa;YACzB,OAAO;SACR,CAAA;QACD,IAAA,oBAAW,EAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAA;IAC7D,CAAC,CAAA;AACH,CAAC,CAAA;AAfY,QAAA,kBAAkB,sBAe9B"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MCP_PROMPT_METADATA = exports.MCP_TOOL_METADATA = exports.MCP_RESOURCE_METADATA = void 0;
|
|
4
|
+
exports.MCP_RESOURCE_METADATA = "mcp:resource";
|
|
5
|
+
exports.MCP_TOOL_METADATA = "mcp:tool";
|
|
6
|
+
exports.MCP_PROMPT_METADATA = "mcp:prompt";
|
|
7
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/decorators/constants.ts"],"names":[],"mappings":";;;AAGa,QAAA,qBAAqB,GAAG,cAAc,CAAA;AAKtC,QAAA,iBAAiB,GAAG,UAAU,CAAA;AAK9B,QAAA,mBAAmB,GAAG,YAAY,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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("./constants"), exports);
|
|
18
|
+
__exportStar(require("./base.decorator"), exports);
|
|
19
|
+
__exportStar(require("./mcp-resource.decorator"), exports);
|
|
20
|
+
__exportStar(require("./mcp-tool.decorator"), exports);
|
|
21
|
+
__exportStar(require("./mcp-prompt.decorator"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decorators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,mDAAgC;AAChC,2DAAwC;AACxC,uDAAoC;AACpC,yDAAsC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.McpPrompt = void 0;
|
|
4
|
+
const base_decorator_1 = require("./base.decorator");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const McpPrompt = (options) => (0, base_decorator_1.createMcpDecorator)(constants_1.MCP_PROMPT_METADATA, options);
|
|
7
|
+
exports.McpPrompt = McpPrompt;
|
|
8
|
+
//# sourceMappingURL=mcp-prompt.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-prompt.decorator.js","sourceRoot":"","sources":["../../src/decorators/mcp-prompt.decorator.ts"],"names":[],"mappings":";;;AAEA,qDAAqD;AACrD,2CAAiD;AA2C1C,MAAM,SAAS,GAAG,CAAC,OAAmB,EAAmB,EAAE,CAChE,IAAA,mCAAkB,EAAC,+BAAmB,EAAE,OAAO,CAAC,CAAA;AADrC,QAAA,SAAS,aAC4B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.McpResource = void 0;
|
|
4
|
+
const base_decorator_1 = require("./base.decorator");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const McpResource = (options) => (0, base_decorator_1.createMcpDecorator)(constants_1.MCP_RESOURCE_METADATA, options);
|
|
7
|
+
exports.McpResource = McpResource;
|
|
8
|
+
//# sourceMappingURL=mcp-resource.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-resource.decorator.js","sourceRoot":"","sources":["../../src/decorators/mcp-resource.decorator.ts"],"names":[],"mappings":";;;AACA,qDAAqD;AACrD,2CAAmD;AAiC5C,MAAM,WAAW,GAAG,CAAC,OAAwB,EAAmB,EAAE,CACvE,IAAA,mCAAkB,EAAC,iCAAqB,EAAE,OAAO,CAAC,CAAA;AADvC,QAAA,WAAW,eAC4B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.McpTool = void 0;
|
|
4
|
+
const base_decorator_1 = require("./base.decorator");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const McpTool = (options) => (0, base_decorator_1.createMcpDecorator)(constants_1.MCP_TOOL_METADATA, options);
|
|
7
|
+
exports.McpTool = McpTool;
|
|
8
|
+
//# sourceMappingURL=mcp-tool.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tool.decorator.js","sourceRoot":"","sources":["../../src/decorators/mcp-tool.decorator.ts"],"names":[],"mappings":";;;AACA,qDAAqD;AACrD,2CAA+C;AA8BxC,MAAM,OAAO,GAAG,CAAC,OAAoB,EAAmB,EAAE,CAC/D,IAAA,mCAAkB,EAAC,6BAAiB,EAAE,OAAO,CAAC,CAAA;AADnC,QAAA,OAAO,WAC4B"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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("./constants"), exports);
|
|
19
|
+
__exportStar(require("./interfaces"), exports);
|
|
20
|
+
__exportStar(require("./decorators"), exports);
|
|
21
|
+
__exportStar(require("./services"), exports);
|
|
22
|
+
__exportStar(require("./mcp.controller"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,+CAA4B;AAG5B,8CAA2B;AAG3B,+CAA4B;AAG5B,+CAA4B;AAG5B,6CAA0B;AAG1B,mDAAgC"}
|
|
@@ -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("./mcp-logger.interface"), exports);
|
|
18
|
+
__exportStar(require("./mcp-module-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,yDAAsC;AACtC,iEAA8C"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface McpLogger {
|
|
2
|
+
info(message: string, context?: string): void;
|
|
3
|
+
warn(message: string, context?: string): void;
|
|
4
|
+
error(message: string, context?: string, trace?: string): void;
|
|
5
|
+
debug(message: string, context?: string): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class DefaultMcpLogger implements McpLogger {
|
|
8
|
+
info(message: string, context?: string): void;
|
|
9
|
+
warn(message: string, context?: string): void;
|
|
10
|
+
error(message: string, context?: string, trace?: string): void;
|
|
11
|
+
debug(message: string, context?: string): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultMcpLogger = void 0;
|
|
4
|
+
class DefaultMcpLogger {
|
|
5
|
+
info(message, context) {
|
|
6
|
+
console.log(`[INFO] ${context ? `[${context}] ` : ""}${message}`);
|
|
7
|
+
}
|
|
8
|
+
warn(message, context) {
|
|
9
|
+
console.warn(`[WARN] ${context ? `[${context}] ` : ""}${message}`);
|
|
10
|
+
}
|
|
11
|
+
error(message, context, trace) {
|
|
12
|
+
console.error(`[ERROR] ${context ? `[${context}] ` : ""}${message}`);
|
|
13
|
+
if (trace) {
|
|
14
|
+
console.error(trace);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
debug(message, context) {
|
|
18
|
+
console.debug(`[DEBUG] ${context ? `[${context}] ` : ""}${message}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.DefaultMcpLogger = DefaultMcpLogger;
|
|
22
|
+
//# sourceMappingURL=mcp-logger.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-logger.interface.js","sourceRoot":"","sources":["../../src/interfaces/mcp-logger.interface.ts"],"names":[],"mappings":";;;AA8BA,MAAa,gBAAgB;IAC3B,IAAI,CAAC,OAAe,EAAE,OAAgB;QACpC,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IACnE,CAAC;IAED,IAAI,CAAC,OAAe,EAAE,OAAgB;QACpC,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,OAAgB,EAAE,KAAc;QACrD,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;QACpE,IAAI,KAAK,EAAE,CAAC;YACV,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACtB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAe,EAAE,OAAgB;QACrC,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;IACtE,CAAC;CACF;AAnBD,4CAmBC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { ResourceMetadata, ResourceTemplate as ResourceTemplateClass } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { Implementation, Resource } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { ModuleMetadata, Type } from "@nestjs/common";
|
|
5
|
+
import { ZodRawShape } from "zod";
|
|
6
|
+
import { McpLogger } from "./mcp-logger.interface";
|
|
7
|
+
export declare enum TransportType {
|
|
8
|
+
STDIO = "stdio",
|
|
9
|
+
SSE = "sse",
|
|
10
|
+
HTTP = "http",
|
|
11
|
+
NONE = "none"
|
|
12
|
+
}
|
|
13
|
+
export interface McpModuleOptions {
|
|
14
|
+
serverInfo: Implementation;
|
|
15
|
+
serverOptions?: ServerOptions;
|
|
16
|
+
transport?: TransportType;
|
|
17
|
+
logger?: McpLogger;
|
|
18
|
+
basePath?: string;
|
|
19
|
+
global?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface McpOptionsFactory {
|
|
22
|
+
createMcpOptions(): Promise<McpModuleOptions> | McpModuleOptions;
|
|
23
|
+
}
|
|
24
|
+
export interface McpModuleAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
25
|
+
useExisting?: Type<McpOptionsFactory>;
|
|
26
|
+
useClass?: Type<McpOptionsFactory>;
|
|
27
|
+
useFactory?: (...args: any[]) => Promise<McpModuleOptions> | McpModuleOptions;
|
|
28
|
+
inject?: any[];
|
|
29
|
+
global?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface FixedResourceOptions extends Resource {
|
|
32
|
+
metadata?: ResourceMetadata;
|
|
33
|
+
}
|
|
34
|
+
export interface TemplateResourceOptions {
|
|
35
|
+
name: string;
|
|
36
|
+
uriTemplate: string | ResourceTemplateClass;
|
|
37
|
+
description?: string;
|
|
38
|
+
metadata?: ResourceMetadata;
|
|
39
|
+
}
|
|
40
|
+
export type ResourceOptions = FixedResourceOptions | TemplateResourceOptions;
|
|
41
|
+
export interface ToolOptions {
|
|
42
|
+
name: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
paramsSchema?: ZodRawShape;
|
|
45
|
+
}
|
|
46
|
+
export interface IMetadataBase {
|
|
47
|
+
methodName: string;
|
|
48
|
+
options?: any;
|
|
49
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransportType = void 0;
|
|
4
|
+
var TransportType;
|
|
5
|
+
(function (TransportType) {
|
|
6
|
+
TransportType["STDIO"] = "stdio";
|
|
7
|
+
TransportType["SSE"] = "sse";
|
|
8
|
+
TransportType["HTTP"] = "http";
|
|
9
|
+
TransportType["NONE"] = "none";
|
|
10
|
+
})(TransportType || (exports.TransportType = TransportType = {}));
|
|
11
|
+
//# sourceMappingURL=mcp-module-options.interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-module-options.interface.js","sourceRoot":"","sources":["../../src/interfaces/mcp-module-options.interface.ts"],"names":[],"mappings":";;;AAcA,IAAY,aASX;AATD,WAAY,aAAa;IAEvB,gCAAe,CAAA;IAEf,4BAAW,CAAA;IAEX,8BAAa,CAAA;IAEb,8BAAa,CAAA;AACf,CAAC,EATW,aAAa,6BAAb,aAAa,QASxB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Request, Response } from "express";
|
|
2
|
+
import { McpLogger, McpModuleOptions } from "./interfaces";
|
|
3
|
+
import { McpHttpService } from "./services/mcp-http.service";
|
|
4
|
+
export declare class McpHttpController {
|
|
5
|
+
private readonly mcpHttpService;
|
|
6
|
+
private readonly logger;
|
|
7
|
+
private readonly loggerCtx;
|
|
8
|
+
private readonly basePath;
|
|
9
|
+
constructor(mcpHttpService: McpHttpService, options: McpModuleOptions, logger: McpLogger);
|
|
10
|
+
handleSSE(req: Request, res: Response): Promise<void>;
|
|
11
|
+
handleMessages(req: Request, res: Response): Promise<void>;
|
|
12
|
+
healthCheck(req: Request, res: Response): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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.McpHttpController = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const constants_1 = require("./constants");
|
|
18
|
+
const mcp_http_service_1 = require("./services/mcp-http.service");
|
|
19
|
+
let McpHttpController = class McpHttpController {
|
|
20
|
+
constructor(mcpHttpService, options, logger) {
|
|
21
|
+
this.mcpHttpService = mcpHttpService;
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
this.loggerCtx = "McpHttpController";
|
|
24
|
+
this.basePath = options.basePath || constants_1.DEFAULT_MCP_PATH;
|
|
25
|
+
}
|
|
26
|
+
async handleSSE(req, res) {
|
|
27
|
+
if (!req.path.includes(this.basePath)) {
|
|
28
|
+
res.status(404).send("Not found");
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.logger.debug("SSE connection request received", this.loggerCtx);
|
|
32
|
+
return this.mcpHttpService.handleSSE(res);
|
|
33
|
+
}
|
|
34
|
+
async handleMessages(req, res) {
|
|
35
|
+
if (!req.path.includes(this.basePath)) {
|
|
36
|
+
res.status(404).send("Not found");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.logger.debug("MCP message received", this.loggerCtx);
|
|
40
|
+
return this.mcpHttpService.handleMessage(req, res);
|
|
41
|
+
}
|
|
42
|
+
healthCheck(req, res) {
|
|
43
|
+
if (!req.path.includes(this.basePath)) {
|
|
44
|
+
res.status(404).send("Not found");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.logger.debug("Health check request received", this.loggerCtx);
|
|
48
|
+
res.json({
|
|
49
|
+
status: "ok",
|
|
50
|
+
timestamp: new Date().toISOString(),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
exports.McpHttpController = McpHttpController;
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, common_1.Get)("*/sse"),
|
|
57
|
+
__param(0, (0, common_1.Req)()),
|
|
58
|
+
__param(1, (0, common_1.Res)()),
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
61
|
+
__metadata("design:returntype", Promise)
|
|
62
|
+
], McpHttpController.prototype, "handleSSE", null);
|
|
63
|
+
__decorate([
|
|
64
|
+
(0, common_1.Post)("*/messages"),
|
|
65
|
+
__param(0, (0, common_1.Req)()),
|
|
66
|
+
__param(1, (0, common_1.Res)()),
|
|
67
|
+
__metadata("design:type", Function),
|
|
68
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
69
|
+
__metadata("design:returntype", Promise)
|
|
70
|
+
], McpHttpController.prototype, "handleMessages", null);
|
|
71
|
+
__decorate([
|
|
72
|
+
(0, common_1.Get)("*/health"),
|
|
73
|
+
__param(0, (0, common_1.Req)()),
|
|
74
|
+
__param(1, (0, common_1.Res)()),
|
|
75
|
+
__metadata("design:type", Function),
|
|
76
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
77
|
+
__metadata("design:returntype", void 0)
|
|
78
|
+
], McpHttpController.prototype, "healthCheck", null);
|
|
79
|
+
exports.McpHttpController = McpHttpController = __decorate([
|
|
80
|
+
(0, common_1.Controller)(),
|
|
81
|
+
__param(1, (0, common_1.Inject)(constants_1.MCP_MODULE_OPTIONS)),
|
|
82
|
+
__param(2, (0, common_1.Inject)(constants_1.MCP_LOGGER)),
|
|
83
|
+
__metadata("design:paramtypes", [mcp_http_service_1.McpHttpService, Object, Object])
|
|
84
|
+
], McpHttpController);
|
|
85
|
+
//# sourceMappingURL=mcp.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp.controller.js","sourceRoot":"","sources":["../src/mcp.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAOuB;AAGvB,2CAA8E;AAE9E,kEAA4D;AAWrD,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAI5B,YACmB,cAA8B,EACnB,OAAyB,EACjC,MAAkC;QAFrC,mBAAc,GAAd,cAAc,CAAgB;QAEV,WAAM,GAAN,MAAM,CAAW;QANvC,cAAS,GAAG,mBAAmB,CAAA;QAQ9C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,4BAAgB,CAAA;IACtD,CAAC;IAMK,AAAN,KAAK,CAAC,SAAS,CAAQ,GAAY,EAAS,GAAa;QACvD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACjC,OAAM;QACR,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QACpE,OAAO,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IAC3C,CAAC;IAMK,AAAN,KAAK,CAAC,cAAc,CACX,GAAY,EACZ,GAAa;QAEpB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACjC,OAAM;QACR,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QACzD,OAAO,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACpD,CAAC;IAMD,WAAW,CAAQ,GAAY,EAAS,GAAa;QACnD,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;YACjC,OAAM;QACR,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+BAA+B,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;QAClE,GAAG,CAAC,IAAI,CAAC;YACP,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;SACpC,CAAC,CAAA;IACJ,CAAC;CACF,CAAA;AAxDY,8CAAiB;AAgBtB;IADL,IAAA,YAAG,EAAC,OAAO,CAAC;IACI,WAAA,IAAA,YAAG,GAAE,CAAA;IAAgB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;kDAO1C;AAMK;IADL,IAAA,aAAI,EAAC,YAAY,CAAC;IAEhB,WAAA,IAAA,YAAG,GAAE,CAAA;IACL,WAAA,IAAA,YAAG,GAAE,CAAA;;;;uDAQP;AAMD;IADC,IAAA,YAAG,EAAC,UAAU,CAAC;IACH,WAAA,IAAA,YAAG,GAAE,CAAA;IAAgB,WAAA,IAAA,YAAG,GAAE,CAAA;;;;oDAUtC;4BAvDU,iBAAiB;IAD7B,IAAA,mBAAU,GAAE;IAOR,WAAA,IAAA,eAAM,EAAC,8BAAkB,CAAC,CAAA;IAC1B,WAAA,IAAA,eAAM,EAAC,sBAAU,CAAC,CAAA;qCAFc,iCAAc;GALtC,iBAAiB,CAwD7B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DynamicModule, OnApplicationBootstrap } from "@nestjs/common";
|
|
2
|
+
import { McpLogger, McpModuleAsyncOptions, McpModuleOptions } from "./interfaces";
|
|
3
|
+
import { ExplorerService, McpService } from "./services";
|
|
4
|
+
export declare class McpModule implements OnApplicationBootstrap {
|
|
5
|
+
private readonly explorerService;
|
|
6
|
+
private readonly mcpService;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(explorerService: ExplorerService, mcpService: McpService, logger: McpLogger);
|
|
9
|
+
static forRoot(options: McpModuleOptions): DynamicModule;
|
|
10
|
+
static forRootAsync(options: McpModuleAsyncOptions): DynamicModule;
|
|
11
|
+
private static createAsyncProviders;
|
|
12
|
+
private static createAsyncOptionsProvider;
|
|
13
|
+
private static createAsyncLoggerProvider;
|
|
14
|
+
onApplicationBootstrap(): Promise<void>;
|
|
15
|
+
private registerMcpHandlers;
|
|
16
|
+
}
|