@muzikanto/nestjs-mcp 1.1.1 → 1.3.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/CHANGELOG.md +12 -0
- package/README.md +97 -50
- package/dist/index.d.ts +6 -3
- package/dist/index.js +6 -3
- package/dist/mcp-client/mcp-client.module.d.ts +15 -0
- package/dist/mcp-client/mcp-client.module.js +42 -0
- package/dist/mcp-client/mcp-client.service.d.ts +12 -0
- package/dist/mcp-client/mcp-client.service.js +49 -0
- package/dist/mcp-server/config.d.ts +6 -0
- package/dist/mcp-server/config.js +7 -0
- package/dist/mcp-server/decorators/mcp-prompt.decorator.d.ts +25 -0
- package/dist/mcp-server/decorators/mcp-prompt.decorator.js +16 -0
- package/dist/mcp-server/decorators/mcp-resource.decorator.d.ts +26 -0
- package/dist/mcp-server/decorators/mcp-resource.decorator.js +16 -0
- package/dist/mcp-server/decorators/mcp-tool.decorator.d.ts +17 -0
- package/dist/mcp-server/decorators/mcp-tool.decorator.js +16 -0
- package/dist/mcp-server/dto/McpMessage.dto.d.ts +5 -0
- package/dist/mcp-server/dto/McpMessage.dto.js +26 -0
- package/dist/mcp-server/dto/McpPrompt.dto.d.ts +6 -0
- package/dist/mcp-server/dto/McpPrompt.dto.js +49 -0
- package/dist/mcp-server/dto/McpPromptMessage.d.ts +5 -0
- package/dist/mcp-server/dto/McpPromptMessage.js +40 -0
- package/dist/mcp-server/dto/McpPromptMessages.dto.d.ts +4 -0
- package/dist/mcp-server/dto/McpPromptMessages.dto.js +26 -0
- package/dist/mcp-server/dto/McpPrompts.dto.d.ts +4 -0
- package/dist/mcp-server/dto/McpPrompts.dto.js +26 -0
- package/dist/mcp-server/dto/McpTool.dto.d.ts +6 -0
- package/dist/mcp-server/dto/McpTool.dto.js +49 -0
- package/dist/mcp-server/dto/McpTools.dto.d.ts +4 -0
- package/dist/mcp-server/dto/McpTools.dto.js +22 -0
- package/dist/mcp-server/mcp.controller.d.ts +20 -0
- package/dist/mcp-server/mcp.controller.js +197 -0
- package/dist/mcp-server/mcp.explorer.d.ts +9 -0
- package/dist/mcp-server/mcp.explorer.js +71 -0
- package/dist/mcp-server/mcp.module.d.ts +12 -0
- package/dist/mcp-server/mcp.module.js +54 -0
- package/dist/mcp-server/mcp.service.d.ts +64 -0
- package/dist/mcp-server/mcp.service.js +247 -0
- package/dist/mcp-server/sse.service.d.ts +6 -0
- package/dist/mcp-server/sse.service.js +45 -0
- package/dist/mcp-server/utils/context.decorator.d.ts +1 -0
- package/dist/mcp-server/utils/context.decorator.js +5 -0
- package/dist/mcp-server/utils/http-adapter.d.ts +18 -0
- package/dist/mcp-server/utils/http-adapter.js +18 -0
- package/dist/mcp-server/utils/http.d.ts +10 -0
- package/dist/mcp-server/utils/http.js +2 -0
- package/dist/mcp-server/utils/inject-tokens.d.ts +2 -0
- package/dist/mcp-server/utils/inject-tokens.js +5 -0
- package/dist/mcp-server/utils/ref.d.ts +1 -0
- package/dist/mcp-server/utils/ref.js +4 -0
- package/dist/mcp-server/utils/run-guards.d.ts +6 -0
- package/dist/mcp-server/utils/run-guards.js +34 -0
- package/dist/mcp-server/utils/run-interceprots.d.ts +11 -0
- package/dist/mcp-server/utils/run-interceprots.js +43 -0
- package/dist/mcp-server/utils/run-interceptors.d.ts +7 -0
- package/dist/mcp-server/utils/run-interceptors.js +40 -0
- package/dist/mcp-server/utils/zod.d.ts +1 -0
- package/dist/mcp-server/utils/zod.js +29 -0
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @muzikanto/nestjs-mcp
|
|
2
2
|
|
|
3
|
+
## 1.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- a5c79ec: add guards and interceptors
|
|
8
|
+
|
|
9
|
+
## 1.2.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- bb282b4: Add resource decorator, move http controllers routes
|
|
14
|
+
|
|
3
15
|
## 1.1.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/Muzikanto/nestjs-mcp)
|
|
6
6
|
[](https://github.com/Muzikanto/nestjs-mcp/blob/main/LICENSE)
|
|
7
7
|
|
|
8
|
-
NestJS MCP (Model Context Protocol) module — allows you to create “tools”
|
|
8
|
+
NestJS MCP (Model Context Protocol) module — allows you to create “tools”, “prompts”, “resources” for LLM or HTTP, with automatic detection via decorators, validation, and integration with OpenAI Function Calls.
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -16,10 +16,11 @@ NestJS MCP (Model Context Protocol) module — allows you to create “tools”
|
|
|
16
16
|
- [Connecting the MCP module](#connecting-the-mcp-module)
|
|
17
17
|
- [Create MCP tool](#create-mcp-tool)
|
|
18
18
|
- [Create MCP prompt](#create-mcp-prompt)
|
|
19
|
+
- [Create MCP resource](#create-mcp-resource)
|
|
19
20
|
- [Calling MCP tools via HTTP](#calling-mcp-tools-via-http)
|
|
21
|
+
- [Calling MCP prompt via HTTP](#obtain-prompt)
|
|
20
22
|
- [Obtaining all tools](#obtaining-all-tools)
|
|
21
23
|
- [Obtaining all prompts](#obtaining-all-prompts)
|
|
22
|
-
- [Obtain prompt](#obtain-prompt)
|
|
23
24
|
- [Auth guard](#auth-guard)
|
|
24
25
|
- [Integration with OpenAI Function Calls](#integration-with-openai-function-calls)
|
|
25
26
|
|
|
@@ -29,11 +30,13 @@ NestJS MCP (Model Context Protocol) module — allows you to create “tools”
|
|
|
29
30
|
- Register MCP prompts using the `@McpPrompt()` decorator
|
|
30
31
|
- Automatic detection of all providers (tools) in the module
|
|
31
32
|
- Input data validation
|
|
32
|
-
-
|
|
33
|
+
- SSE endpoints for MCP (`GET /mcp/sse, POST /mcp/messages`)
|
|
34
|
+
- Endpoint for calling tool (`POST /mcp/toos`)
|
|
33
35
|
- Endpoint for a list of all tools (`GET /mcp/tools`)
|
|
36
|
+
- Endpoint for calling prompt (`POST /mcp/prompts/:name`)
|
|
34
37
|
- Endpoint for a list of all prompts (`GET /mcp/prompts`)
|
|
35
|
-
- Endpoint for prompt (`GET /mcp/prompts/:name`)
|
|
36
38
|
- Easy integration with LLM (OpenAI Function Calls)
|
|
39
|
+
- Support http adapters (default fastify)
|
|
37
40
|
- Full TypeScript typing
|
|
38
41
|
|
|
39
42
|
---
|
|
@@ -44,7 +47,7 @@ NestJS MCP (Model Context Protocol) module — allows you to create “tools”
|
|
|
44
47
|
yarn add @muzikanto/nestjs-mcp
|
|
45
48
|
```
|
|
46
49
|
|
|
47
|
-
Peer dependencies: `@nestjs/common, @nestjs/core, reflect-metadata`
|
|
50
|
+
Peer dependencies: `@nestjs/common, @nestjs/core, @nestjs/swagger, reflect-metadata`
|
|
48
51
|
|
|
49
52
|
## Usage
|
|
50
53
|
|
|
@@ -71,6 +74,12 @@ export class AppModule {}
|
|
|
71
74
|
```ts
|
|
72
75
|
import { IMcpTool, McpTool } from '@muzikanto/nestjs-mcp';
|
|
73
76
|
import { Telegraf } from 'telegraf';
|
|
77
|
+
import z from 'zod';
|
|
78
|
+
|
|
79
|
+
const schema = {
|
|
80
|
+
chatId: z.string().describe('Telegram chat id'), // строка с описанием
|
|
81
|
+
text: z.string().describe('Message text'), // строка с описанием
|
|
82
|
+
};
|
|
74
83
|
|
|
75
84
|
@McpTool()
|
|
76
85
|
export class TelegramSendMessageTool implements IMcpTool<
|
|
@@ -79,20 +88,7 @@ export class TelegramSendMessageTool implements IMcpTool<
|
|
|
79
88
|
> {
|
|
80
89
|
name = 'telegram.sendMessage';
|
|
81
90
|
|
|
82
|
-
inputSchema =
|
|
83
|
-
type: "object",
|
|
84
|
-
properties: {
|
|
85
|
-
chatId: {
|
|
86
|
-
type: "string",
|
|
87
|
-
description: "Telegram chat id"
|
|
88
|
-
},
|
|
89
|
-
text: {
|
|
90
|
-
type: "string",
|
|
91
|
-
description: "Message text"
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
required: ["chatId", "text"]
|
|
95
|
-
};
|
|
91
|
+
inputSchema = schema;
|
|
96
92
|
|
|
97
93
|
constructor(private readonly bot: Telegraf) {}
|
|
98
94
|
|
|
@@ -136,14 +132,21 @@ GET /mcp/tool
|
|
|
136
132
|
"name": "telegram.sendMessage",
|
|
137
133
|
"description": "Sent message via Telegram",
|
|
138
134
|
"inputSchema": {
|
|
139
|
-
"
|
|
140
|
-
|
|
141
|
-
|
|
135
|
+
"type": "object",
|
|
136
|
+
"properties": {
|
|
137
|
+
"chatId": {
|
|
138
|
+
"type": "number",
|
|
139
|
+
"description": "Telegram chat ID"
|
|
140
|
+
},
|
|
141
|
+
"text": {
|
|
142
|
+
"type": "string",
|
|
143
|
+
"description": "Message text"
|
|
144
|
+
}
|
|
142
145
|
},
|
|
143
|
-
"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
146
|
+
"required": [
|
|
147
|
+
"chatId",
|
|
148
|
+
"text"
|
|
149
|
+
]
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
152
|
]
|
|
@@ -153,11 +156,18 @@ GET /mcp/tool
|
|
|
153
156
|
|
|
154
157
|
```ts
|
|
155
158
|
import { IMcpPrompt, McpPrompt } from '@muzikanto/nestjs-mcp';
|
|
159
|
+
import z from 'zod';
|
|
160
|
+
|
|
161
|
+
const schema = {
|
|
162
|
+
chatId: z.string().describe('Telegram chat id'), // строка с описанием
|
|
163
|
+
text: z.string().describe('Message text'), // строка с описанием
|
|
164
|
+
};
|
|
156
165
|
|
|
157
166
|
@McpPrompt()
|
|
158
167
|
export class TelegramAutoReplyPrompt implements IMcpPrompt<{ text: string; chatId: number; }> {
|
|
159
168
|
name = 'telegram_auto_reply';
|
|
160
169
|
description = 'Generate a short, fiendly reply to an incoming Telegram message and send it back to the same chat using teegram.sendMessage tool';
|
|
170
|
+
schema = schema;
|
|
161
171
|
|
|
162
172
|
async execute({ text, chatId }: { text: string; chatId: number }) {
|
|
163
173
|
return [
|
|
@@ -192,12 +202,29 @@ GET /mcp/prompts
|
|
|
192
202
|
[
|
|
193
203
|
{
|
|
194
204
|
"name": "telegram_auto_reply",
|
|
195
|
-
"description": "Generate a short, fiendly reply to an incoming Telegram message and send it back to the same chat using teegram.sendMessage tool"
|
|
205
|
+
"description": "Generate a short, fiendly reply to an incoming Telegram message and send it back to the same chat using teegram.sendMessage tool",
|
|
206
|
+
"inputSchema": {
|
|
207
|
+
"type": "object",
|
|
208
|
+
"properties": {
|
|
209
|
+
"chatId": {
|
|
210
|
+
"type": "number",
|
|
211
|
+
"description": "Telegram chat ID"
|
|
212
|
+
},
|
|
213
|
+
"text": {
|
|
214
|
+
"type": "string",
|
|
215
|
+
"description": "Message text"
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
"required": [
|
|
219
|
+
"chatId",
|
|
220
|
+
"text"
|
|
221
|
+
]
|
|
222
|
+
}
|
|
196
223
|
}
|
|
197
224
|
]
|
|
198
225
|
```
|
|
199
226
|
|
|
200
|
-
###
|
|
227
|
+
### Calling MCP prompt via HTTP
|
|
201
228
|
|
|
202
229
|
POST /mcp/prompts/telegram_auto_reply
|
|
203
230
|
|
|
@@ -234,29 +261,52 @@ Response
|
|
|
234
261
|
}
|
|
235
262
|
```
|
|
236
263
|
|
|
264
|
+
### Create MCP resource
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
import { IMcpResource, McpResource } from '@muzikanto/nestjs-mcp';
|
|
268
|
+
|
|
269
|
+
@McpResource()
|
|
270
|
+
export class TestResource implements IMcpResource<{ userId: string }> {
|
|
271
|
+
name = 'users.get';
|
|
272
|
+
uri = 'users://{userId}';
|
|
273
|
+
title = 'Get test user';
|
|
274
|
+
description = 'Get user by id';
|
|
275
|
+
|
|
276
|
+
async execute(url: URL, vars: { userId: string }) {
|
|
277
|
+
return [{ uri: url.href, text: `Hello ${vars.userId}` }];
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
237
282
|
### Auth guard
|
|
238
283
|
```ts
|
|
239
|
-
import {
|
|
240
|
-
import {
|
|
284
|
+
import { IMcpTool, McpTool } from '@muzikanto/nestjs-mcp';
|
|
285
|
+
import { UseGuards } from '@nestjs/common';
|
|
286
|
+
import { CanActivate, ExecutionContext, Injectable } from '@nestjs/common';
|
|
287
|
+
import { Observable } from 'rxjs';
|
|
241
288
|
|
|
242
289
|
@Injectable()
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
return true;
|
|
249
|
-
}
|
|
290
|
+
class TestGuard implements CanActivate {
|
|
291
|
+
canActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean> {
|
|
292
|
+
console.log('TestGuard called');
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
250
295
|
}
|
|
251
296
|
|
|
252
|
-
@
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
297
|
+
@UseGuard(TestGuard)
|
|
298
|
+
@McpTool()
|
|
299
|
+
export class TelegramSendMessageTool implements IMcpTool<
|
|
300
|
+
{ chatId: string; text: string },
|
|
301
|
+
{ success: boolean }
|
|
302
|
+
> {
|
|
303
|
+
name = 'telegram.sendMessage';
|
|
304
|
+
|
|
305
|
+
async execute() {
|
|
306
|
+
await this.bot.telegram.sendMessage(input.chatId, input.text);
|
|
307
|
+
return { success: true };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
260
310
|
```
|
|
261
311
|
|
|
262
312
|
### Integration with OpenAI Function Calls
|
|
@@ -265,7 +315,6 @@ export class AppModule {}
|
|
|
265
315
|
import axios from 'axios';
|
|
266
316
|
import OpenAI from 'openai';
|
|
267
317
|
|
|
268
|
-
const MCP_URL = 'http://localhost:3000/mcp';
|
|
269
318
|
const MCP_TOOLS_URL = 'http://localhost:3000/mcp/tools';
|
|
270
319
|
const MCP_TELEGRAM_PROMPT_URL = 'http://localhost:3000/mcp/prompts/telegram_auto_reply';
|
|
271
320
|
|
|
@@ -277,7 +326,7 @@ const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
|
277
326
|
*/
|
|
278
327
|
async function getMcpTools() {
|
|
279
328
|
const response = await axios.get(MCP_TOOLS_URL);
|
|
280
|
-
return response.data;
|
|
329
|
+
return response.data.tools.map(el => ({ name: el.name, description: el.description, parameters: el.inputSchema }));
|
|
281
330
|
}
|
|
282
331
|
|
|
283
332
|
/**
|
|
@@ -286,16 +335,14 @@ async function getMcpTools() {
|
|
|
286
335
|
async function getMcpPrompt() {
|
|
287
336
|
const response = await axios.post(MCP_TELEGRAM_PROMPT_URL, {/* propmpt generation arguments */});
|
|
288
337
|
return response.data;
|
|
289
|
-
}
|
|
290
338
|
|
|
291
339
|
/**
|
|
292
340
|
* Request mcp tool
|
|
293
341
|
*/
|
|
294
342
|
async function callMcpTool(toolName: string, payload: Record<string, any>) {
|
|
295
343
|
const response = await axios.post(
|
|
296
|
-
|
|
344
|
+
MCP_TOOLS_URL,
|
|
297
345
|
{ type: toolName, payload },
|
|
298
|
-
{ headers: { 'Content-Type': 'application/json' } }
|
|
299
346
|
);
|
|
300
347
|
return response.data;
|
|
301
348
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
export * from "./mcp.module";
|
|
2
|
-
export * from "./decorators/mcp-tool.decorator";
|
|
3
|
-
export * from "./decorators/mcp-prompt.decorator";
|
|
1
|
+
export * from "./mcp-server/mcp.module";
|
|
2
|
+
export * from "./mcp-server/decorators/mcp-tool.decorator";
|
|
3
|
+
export * from "./mcp-server/decorators/mcp-prompt.decorator";
|
|
4
|
+
export * from "./mcp-server/decorators/mcp-resource.decorator";
|
|
5
|
+
export * from "./mcp-client/mcp-client.module";
|
|
6
|
+
export * from "./mcp-client/mcp-client.service";
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./mcp.module"), exports);
|
|
18
|
-
__exportStar(require("./decorators/mcp-tool.decorator"), exports);
|
|
19
|
-
__exportStar(require("./decorators/mcp-prompt.decorator"), exports);
|
|
17
|
+
__exportStar(require("./mcp-server/mcp.module"), exports);
|
|
18
|
+
__exportStar(require("./mcp-server/decorators/mcp-tool.decorator"), exports);
|
|
19
|
+
__exportStar(require("./mcp-server/decorators/mcp-prompt.decorator"), exports);
|
|
20
|
+
__exportStar(require("./mcp-server/decorators/mcp-resource.decorator"), exports);
|
|
21
|
+
__exportStar(require("./mcp-client/mcp-client.module"), exports);
|
|
22
|
+
__exportStar(require("./mcp-client/mcp-client.service"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Provider, Type } from "@nestjs/common";
|
|
2
|
+
export interface IMcpClientConfig {
|
|
3
|
+
url: string;
|
|
4
|
+
}
|
|
5
|
+
export declare class McpClientModule {
|
|
6
|
+
static forRoot(metadata: {
|
|
7
|
+
useValue?: IMcpClientConfig;
|
|
8
|
+
useExisting?: Type<IMcpClientConfig>;
|
|
9
|
+
useFactory?: (...args: any) => IMcpClientConfig | Promise<IMcpClientConfig>;
|
|
10
|
+
}): {
|
|
11
|
+
module: typeof McpClientModule;
|
|
12
|
+
implements: import("@nestjs/common").DynamicModule[];
|
|
13
|
+
providers: Provider<IMcpClientConfig>[];
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 McpClientModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.McpClientModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const mcp_client_service_1 = require("./mcp-client.service");
|
|
13
|
+
const inject_tokens_1 = require("../mcp-server/utils/inject-tokens");
|
|
14
|
+
const axios_1 = require("@nestjs/axios");
|
|
15
|
+
let McpClientModule = McpClientModule_1 = class McpClientModule {
|
|
16
|
+
static forRoot(metadata) {
|
|
17
|
+
const configProvider = {
|
|
18
|
+
provide: inject_tokens_1.MCP_CLIENT_CONFIG,
|
|
19
|
+
...(metadata.useValue
|
|
20
|
+
? { useValue: metadata.useValue }
|
|
21
|
+
: metadata.useExisting
|
|
22
|
+
? { useExisting: metadata.useExisting }
|
|
23
|
+
: { useFactory: metadata.useFactory }),
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
module: McpClientModule_1,
|
|
27
|
+
implements: [
|
|
28
|
+
axios_1.HttpModule.registerAsync({
|
|
29
|
+
inject: [inject_tokens_1.MCP_CLIENT_CONFIG],
|
|
30
|
+
useFactory: (config) => {
|
|
31
|
+
return { baseUrl: config.url };
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
],
|
|
35
|
+
providers: [mcp_client_service_1.McpClientService, configProvider],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
exports.McpClientModule = McpClientModule;
|
|
40
|
+
exports.McpClientModule = McpClientModule = McpClientModule_1 = __decorate([
|
|
41
|
+
(0, common_1.Module)({})
|
|
42
|
+
], McpClientModule);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { HttpService } from "@nestjs/axios";
|
|
2
|
+
import { McpToolsDto } from "../mcp-server/dto/McpTools.dto";
|
|
3
|
+
import { McpPromptsDto } from "../mcp-server/dto/McpPrompts.dto";
|
|
4
|
+
import { McpPromptMessagesDto } from "../mcp-server/dto/McpPromptMessages.dto";
|
|
5
|
+
export declare class McpClientService {
|
|
6
|
+
private readonly httpService;
|
|
7
|
+
constructor(httpService: HttpService);
|
|
8
|
+
getAllTools(): Promise<McpToolsDto>;
|
|
9
|
+
getAllPrompts(): Promise<McpPromptsDto>;
|
|
10
|
+
getPromptByName<Payload = any>(promptName: string, params: Payload): Promise<McpPromptMessagesDto>;
|
|
11
|
+
callMcpTool<Payload = any, Result = any>(toolName: string, payload: Payload): Promise<Result>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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.McpClientService = void 0;
|
|
13
|
+
const axios_1 = require("@nestjs/axios");
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
let McpClientService = class McpClientService {
|
|
16
|
+
httpService;
|
|
17
|
+
constructor(httpService) {
|
|
18
|
+
this.httpService = httpService;
|
|
19
|
+
}
|
|
20
|
+
// Получить все инструменты
|
|
21
|
+
async getAllTools() {
|
|
22
|
+
const response = await this.httpService.get("/mcp/tools").toPromise();
|
|
23
|
+
return response.data;
|
|
24
|
+
}
|
|
25
|
+
// Получить все подсказки
|
|
26
|
+
async getAllPrompts() {
|
|
27
|
+
const response = await this.httpService.get("/mcp/prompts").toPromise();
|
|
28
|
+
return response.data;
|
|
29
|
+
}
|
|
30
|
+
// Получить подсказку по имени
|
|
31
|
+
async getPromptByName(promptName, params) {
|
|
32
|
+
const response = await this.httpService
|
|
33
|
+
.post(`/mcp/prompts/${promptName}`, params)
|
|
34
|
+
.toPromise();
|
|
35
|
+
return response.data;
|
|
36
|
+
}
|
|
37
|
+
// Вызвать инструмент MCP
|
|
38
|
+
async callMcpTool(toolName, payload) {
|
|
39
|
+
const response = await this.httpService
|
|
40
|
+
.post("/mcp/tools", { type: toolName, payload }, { headers: { "Content-Type": "application/json" } })
|
|
41
|
+
.toPromise();
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
exports.McpClientService = McpClientService;
|
|
46
|
+
exports.McpClientService = McpClientService = __decorate([
|
|
47
|
+
(0, common_1.Injectable)(),
|
|
48
|
+
__metadata("design:paramtypes", [axios_1.HttpService])
|
|
49
|
+
], McpClientService);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InjectMcpConfig = exports.MCP_CONFIG_TOKEN = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.MCP_CONFIG_TOKEN = "mcl:config-token";
|
|
6
|
+
const InjectMcpConfig = () => (0, common_1.Inject)(exports.MCP_CONFIG_TOKEN);
|
|
7
|
+
exports.InjectMcpConfig = InjectMcpConfig;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type * as z3 from "zod/v3";
|
|
3
|
+
type AnySchema = z3.ZodTypeAny;
|
|
4
|
+
type ZodRawShapeCompat = Record<string, AnySchema>;
|
|
5
|
+
export type IMcpPromptMessage = {
|
|
6
|
+
role: "user" | "assistant" | "system";
|
|
7
|
+
content?: string;
|
|
8
|
+
tool_call?: {
|
|
9
|
+
name: string;
|
|
10
|
+
arguments: object;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export interface IMcpPrompt<Payload = any, Result extends IMcpPromptMessage[] = IMcpPromptMessage[]> {
|
|
14
|
+
name: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
inputSchema?: ZodRawShapeCompat;
|
|
18
|
+
execute(input: Payload): Promise<Result>;
|
|
19
|
+
}
|
|
20
|
+
export declare const MCP_PROMPT_METADATA = "mcp:prompt-class";
|
|
21
|
+
/**
|
|
22
|
+
* Декоратор класса для MCP prompt
|
|
23
|
+
*/
|
|
24
|
+
export declare const McpPrompt: () => (target: any) => void;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.McpPrompt = exports.MCP_PROMPT_METADATA = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
exports.MCP_PROMPT_METADATA = "mcp:prompt-class";
|
|
7
|
+
/**
|
|
8
|
+
* Декоратор класса для MCP prompt
|
|
9
|
+
*/
|
|
10
|
+
const McpPrompt = () => {
|
|
11
|
+
return (target) => {
|
|
12
|
+
(0, common_1.Injectable)()(target);
|
|
13
|
+
Reflect.defineMetadata(exports.MCP_PROMPT_METADATA, {}, target);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.McpPrompt = McpPrompt;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol";
|
|
2
|
+
import { ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types";
|
|
3
|
+
import "reflect-metadata";
|
|
4
|
+
export type IMcpResourceResult = {
|
|
5
|
+
uri: string;
|
|
6
|
+
text: string;
|
|
7
|
+
};
|
|
8
|
+
export type IMcpResourceListItem = {
|
|
9
|
+
name: string;
|
|
10
|
+
uri: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
};
|
|
14
|
+
export interface IMcpResource<Payload = any> {
|
|
15
|
+
name: string;
|
|
16
|
+
uri: string;
|
|
17
|
+
title?: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
execute(url: URL, input: Payload): Promise<IMcpResourceResult[]>;
|
|
20
|
+
list?(extra: RequestHandlerExtra<ServerRequest, ServerNotification>): Promise<IMcpResourceListItem[]>;
|
|
21
|
+
}
|
|
22
|
+
export declare const MCP_RESOURCE_METADATA = "mcp:resource-class";
|
|
23
|
+
/**
|
|
24
|
+
* Декоратор класса для MCP resource
|
|
25
|
+
*/
|
|
26
|
+
export declare const McpResource: () => (target: any) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.McpResource = exports.MCP_RESOURCE_METADATA = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
exports.MCP_RESOURCE_METADATA = "mcp:resource-class";
|
|
7
|
+
/**
|
|
8
|
+
* Декоратор класса для MCP resource
|
|
9
|
+
*/
|
|
10
|
+
const McpResource = () => {
|
|
11
|
+
return (target) => {
|
|
12
|
+
(0, common_1.Injectable)()(target);
|
|
13
|
+
Reflect.defineMetadata(exports.MCP_RESOURCE_METADATA, {}, target);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.McpResource = McpResource;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import type * as z3 from "zod/v3";
|
|
3
|
+
type AnySchema = z3.ZodTypeAny;
|
|
4
|
+
type ZodRawShapeCompat = Record<string, AnySchema>;
|
|
5
|
+
export interface IMcpTool<Payload = any, Result = any> {
|
|
6
|
+
name: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
inputSchema?: ZodRawShapeCompat;
|
|
10
|
+
execute(input: Payload): Promise<Result>;
|
|
11
|
+
}
|
|
12
|
+
export declare const MCP_TOOL_METADATA = "mcp:tool-class";
|
|
13
|
+
/**
|
|
14
|
+
* Декоратор класса для MCP тулзы
|
|
15
|
+
*/
|
|
16
|
+
export declare const McpTool: () => ClassDecorator;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.McpTool = exports.MCP_TOOL_METADATA = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
require("reflect-metadata");
|
|
6
|
+
exports.MCP_TOOL_METADATA = "mcp:tool-class";
|
|
7
|
+
/**
|
|
8
|
+
* Декоратор класса для MCP тулзы
|
|
9
|
+
*/
|
|
10
|
+
const McpTool = () => {
|
|
11
|
+
return (target) => {
|
|
12
|
+
(0, common_1.Injectable)()(target);
|
|
13
|
+
Reflect.defineMetadata(exports.MCP_TOOL_METADATA, {}, target);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
exports.McpTool = McpTool;
|
|
@@ -0,0 +1,26 @@
|
|
|
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.McpMessageDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
class McpMessageDto {
|
|
15
|
+
type;
|
|
16
|
+
payload;
|
|
17
|
+
}
|
|
18
|
+
exports.McpMessageDto = McpMessageDto;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, swagger_1.ApiProperty)({ type: "string", description: "Tool name" }),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], McpMessageDto.prototype, "type", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, swagger_1.ApiProperty)({ description: "Tool handler payload" }),
|
|
25
|
+
__metadata("design:type", Object)
|
|
26
|
+
], McpMessageDto.prototype, "payload", void 0);
|
|
@@ -0,0 +1,49 @@
|
|
|
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.McpPromptDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
class McpPromptDto {
|
|
15
|
+
name;
|
|
16
|
+
title;
|
|
17
|
+
description;
|
|
18
|
+
inputSchema;
|
|
19
|
+
}
|
|
20
|
+
exports.McpPromptDto = McpPromptDto;
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, swagger_1.ApiProperty)({ type: "string", description: "Propmt name" }),
|
|
23
|
+
__metadata("design:type", String)
|
|
24
|
+
], McpPromptDto.prototype, "name", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, swagger_1.ApiProperty)({
|
|
27
|
+
type: "string",
|
|
28
|
+
description: "Propmt title",
|
|
29
|
+
nullable: true,
|
|
30
|
+
}),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], McpPromptDto.prototype, "title", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, swagger_1.ApiProperty)({
|
|
35
|
+
type: "string",
|
|
36
|
+
description: "Propmt description",
|
|
37
|
+
nullable: true,
|
|
38
|
+
}),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], McpPromptDto.prototype, "description", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, swagger_1.ApiProperty)({
|
|
43
|
+
type: "object",
|
|
44
|
+
description: "Tool validation schema",
|
|
45
|
+
nullable: true,
|
|
46
|
+
additionalProperties: false,
|
|
47
|
+
}),
|
|
48
|
+
__metadata("design:type", Object)
|
|
49
|
+
], McpPromptDto.prototype, "inputSchema", void 0);
|