@rekog/mcp-nest 1.1.0 → 1.1.2
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 +44 -80
- package/dist/decorators/tool.decorator.d.ts +7 -7
- package/dist/decorators/tool.decorator.d.ts.map +1 -1
- package/dist/decorators/tool.decorator.js +2 -2
- package/dist/decorators/tool.decorator.js.map +1 -1
- package/dist/services/mcp-tools.discovery.d.ts +18 -3
- package/dist/services/mcp-tools.discovery.d.ts.map +1 -1
- package/dist/services/mcp-tools.discovery.js +112 -24
- package/dist/services/mcp-tools.discovery.js.map +1 -1
- package/package.json +1 -1
- package/tests/mcp.e2e.spec.ts +80 -114
- package/tsconfig.tsbuildinfo +1 -1
- package/.rinorism/index.d.ts +0 -1
- package/coverage/clover.xml +0 -151
- package/coverage/coverage-final.json +0 -9
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -176
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -267
- package/dist/mcp.module.spec.d.ts +0 -13
- package/dist/mcp.module.spec.d.ts.map +0 -1
- package/dist/mcp.module.spec.js +0 -87
- package/dist/mcp.module.spec.js.map +0 -1
package/README.md
CHANGED
|
@@ -45,54 +45,37 @@ export class AppModule {}
|
|
|
45
45
|
import { Injectable } from '@nestjs/common';
|
|
46
46
|
import { Tool } from '@rekog/mcp-nest';
|
|
47
47
|
import { z } from 'zod';
|
|
48
|
-
import {
|
|
49
|
-
|
|
50
|
-
const ProgressRequestSchema = RequestSchema.extend({
|
|
51
|
-
method: z.literal('progress/request'),
|
|
52
|
-
params: z.object({
|
|
53
|
-
_meta: z.object({
|
|
54
|
-
progressToken: z.union([z.string(), z.number().int()]).optional(),
|
|
55
|
-
}).optional(),
|
|
56
|
-
}).optional(),
|
|
57
|
-
});
|
|
48
|
+
import { Context } from '@rekog/mcp-nest/dist/services/mcp-tools.discovery';
|
|
49
|
+
import { Progress } from "@modelcontextprotocol/sdk/types.js";
|
|
58
50
|
|
|
59
51
|
@Injectable()
|
|
60
52
|
export class GreetingTool {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
53
|
+
constructor() {}
|
|
54
|
+
|
|
55
|
+
@Tool({
|
|
56
|
+
name: 'hello-world',
|
|
57
|
+
description: 'Returns a greeting and simulates a long operation with progress updates',
|
|
58
|
+
parameters: z.object({
|
|
59
|
+
name: z.string().default('World'),
|
|
60
|
+
}),
|
|
65
61
|
})
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
content: [{ type: 'text', text: `Hello ${name}!` }]
|
|
69
|
-
};
|
|
70
|
-
}
|
|
62
|
+
async sayHello({ name }, context: Context) {
|
|
71
63
|
|
|
72
|
-
|
|
73
|
-
requestSchema: ProgressRequestSchema,
|
|
74
|
-
})
|
|
75
|
-
async progressTest(params, context) {
|
|
76
|
-
const progressToken = params._meta?.progressToken;
|
|
64
|
+
const greeting = `Hello, ${name}!`;
|
|
77
65
|
|
|
78
|
-
|
|
66
|
+
const totalSteps = 5;
|
|
67
|
+
for (let i = 0; i < totalSteps; i++) {
|
|
79
68
|
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
progress: i,
|
|
87
|
-
total: 5,
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
console.log(`Sent progress: \${i}/5`);
|
|
91
|
-
}
|
|
70
|
+
// Send a progress update.
|
|
71
|
+
await context.reportProgress({
|
|
72
|
+
progress: (i + 1) * 20,
|
|
73
|
+
total: 100,
|
|
74
|
+
} as Progress);
|
|
92
75
|
}
|
|
93
76
|
|
|
94
77
|
return {
|
|
95
|
-
|
|
78
|
+
content: [{ type: 'text', text: greeting }]
|
|
96
79
|
};
|
|
97
80
|
}
|
|
98
81
|
}
|
|
@@ -101,6 +84,7 @@ export class GreetingTool {
|
|
|
101
84
|
### 3. Start Server
|
|
102
85
|
|
|
103
86
|
```typescript
|
|
87
|
+
// main.ts
|
|
104
88
|
import { NestFactory } from '@nestjs/core';
|
|
105
89
|
import { AppModule } from './app.module';
|
|
106
90
|
|
|
@@ -118,6 +102,7 @@ Clients can connect using the MCP SDK:
|
|
|
118
102
|
```typescript
|
|
119
103
|
import { Client } from '@modelcontextprotocol/sdk/client';
|
|
120
104
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse';
|
|
105
|
+
import { z } from 'zod';
|
|
121
106
|
|
|
122
107
|
const client = new Client(
|
|
123
108
|
{ name: 'client-name', version: '1.0.0' },
|
|
@@ -128,29 +113,25 @@ await client.connect(
|
|
|
128
113
|
new SSEClientTransport(new URL('<http://localhost:3000/sse>'))
|
|
129
114
|
);
|
|
130
115
|
|
|
131
|
-
// Execute tool
|
|
132
|
-
const
|
|
133
|
-
name: 'hello',
|
|
134
|
-
arguments: { name: 'World' }
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// Execute tool with request schema and receive progress notifications
|
|
138
|
-
const progressResult = await client.request(
|
|
116
|
+
// Execute the 'hello-world' tool with progress tracking
|
|
117
|
+
const greetResult = await client.callTool(
|
|
139
118
|
{
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
progressToken: 'test-token',
|
|
144
|
-
},
|
|
119
|
+
name: 'hello-world',
|
|
120
|
+
arguments: {
|
|
121
|
+
name: 'MCP User',
|
|
145
122
|
},
|
|
146
123
|
},
|
|
147
|
-
|
|
124
|
+
undefined, // responseSchema is optional, or you can define a Zod schema here
|
|
148
125
|
{
|
|
149
126
|
onprogress: (progress) => {
|
|
150
|
-
console.log(
|
|
127
|
+
console.log(
|
|
128
|
+
`Progress: ${progress.progress}/${progress.total}`
|
|
129
|
+
);
|
|
151
130
|
},
|
|
152
131
|
},
|
|
153
132
|
);
|
|
133
|
+
|
|
134
|
+
console.log(greetResult.content[0].text); // Output: Hello MCP User! I'm Test User from Test Org.
|
|
154
135
|
```
|
|
155
136
|
|
|
156
137
|
## API Endpoints
|
|
@@ -162,40 +143,23 @@ const progressResult = await client.request(
|
|
|
162
143
|
|
|
163
144
|
### `McpOptions`
|
|
164
145
|
|
|
165
|
-
| Property
|
|
166
|
-
|
|
167
|
-
| `name`
|
|
168
|
-
| `version`
|
|
169
|
-
| `capabilities`
|
|
170
|
-
| `sseEndpoint`
|
|
171
|
-
| `messagesEndpoint`
|
|
172
|
-
| `globalApiPrefix`
|
|
146
|
+
| Property | Type | Description | Default Value |
|
|
147
|
+
|----------------------|---------------------------|-----------------------------------------------------------------------------|---------------|
|
|
148
|
+
| `name` | string | Server name | - |
|
|
149
|
+
| `version` | string | Server version | - |
|
|
150
|
+
| `capabilities` | Record<string, any> | Server capabilities, defines what the server can do. | `{}` |
|
|
151
|
+
| `sseEndpoint` | string (optional) | Endpoint for SSE connections. | `'sse'` |
|
|
152
|
+
| `messagesEndpoint` | string (optional) | Endpoint for handling tool execution. | `'messages'` |
|
|
153
|
+
| `globalApiPrefix` | string (optional) | Global API prefix for all endpoints. | `''` |
|
|
173
154
|
|
|
174
155
|
### Tool Decorator
|
|
175
156
|
|
|
176
157
|
The `@Tool` decorator is used to define a method as an MCP tool.
|
|
177
158
|
|
|
178
159
|
```typescript
|
|
179
|
-
@Tool(name: string, description: string,
|
|
160
|
+
@Tool({ name: string, description: string, parameters?: z.ZodObject<any> })
|
|
180
161
|
```
|
|
181
162
|
|
|
182
|
-
- `name`: The name of the tool.
|
|
163
|
+
- `name`: The name of the tool. This will be used to list it in the `listTools` request.
|
|
183
164
|
- `description`: A description of the tool.
|
|
184
|
-
- `
|
|
185
|
-
- `options.requestSchema`: (Optional) A Zod schema extending the base `RequestSchema` to validate the entire request structure, including method name and metadata.
|
|
186
|
-
|
|
187
|
-
### Context Object
|
|
188
|
-
|
|
189
|
-
When defining a tool, you can access a context object passed as the second argument to the tool method. This object provides methods for sending notifications, errors, and responses.
|
|
190
|
-
|
|
191
|
-
```typescript
|
|
192
|
-
{
|
|
193
|
-
sendNotification: async (notification: any) => { ... },
|
|
194
|
-
sendError: async (message: string, data?: any) => { ... },
|
|
195
|
-
sendResponse: async (response: any) => { ... }
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
- `sendNotification`: Sends a notification to the client.
|
|
200
|
-
- `sendError`: Sends an error response to the client.
|
|
201
|
-
- `sendResponse`: Sends a successful response to the client.
|
|
165
|
+
- `parameters`: (Optional) A Zod schema defining the expected structure of the tool's input arguments.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { z } from
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
export interface ToolMetadata {
|
|
3
3
|
name: string;
|
|
4
4
|
description: string;
|
|
5
|
-
|
|
6
|
-
requestSchema?: z.ZodObject<any>;
|
|
5
|
+
parameters?: z.ZodTypeAny;
|
|
7
6
|
}
|
|
8
|
-
export declare const Tool: (name
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
export declare const Tool: ({ name, description, parameters, }: {
|
|
8
|
+
name: string;
|
|
9
|
+
description: string;
|
|
10
|
+
parameters?: z.ZodTypeAny;
|
|
11
|
+
}) => import("@nestjs/common").CustomDecorator<string>;
|
|
12
12
|
//# sourceMappingURL=tool.decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"tool.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC;CAC3B;AAED,eAAO,MAAM,IAAI,uCAId;IACD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC;CAC3B,qDAMA,CAAC"}
|
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Tool = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const constants_1 = require("./constants");
|
|
6
|
-
const Tool = (name, description,
|
|
6
|
+
const Tool = ({ name, description, parameters, }) => {
|
|
7
7
|
return (0, common_1.SetMetadata)(constants_1.MCP_TOOL_METADATA_KEY, {
|
|
8
8
|
name,
|
|
9
9
|
description,
|
|
10
|
-
|
|
10
|
+
parameters,
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
exports.Tool = Tool;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.decorator.js","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,2CAAoD;
|
|
1
|
+
{"version":3,"file":"tool.decorator.js","sourceRoot":"","sources":["../../src/decorators/tool.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,2CAAoD;AAS7C,MAAM,IAAI,GAAG,CAAC,EACnB,IAAI,EACJ,WAAW,EACX,UAAU,GAKX,EAAE,EAAE;IACH,OAAO,IAAA,oBAAW,EAAC,iCAAqB,EAAE;QACxC,IAAI;QACJ,WAAW;QACX,UAAU;KACX,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,IAAI,QAcf"}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import { McpServer } from
|
|
2
|
-
import { OnApplicationBootstrap } from
|
|
3
|
-
import { DiscoveryService, MetadataScanner } from
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { OnApplicationBootstrap } from "@nestjs/common";
|
|
3
|
+
import { DiscoveryService, MetadataScanner } from "@nestjs/core";
|
|
4
|
+
import { Progress } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
export type Context = {
|
|
6
|
+
reportProgress: (progress: Progress) => Promise<void>;
|
|
7
|
+
log: {
|
|
8
|
+
debug: (message: string, data?: SerializableValue) => void;
|
|
9
|
+
error: (message: string, data?: SerializableValue) => void;
|
|
10
|
+
info: (message: string, data?: SerializableValue) => void;
|
|
11
|
+
warn: (message: string, data?: SerializableValue) => void;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
type Literal = boolean | null | number | string | undefined;
|
|
15
|
+
type SerializableValue = Literal | SerializableValue[] | {
|
|
16
|
+
[key: string]: SerializableValue;
|
|
17
|
+
};
|
|
4
18
|
export declare class McpToolsDiscovery implements OnApplicationBootstrap {
|
|
5
19
|
private readonly discovery;
|
|
6
20
|
private readonly metadataScanner;
|
|
@@ -11,4 +25,5 @@ export declare class McpToolsDiscovery implements OnApplicationBootstrap {
|
|
|
11
25
|
registerTools(mcpServer: McpServer): void;
|
|
12
26
|
private createContext;
|
|
13
27
|
}
|
|
28
|
+
export {};
|
|
14
29
|
//# sourceMappingURL=mcp-tools.discovery.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tools.discovery.d.ts","sourceRoot":"","sources":["../../src/services/mcp-tools.discovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAc,sBAAsB,EAAE,MAAM,gBAAgB,C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;IARlC,OAAO,CAAC,KAAK,CAIL;gBAGW,SAAS,EAAE,gBAAgB,EAC3B,eAAe,EAAE,eAAe;IAGnD,sBAAsB;IAItB,YAAY;IA8BZ,aAAa,CAAC,SAAS,EAAE,SAAS;IA6ElC,OAAO,CAAC,aAAa;CA0CtB"}
|
|
@@ -13,6 +13,30 @@ exports.McpToolsDiscovery = void 0;
|
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const decorators_1 = require("../decorators");
|
|
16
|
+
const zod_1 = require("zod");
|
|
17
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
18
|
+
const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
|
|
19
|
+
const TextContentZodSchema = zod_1.z
|
|
20
|
+
.object({
|
|
21
|
+
type: zod_1.z.literal("text"),
|
|
22
|
+
text: zod_1.z.string(),
|
|
23
|
+
})
|
|
24
|
+
.strict();
|
|
25
|
+
const ContentZodSchema = zod_1.z.discriminatedUnion("type", [
|
|
26
|
+
TextContentZodSchema,
|
|
27
|
+
]);
|
|
28
|
+
const ContentResultZodSchema = zod_1.z
|
|
29
|
+
.object({
|
|
30
|
+
content: ContentZodSchema.array(),
|
|
31
|
+
isError: zod_1.z.boolean().optional(),
|
|
32
|
+
})
|
|
33
|
+
.strict();
|
|
34
|
+
class UserError extends Error {
|
|
35
|
+
constructor(message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.name = 'UserError';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
16
40
|
let McpToolsDiscovery = class McpToolsDiscovery {
|
|
17
41
|
constructor(discovery, metadataScanner) {
|
|
18
42
|
this.discovery = discovery;
|
|
@@ -48,40 +72,104 @@ let McpToolsDiscovery = class McpToolsDiscovery {
|
|
|
48
72
|
});
|
|
49
73
|
}
|
|
50
74
|
registerTools(mcpServer) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
75
|
+
mcpServer.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
|
|
76
|
+
let tools = this.tools.map((tool) => ({
|
|
77
|
+
name: tool.metadata.name,
|
|
78
|
+
description: tool.metadata.description,
|
|
79
|
+
inputSchema: tool.metadata.parameters
|
|
80
|
+
? (0, zod_to_json_schema_1.zodToJsonSchema)(tool.metadata.parameters)
|
|
81
|
+
: undefined,
|
|
82
|
+
}));
|
|
83
|
+
return {
|
|
84
|
+
tools
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
mcpServer.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
88
|
+
const tool = this.tools.find((tool) => tool.metadata.name === request.params.name);
|
|
89
|
+
if (!tool) {
|
|
90
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}`);
|
|
91
|
+
}
|
|
92
|
+
const schema = tool.metadata.parameters;
|
|
93
|
+
let parsedParams = request.params.arguments;
|
|
94
|
+
if (schema && schema instanceof zod_1.z.ZodType) {
|
|
95
|
+
const result = schema.safeParse(request.params.arguments);
|
|
96
|
+
if (!result.success) {
|
|
97
|
+
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, `Invalid ${request.params.name} parameters: ${JSON.stringify(result.error.format())}`);
|
|
98
|
+
}
|
|
99
|
+
parsedParams = result.data;
|
|
100
|
+
}
|
|
101
|
+
const progressToken = request.params?._meta?.progressToken;
|
|
102
|
+
try {
|
|
103
|
+
const context = this.createContext(mcpServer, progressToken);
|
|
104
|
+
const result = await tool.instance[tool.methodName].call(tool.instance, parsedParams, context);
|
|
105
|
+
if (typeof result === "string") {
|
|
106
|
+
return ContentResultZodSchema.parse({
|
|
107
|
+
content: [{ type: "text", text: result }],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
else if (result && typeof result === "object" && "type" in result) {
|
|
111
|
+
return ContentResultZodSchema.parse({
|
|
112
|
+
content: [result],
|
|
113
|
+
});
|
|
61
114
|
}
|
|
62
115
|
else {
|
|
63
|
-
return
|
|
116
|
+
return ContentResultZodSchema.parse(result);
|
|
64
117
|
}
|
|
65
|
-
};
|
|
66
|
-
if (tool.metadata.requestSchema) {
|
|
67
|
-
mcpServer.server.setRequestHandler(tool.metadata.requestSchema, handler);
|
|
68
118
|
}
|
|
69
|
-
|
|
70
|
-
|
|
119
|
+
catch (error) {
|
|
120
|
+
if (error instanceof UserError) {
|
|
121
|
+
return {
|
|
122
|
+
content: [{ type: "text", text: error.message }],
|
|
123
|
+
isError: true,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
content: [{ type: "text", text: `Error: ${error}` }],
|
|
128
|
+
isError: true,
|
|
129
|
+
};
|
|
71
130
|
}
|
|
72
131
|
});
|
|
73
132
|
}
|
|
74
|
-
createContext(mcpServer,
|
|
133
|
+
createContext(mcpServer, progressToken) {
|
|
75
134
|
return {
|
|
76
|
-
|
|
77
|
-
|
|
135
|
+
reportProgress: async (progress) => {
|
|
136
|
+
if (progressToken) {
|
|
137
|
+
console.log("Reporting progress", progress);
|
|
138
|
+
await mcpServer.server.notification({
|
|
139
|
+
method: "notifications/progress",
|
|
140
|
+
params: {
|
|
141
|
+
...progress,
|
|
142
|
+
progressToken,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
78
146
|
},
|
|
79
|
-
|
|
80
|
-
|
|
147
|
+
log: {
|
|
148
|
+
debug: (message, context) => {
|
|
149
|
+
mcpServer.server.sendLoggingMessage({
|
|
150
|
+
level: "debug",
|
|
151
|
+
data: { message, context },
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
error: (message, context) => {
|
|
155
|
+
mcpServer.server.sendLoggingMessage({
|
|
156
|
+
level: "error",
|
|
157
|
+
data: { message, context },
|
|
158
|
+
});
|
|
159
|
+
},
|
|
160
|
+
info: (message, context) => {
|
|
161
|
+
mcpServer.server.sendLoggingMessage({
|
|
162
|
+
level: "info",
|
|
163
|
+
data: { message, context },
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
warn: (message, context) => {
|
|
167
|
+
mcpServer.server.sendLoggingMessage({
|
|
168
|
+
level: "warning",
|
|
169
|
+
data: { message, context },
|
|
170
|
+
});
|
|
171
|
+
},
|
|
81
172
|
},
|
|
82
|
-
sendResponse: async (response) => {
|
|
83
|
-
await extra.send(response);
|
|
84
|
-
}
|
|
85
173
|
};
|
|
86
174
|
}
|
|
87
175
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-tools.discovery.js","sourceRoot":"","sources":["../../src/services/mcp-tools.discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAAoE;AACpE,uCAAiE;AACjE,8CAAoE;
|
|
1
|
+
{"version":3,"file":"mcp-tools.discovery.js","sourceRoot":"","sources":["../../src/services/mcp-tools.discovery.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2CAAoE;AACpE,uCAAiE;AACjE,8CAAoE;AACpE,6BAAwB;AACxB,2DAAqD;AACrD,iEAAkI;AAwBlI,MAAM,oBAAoB,GAAG,OAAC;KAC3B,MAAM,CAAC;IACN,IAAI,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IAIvB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;CACjB,CAAC;KACD,MAAM,EAAmC,CAAC;AAG7C,MAAM,gBAAgB,GAAG,OAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACpD,oBAAoB;CACrB,CAA8B,CAAC;AAOhC,MAAM,sBAAsB,GAAG,OAAC;KAC7B,MAAM,CAAC;IACN,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE;IACjC,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CAChC,CAAC;KACD,MAAM,EAAqC,CAAC;AAE/C,MAAM,SAAU,SAAQ,KAA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