@muzikanto/nestjs-mcp 1.1.1 → 1.2.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 +6 -0
- package/README.md +73 -32
- 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/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 +20 -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 +27 -0
- package/dist/mcp-server/mcp.controller.js +181 -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 +8 -0
- package/dist/mcp-server/mcp.module.js +45 -0
- package/dist/mcp-server/mcp.service.d.ts +59 -0
- package/dist/mcp-server/mcp.service.js +193 -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.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/zod.d.ts +1 -0
- package/dist/mcp-server/utils/zod.js +29 -0
- package/package.json +6 -2
package/CHANGELOG.md
CHANGED
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,10 +30,11 @@ 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)
|
|
37
39
|
- Full TypeScript typing
|
|
38
40
|
|
|
@@ -71,6 +73,12 @@ export class AppModule {}
|
|
|
71
73
|
```ts
|
|
72
74
|
import { IMcpTool, McpTool } from '@muzikanto/nestjs-mcp';
|
|
73
75
|
import { Telegraf } from 'telegraf';
|
|
76
|
+
import z from 'zod';
|
|
77
|
+
|
|
78
|
+
const schema = {
|
|
79
|
+
chatId: z.string().describe('Telegram chat id'), // строка с описанием
|
|
80
|
+
text: z.string().describe('Message text'), // строка с описанием
|
|
81
|
+
};
|
|
74
82
|
|
|
75
83
|
@McpTool()
|
|
76
84
|
export class TelegramSendMessageTool implements IMcpTool<
|
|
@@ -79,20 +87,7 @@ export class TelegramSendMessageTool implements IMcpTool<
|
|
|
79
87
|
> {
|
|
80
88
|
name = 'telegram.sendMessage';
|
|
81
89
|
|
|
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
|
-
};
|
|
90
|
+
inputSchema = schema;
|
|
96
91
|
|
|
97
92
|
constructor(private readonly bot: Telegraf) {}
|
|
98
93
|
|
|
@@ -136,14 +131,21 @@ GET /mcp/tool
|
|
|
136
131
|
"name": "telegram.sendMessage",
|
|
137
132
|
"description": "Sent message via Telegram",
|
|
138
133
|
"inputSchema": {
|
|
139
|
-
"
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
"type": "object",
|
|
135
|
+
"properties": {
|
|
136
|
+
"chatId": {
|
|
137
|
+
"type": "number",
|
|
138
|
+
"description": "Telegram chat ID"
|
|
139
|
+
},
|
|
140
|
+
"text": {
|
|
141
|
+
"type": "string",
|
|
142
|
+
"description": "Message text"
|
|
143
|
+
}
|
|
142
144
|
},
|
|
143
|
-
"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
"required": [
|
|
146
|
+
"chatId",
|
|
147
|
+
"text"
|
|
148
|
+
]
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
]
|
|
@@ -153,11 +155,18 @@ GET /mcp/tool
|
|
|
153
155
|
|
|
154
156
|
```ts
|
|
155
157
|
import { IMcpPrompt, McpPrompt } from '@muzikanto/nestjs-mcp';
|
|
158
|
+
import z from 'zod';
|
|
159
|
+
|
|
160
|
+
const schema = {
|
|
161
|
+
chatId: z.string().describe('Telegram chat id'), // строка с описанием
|
|
162
|
+
text: z.string().describe('Message text'), // строка с описанием
|
|
163
|
+
};
|
|
156
164
|
|
|
157
165
|
@McpPrompt()
|
|
158
166
|
export class TelegramAutoReplyPrompt implements IMcpPrompt<{ text: string; chatId: number; }> {
|
|
159
167
|
name = 'telegram_auto_reply';
|
|
160
168
|
description = 'Generate a short, fiendly reply to an incoming Telegram message and send it back to the same chat using teegram.sendMessage tool';
|
|
169
|
+
schema = schema;
|
|
161
170
|
|
|
162
171
|
async execute({ text, chatId }: { text: string; chatId: number }) {
|
|
163
172
|
return [
|
|
@@ -192,12 +201,29 @@ GET /mcp/prompts
|
|
|
192
201
|
[
|
|
193
202
|
{
|
|
194
203
|
"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"
|
|
204
|
+
"description": "Generate a short, fiendly reply to an incoming Telegram message and send it back to the same chat using teegram.sendMessage tool",
|
|
205
|
+
"inputSchema": {
|
|
206
|
+
"type": "object",
|
|
207
|
+
"properties": {
|
|
208
|
+
"chatId": {
|
|
209
|
+
"type": "number",
|
|
210
|
+
"description": "Telegram chat ID"
|
|
211
|
+
},
|
|
212
|
+
"text": {
|
|
213
|
+
"type": "string",
|
|
214
|
+
"description": "Message text"
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"required": [
|
|
218
|
+
"chatId",
|
|
219
|
+
"text"
|
|
220
|
+
]
|
|
221
|
+
}
|
|
196
222
|
}
|
|
197
223
|
]
|
|
198
224
|
```
|
|
199
225
|
|
|
200
|
-
###
|
|
226
|
+
### Calling MCP prompt via HTTP
|
|
201
227
|
|
|
202
228
|
POST /mcp/prompts/telegram_auto_reply
|
|
203
229
|
|
|
@@ -234,6 +260,24 @@ Response
|
|
|
234
260
|
}
|
|
235
261
|
```
|
|
236
262
|
|
|
263
|
+
### Create MCP resource
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
import { IMcpResource, McpResource } from '@muzikanto/nestjs-mcp';
|
|
267
|
+
|
|
268
|
+
@McpResource()
|
|
269
|
+
export class TestResource implements IMcpResource<{ userId: string }> {
|
|
270
|
+
name = 'users.get';
|
|
271
|
+
uri = 'users://{userId}';
|
|
272
|
+
title = 'Get test user';
|
|
273
|
+
description = 'Get user by id';
|
|
274
|
+
|
|
275
|
+
async execute(url: URL, vars: { userId: string }) {
|
|
276
|
+
return [{ uri: url.href, text: `Hello ${vars.userId}` }];
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
```
|
|
280
|
+
|
|
237
281
|
### Auth guard
|
|
238
282
|
```ts
|
|
239
283
|
import { McpModule } from '@muzikanto/nestjs-mcp';
|
|
@@ -265,7 +309,6 @@ export class AppModule {}
|
|
|
265
309
|
import axios from 'axios';
|
|
266
310
|
import OpenAI from 'openai';
|
|
267
311
|
|
|
268
|
-
const MCP_URL = 'http://localhost:3000/mcp';
|
|
269
312
|
const MCP_TOOLS_URL = 'http://localhost:3000/mcp/tools';
|
|
270
313
|
const MCP_TELEGRAM_PROMPT_URL = 'http://localhost:3000/mcp/prompts/telegram_auto_reply';
|
|
271
314
|
|
|
@@ -277,7 +320,7 @@ const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
|
277
320
|
*/
|
|
278
321
|
async function getMcpTools() {
|
|
279
322
|
const response = await axios.get(MCP_TOOLS_URL);
|
|
280
|
-
return response.data;
|
|
323
|
+
return response.data.tools.map(el => ({ name: el.name, description: el.description, parameters: el.inputSchema }));
|
|
281
324
|
}
|
|
282
325
|
|
|
283
326
|
/**
|
|
@@ -286,16 +329,14 @@ async function getMcpTools() {
|
|
|
286
329
|
async function getMcpPrompt() {
|
|
287
330
|
const response = await axios.post(MCP_TELEGRAM_PROMPT_URL, {/* propmpt generation arguments */});
|
|
288
331
|
return response.data;
|
|
289
|
-
}
|
|
290
332
|
|
|
291
333
|
/**
|
|
292
334
|
* Request mcp tool
|
|
293
335
|
*/
|
|
294
336
|
async function callMcpTool(toolName: string, payload: Record<string, any>) {
|
|
295
337
|
const response = await axios.post(
|
|
296
|
-
|
|
338
|
+
MCP_TOOLS_URL,
|
|
297
339
|
{ type: toolName, payload },
|
|
298
|
-
{ headers: { 'Content-Type': 'application/json' } }
|
|
299
340
|
);
|
|
300
341
|
return response.data;
|
|
301
342
|
}
|
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,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,20 @@
|
|
|
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 IMcpToolContext = {
|
|
6
|
+
request: any;
|
|
7
|
+
};
|
|
8
|
+
export interface IMcpTool<Payload = any, Result = any> {
|
|
9
|
+
name: string;
|
|
10
|
+
title?: string;
|
|
11
|
+
description?: string;
|
|
12
|
+
inputSchema?: ZodRawShapeCompat;
|
|
13
|
+
execute(input: Payload, context: IMcpToolContext): Promise<Result>;
|
|
14
|
+
}
|
|
15
|
+
export declare const MCP_TOOL_METADATA = "mcp:tool-class";
|
|
16
|
+
/**
|
|
17
|
+
* Декоратор класса для MCP тулзы
|
|
18
|
+
*/
|
|
19
|
+
export declare const McpTool: () => (target: any) => void;
|
|
20
|
+
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);
|
|
@@ -0,0 +1,40 @@
|
|
|
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.McpPromptMessageDto = void 0;
|
|
13
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
+
class McpPromptMessageDto {
|
|
15
|
+
role;
|
|
16
|
+
content;
|
|
17
|
+
tool_call;
|
|
18
|
+
}
|
|
19
|
+
exports.McpPromptMessageDto = McpPromptMessageDto;
|
|
20
|
+
__decorate([
|
|
21
|
+
(0, swagger_1.ApiProperty)({ type: "string", description: "AI role" }),
|
|
22
|
+
__metadata("design:type", String)
|
|
23
|
+
], McpPromptMessageDto.prototype, "role", void 0);
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, swagger_1.ApiProperty)({
|
|
26
|
+
type: "string",
|
|
27
|
+
description: "Request ai message",
|
|
28
|
+
nullable: true,
|
|
29
|
+
}),
|
|
30
|
+
__metadata("design:type", String)
|
|
31
|
+
], McpPromptMessageDto.prototype, "content", void 0);
|
|
32
|
+
__decorate([
|
|
33
|
+
(0, swagger_1.ApiProperty)({
|
|
34
|
+
type: "object",
|
|
35
|
+
description: "Tool call context",
|
|
36
|
+
nullable: true,
|
|
37
|
+
additionalProperties: false,
|
|
38
|
+
}),
|
|
39
|
+
__metadata("design:type", Object)
|
|
40
|
+
], McpPromptMessageDto.prototype, "tool_call", void 0);
|