@tsed/platform-mcp 8.28.0 → 8.28.1
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/lib/esm/decorators/resource.js +13 -4
- package/lib/esm/fn/definePrompt.js +2 -18
- package/lib/esm/fn/defineResource.js +6 -1
- package/lib/esm/fn/defineTool.js +0 -18
- package/lib/esm/services/McpServerFactory.js +8 -2
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/decorators/prompt.d.ts +3 -3
- package/lib/types/decorators/resource.d.ts +2 -2
- package/lib/types/fn/definePrompt.d.ts +24 -29
- package/lib/types/fn/defineResource.d.ts +114 -8
- package/lib/types/fn/defineTool.d.ts +12 -222
- package/package.json +8 -7
- package/src/decorators/prompt.ts +5 -5
- package/src/decorators/resource.ts +20 -8
- package/src/decorators/tool.ts +1 -1
- package/src/fn/definePrompt.ts +27 -12
- package/src/fn/defineResource.ts +33 -10
- package/src/fn/defineTool.spec.ts +1 -1
- package/src/fn/defineTool.ts +13 -6
- package/src/services/McpServerFactory.ts +10 -4
|
@@ -21,13 +21,22 @@ import { defineResource } from "../fn/defineResource.js";
|
|
|
21
21
|
*/
|
|
22
22
|
export function Resource(uriOrTemplate, options) {
|
|
23
23
|
return (target, propertyKey, _) => {
|
|
24
|
-
|
|
24
|
+
const base = {
|
|
25
25
|
...options,
|
|
26
26
|
name: options?.name || String(propertyKey),
|
|
27
27
|
token: classOf(target),
|
|
28
|
-
propertyKey
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
propertyKey
|
|
29
|
+
};
|
|
30
|
+
if (isString(uriOrTemplate)) {
|
|
31
|
+
defineResource({
|
|
32
|
+
...base,
|
|
33
|
+
uri: uriOrTemplate
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
defineResource({
|
|
38
|
+
...base,
|
|
39
|
+
template: uriOrTemplate
|
|
31
40
|
});
|
|
32
41
|
};
|
|
33
42
|
}
|
|
@@ -5,6 +5,7 @@ import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
|
|
|
5
5
|
import { toZod } from "../utils/toZod.js";
|
|
6
6
|
function mapOptions(options) {
|
|
7
7
|
let handler = undefined;
|
|
8
|
+
const name = options.name || ("propertyKey" in options ? String(options.propertyKey) : undefined);
|
|
8
9
|
if ("handler" in options) {
|
|
9
10
|
handler = options.handler;
|
|
10
11
|
}
|
|
@@ -20,28 +21,11 @@ function mapOptions(options) {
|
|
|
20
21
|
}
|
|
21
22
|
return {
|
|
22
23
|
...options,
|
|
24
|
+
name,
|
|
23
25
|
argsSchema: toZod(isArrowFn(options.argsSchema) ? options.argsSchema() : options.argsSchema),
|
|
24
26
|
handler: handler
|
|
25
27
|
};
|
|
26
28
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Registers an MCP prompt provider with the Ts.ED injector and returns the associated token.
|
|
29
|
-
*
|
|
30
|
-
* @typeParam Args JSON payload expected by the prompt.
|
|
31
|
-
* @param options Functional or class-based prompt configuration.
|
|
32
|
-
* @returns The DI token representing the registered prompt provider.
|
|
33
|
-
* @module platform/mcp
|
|
34
|
-
* @since 8.17.0
|
|
35
|
-
*
|
|
36
|
-
* ### Usage
|
|
37
|
-
* ```ts
|
|
38
|
-
* definePrompt({
|
|
39
|
-
* name: "weather",
|
|
40
|
-
* description: "Summaries today's forecast",
|
|
41
|
-
* handler: async () => ({content: [{type: "text", text: "Sunny"}]})
|
|
42
|
-
* });
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
29
|
export function definePrompt(options) {
|
|
46
30
|
const provider = injectable(Symbol.for(`MCP:PROMPT:${options.name}`))
|
|
47
31
|
.type(MCP_PROVIDER_TYPES.PROMPT)
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { inject, injectable } from "@tsed/di";
|
|
2
2
|
import { JsonEntityStore } from "@tsed/schema";
|
|
3
3
|
import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
|
|
4
|
+
function isClassResourceProps(options) {
|
|
5
|
+
return "token" in options && "propertyKey" in options;
|
|
6
|
+
}
|
|
4
7
|
function mapOptions(options) {
|
|
5
8
|
let handler;
|
|
6
|
-
|
|
9
|
+
const name = options.name || ("propertyKey" in options ? String(options.propertyKey) : undefined);
|
|
10
|
+
if (isClassResourceProps(options)) {
|
|
7
11
|
const { token, propertyKey } = options;
|
|
8
12
|
handler = (...args) => {
|
|
9
13
|
const instance = inject(options.token);
|
|
@@ -18,6 +22,7 @@ function mapOptions(options) {
|
|
|
18
22
|
}
|
|
19
23
|
return {
|
|
20
24
|
...options,
|
|
25
|
+
name,
|
|
21
26
|
handler
|
|
22
27
|
};
|
|
23
28
|
}
|
package/lib/esm/fn/defineTool.js
CHANGED
|
@@ -31,24 +31,6 @@ function mapOptions(options) {
|
|
|
31
31
|
handler
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Registers an MCP tool provider and wraps its handler with error logging plus schema conversion.
|
|
36
|
-
*
|
|
37
|
-
* @typeParam Input JSON payload expected by the tool.
|
|
38
|
-
* @typeParam Output Structured output returned by the handler.
|
|
39
|
-
* @param options Functional or class-based tool configuration.
|
|
40
|
-
* @returns The DI token referencing the registered tool provider.
|
|
41
|
-
* @module platform/mcp
|
|
42
|
-
* @since 8.17.0
|
|
43
|
-
*
|
|
44
|
-
* ### Usage
|
|
45
|
-
* ```ts
|
|
46
|
-
* defineTool({
|
|
47
|
-
* name: "add",
|
|
48
|
-
* handler: async ({a, b}) => ({content: [{type: "text", text: String(a + b)}]})
|
|
49
|
-
* });
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
34
|
export function defineTool(options) {
|
|
53
35
|
const provider = injectable(Symbol.for(`MCP:TOOL:${options.name}`))
|
|
54
36
|
.type(MCP_PROVIDER_TYPES.TOOL)
|
|
@@ -33,13 +33,19 @@ export const MCP_SERVER = injectable(McpServer)
|
|
|
33
33
|
resourceTokens.forEach((token) => {
|
|
34
34
|
const definition = inject(token);
|
|
35
35
|
const { name, handler, uri, template, ...opts } = definition;
|
|
36
|
-
|
|
36
|
+
const resourceName = name || String(token);
|
|
37
|
+
if (uri) {
|
|
38
|
+
server.registerResource(resourceName, uri, opts, handler);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
server.registerResource(resourceName, template, opts, handler);
|
|
42
|
+
}
|
|
37
43
|
});
|
|
38
44
|
const promptTokens = collectTokens(MCP_PROVIDER_TYPES.PROMPT, settings.prompts);
|
|
39
45
|
promptTokens.forEach((token) => {
|
|
40
46
|
const definition = inject(token);
|
|
41
47
|
const { name, handler, ...opts } = definition;
|
|
42
|
-
server.registerPrompt(name, opts, handler);
|
|
48
|
+
server.registerPrompt(name || String(token), opts, handler);
|
|
43
49
|
});
|
|
44
50
|
return server;
|
|
45
51
|
})
|