@tsed/platform-mcp 8.26.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/lib/esm/constants/constants.js +11 -0
- package/lib/esm/decorators/prompt.js +29 -0
- package/lib/esm/decorators/resource.js +33 -0
- package/lib/esm/decorators/tool.js +32 -0
- package/lib/esm/fn/definePrompt.js +52 -0
- package/lib/esm/fn/defineResource.js +31 -0
- package/lib/esm/fn/defineTool.js +85 -0
- package/lib/esm/index.js +40 -0
- package/lib/esm/interfaces/PlatformMcpSettings.js +1 -0
- package/lib/esm/services/McpServerFactory.js +46 -0
- package/lib/esm/services/PlatformMcpModule.js +54 -0
- package/lib/esm/utils/json-schema-to-zod/Types.js +1 -0
- package/lib/esm/utils/json-schema-to-zod/cli.js +83 -0
- package/lib/esm/utils/json-schema-to-zod/index.js +25 -0
- package/lib/esm/utils/json-schema-to-zod/jsonSchemaToZod.js +52 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseAllOf.js +43 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseAnyOf.js +17 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseArray.js +22 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseBoolean.js +9 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseConst.js +9 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseDefault.js +9 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseEnum.js +21 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseIfThenElse.js +26 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseMultipleType.js +10 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNot.js +13 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNull.js +9 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNullable.js +11 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseNumber.js +52 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseObject.js +177 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseOneOf.js +40 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseSchema.js +153 -0
- package/lib/esm/utils/json-schema-to-zod/parsers/parseString.js +63 -0
- package/lib/esm/utils/json-schema-to-zod/utils/cliTools.js +126 -0
- package/lib/esm/utils/json-schema-to-zod/utils/half.js +9 -0
- package/lib/esm/utils/json-schema-to-zod/utils/jsdocs.js +24 -0
- package/lib/esm/utils/json-schema-to-zod/utils/omit.js +12 -0
- package/lib/esm/utils/json-schema-to-zod/utils/withMessage.js +28 -0
- package/lib/esm/utils/toZod.js +17 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -0
- package/lib/types/constants/constants.d.ts +11 -0
- package/lib/types/decorators/prompt.d.ts +26 -0
- package/lib/types/decorators/resource.d.ts +28 -0
- package/lib/types/decorators/tool.d.ts +22 -0
- package/lib/types/fn/definePrompt.d.ts +78 -0
- package/lib/types/fn/defineResource.d.ts +41 -0
- package/lib/types/fn/defineTool.d.ts +284 -0
- package/lib/types/index.d.ts +40 -0
- package/lib/types/interfaces/PlatformMcpSettings.d.ts +43 -0
- package/lib/types/services/McpServerFactory.d.ts +15 -0
- package/lib/types/services/PlatformMcpModule.d.ts +22 -0
- package/lib/types/utils/json-schema-to-zod/Types.d.ts +116 -0
- package/lib/types/utils/json-schema-to-zod/cli.d.ts +2 -0
- package/lib/types/utils/json-schema-to-zod/index.d.ts +25 -0
- package/lib/types/utils/json-schema-to-zod/jsonSchemaToZod.d.ts +11 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseAllOf.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseAnyOf.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseArray.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseBoolean.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseConst.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseDefault.d.ts +8 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseEnum.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseIfThenElse.d.ts +12 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseMultipleType.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseNot.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseNull.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseNullable.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseNumber.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseObject.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseOneOf.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseSchema.d.ts +61 -0
- package/lib/types/utils/json-schema-to-zod/parsers/parseString.d.ts +10 -0
- package/lib/types/utils/json-schema-to-zod/utils/cliTools.d.ts +67 -0
- package/lib/types/utils/json-schema-to-zod/utils/half.d.ts +7 -0
- package/lib/types/utils/json-schema-to-zod/utils/jsdocs.d.ts +15 -0
- package/lib/types/utils/json-schema-to-zod/utils/omit.d.ts +7 -0
- package/lib/types/utils/json-schema-to-zod/utils/withMessage.d.ts +19 -0
- package/lib/types/utils/toZod.d.ts +10 -0
- package/package.json +69 -0
- package/readme.md +73 -0
- package/src/constants/constants.ts +11 -0
- package/src/decorators/prompt.spec.ts +30 -0
- package/src/decorators/prompt.ts +39 -0
- package/src/decorators/resource.spec.ts +33 -0
- package/src/decorators/resource.ts +44 -0
- package/src/decorators/tool.spec.ts +68 -0
- package/src/decorators/tool.ts +34 -0
- package/src/fn/definePrompt.ts +93 -0
- package/src/fn/defineResource.ts +81 -0
- package/src/fn/defineTool.spec.ts +29 -0
- package/src/fn/defineTool.ts +141 -0
- package/src/index.ts +40 -0
- package/src/interfaces/PlatformMcpSettings.ts +45 -0
- package/src/services/McpServerFactory.ts +69 -0
- package/src/services/PlatformMcpModule.ts +67 -0
- package/src/utils/json-schema-to-zod/Types.ts +123 -0
- package/src/utils/json-schema-to-zod/cli.ts +88 -0
- package/src/utils/json-schema-to-zod/index.ts +26 -0
- package/src/utils/json-schema-to-zod/jsonSchemaToZod.ts +60 -0
- package/src/utils/json-schema-to-zod/parsers/parseAllOf.ts +50 -0
- package/src/utils/json-schema-to-zod/parsers/parseAnyOf.ts +19 -0
- package/src/utils/json-schema-to-zod/parsers/parseArray.ts +28 -0
- package/src/utils/json-schema-to-zod/parsers/parseBoolean.ts +11 -0
- package/src/utils/json-schema-to-zod/parsers/parseConst.ts +11 -0
- package/src/utils/json-schema-to-zod/parsers/parseDefault.ts +11 -0
- package/src/utils/json-schema-to-zod/parsers/parseEnum.ts +20 -0
- package/src/utils/json-schema-to-zod/parsers/parseIfThenElse.ts +35 -0
- package/src/utils/json-schema-to-zod/parsers/parseMultipleType.ts +12 -0
- package/src/utils/json-schema-to-zod/parsers/parseNot.ts +15 -0
- package/src/utils/json-schema-to-zod/parsers/parseNull.ts +11 -0
- package/src/utils/json-schema-to-zod/parsers/parseNullable.ts +13 -0
- package/src/utils/json-schema-to-zod/parsers/parseNumber.ts +56 -0
- package/src/utils/json-schema-to-zod/parsers/parseObject.ts +220 -0
- package/src/utils/json-schema-to-zod/parsers/parseOneOf.ts +44 -0
- package/src/utils/json-schema-to-zod/parsers/parseSchema.ts +190 -0
- package/src/utils/json-schema-to-zod/parsers/parseString.ts +73 -0
- package/src/utils/json-schema-to-zod/utils/cliTools.ts +189 -0
- package/src/utils/json-schema-to-zod/utils/half.ts +9 -0
- package/src/utils/json-schema-to-zod/utils/jsdocs.ts +29 -0
- package/src/utils/json-schema-to-zod/utils/omit.ts +14 -0
- package/src/utils/json-schema-to-zod/utils/withMessage.ts +42 -0
- package/src/utils/toZod.spec.ts +15 -0
- package/src/utils/toZod.ts +20 -0
- package/tsconfig.esm.json +14 -0
- package/vitest.config.mts +36 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider type tokens used to register MCP tools, resources, and prompts with the Ts.ED DI container.
|
|
3
|
+
*
|
|
4
|
+
* @module platform/mcp
|
|
5
|
+
* @since 8.17.0
|
|
6
|
+
*/
|
|
7
|
+
export declare const MCP_PROVIDER_TYPES: {
|
|
8
|
+
readonly TOOL: "mcp:tool";
|
|
9
|
+
readonly RESOURCE: "mcp:resource";
|
|
10
|
+
readonly PROMPT: "mcp:prompt";
|
|
11
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type PromptProps } from "../fn/definePrompt.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options accepted by {@link Prompt} when decorating a class method. Matches {@link PromptProps} minus the handler reference.
|
|
4
|
+
*
|
|
5
|
+
* @module platform/mcp
|
|
6
|
+
* @since 8.17.0
|
|
7
|
+
*/
|
|
8
|
+
export type PromptDecoratorOptions = Omit<PromptProps, "handler">;
|
|
9
|
+
/**
|
|
10
|
+
* Declares a Ts.ED class method as an MCP prompt and registers it through {@link definePrompt}.
|
|
11
|
+
*
|
|
12
|
+
* @param options Optional MCP prompt metadata such as name, description, and args schema.
|
|
13
|
+
* @module platform/mcp
|
|
14
|
+
* @since 8.17.0
|
|
15
|
+
*
|
|
16
|
+
* ### Usage
|
|
17
|
+
* ```ts
|
|
18
|
+
* class ConciergePrompts {
|
|
19
|
+
* @Prompt()
|
|
20
|
+
* async hotelWelcome() {
|
|
21
|
+
* return {content: [{type: "text", text: "Welcome to Ts.ED Hotel!"}]};
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function Prompt(options?: PromptDecoratorOptions): (target: any, propertyKey: string | symbol, _: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type ResourceProps } from "../fn/defineResource.js";
|
|
3
|
+
/**
|
|
4
|
+
* Options accepted by the {@link Resource} decorator beyond the handler binding fields, allowing callers to override metadata.
|
|
5
|
+
*
|
|
6
|
+
* @module platform/mcp
|
|
7
|
+
* @since 8.17.0
|
|
8
|
+
*/
|
|
9
|
+
export type ResourceDecoratorOptions = Omit<ResourceProps, "handler" | "uri" | "template">;
|
|
10
|
+
/**
|
|
11
|
+
* Decorator that turns a class method into an MCP resource backed by either a URI or a full {@link ResourceTemplate}.
|
|
12
|
+
*
|
|
13
|
+
* @param uriOrTemplate Direct URI string or a template describing the resource discovery metadata.
|
|
14
|
+
* @param options Optional overrides for metadata such as name, description, or visibility.
|
|
15
|
+
* @module platform/mcp
|
|
16
|
+
* @since 8.17.0
|
|
17
|
+
*
|
|
18
|
+
* ### Usage
|
|
19
|
+
* ```ts
|
|
20
|
+
* class FileCatalog {
|
|
21
|
+
* @Resource("file:///var/data/catalog")
|
|
22
|
+
* async readCatalog() {
|
|
23
|
+
* return {contents: [{uri: "file:///var/data/catalog/index.json"}]};
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function Resource(uriOrTemplate: string | ResourceTemplate, options?: Partial<ResourceDecoratorOptions>): (target: any, propertyKey: string | symbol, _: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ClassToolProps } from "../fn/defineTool.js";
|
|
2
|
+
/**
|
|
3
|
+
* Decorator that registers a class method as an MCP tool and binds it to the Ts.ED DI container.
|
|
4
|
+
*
|
|
5
|
+
* @typeParam Input JSON payload schema expected by the tool invocation.
|
|
6
|
+
* @typeParam Output Optional structured response returned by the handler.
|
|
7
|
+
* @param name Optional override for the exported tool name; defaults to the method key.
|
|
8
|
+
* @param options Additional {@link ClassToolProps} such as descriptions and schema overrides.
|
|
9
|
+
* @module platform/mcp
|
|
10
|
+
* @since 8.17.0
|
|
11
|
+
*
|
|
12
|
+
* ### Usage
|
|
13
|
+
* ```ts
|
|
14
|
+
* class MathTools {
|
|
15
|
+
* @Tool()
|
|
16
|
+
* async add({a, b}: {a: number; b: number}) {
|
|
17
|
+
* return {content: [{type: "text", text: String(a + b)}]};
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function Tool<Input = any, Output = any>(name?: string, options?: Partial<ClassToolProps<Input, Output>>): (target: any, propertyKey: string | symbol, _: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { McpServer, PromptCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type AbstractType, type Type } from "@tsed/core";
|
|
3
|
+
import { JsonSchema } from "@tsed/schema";
|
|
4
|
+
type BasePromptProps<Args> = Omit<Parameters<McpServer["registerPrompt"]>[1], "argsSchema"> & {
|
|
5
|
+
name: string;
|
|
6
|
+
argsSchema?: Parameters<McpServer["registerPrompt"]>[1]["argsSchema"] | JsonSchema<Args> | (() => JsonSchema<Args>);
|
|
7
|
+
};
|
|
8
|
+
type FnPromptProps<Args extends undefined = any> = BasePromptProps<Args> & {
|
|
9
|
+
handler: PromptCallback<Args>;
|
|
10
|
+
};
|
|
11
|
+
type ClassPromptProps<Args extends undefined = any> = BasePromptProps<Args> & {
|
|
12
|
+
token: Type | AbstractType<any>;
|
|
13
|
+
propertyKey: string | symbol;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Union of prompt configuration accepted by {@link definePrompt}, supporting both functional and class-based handlers.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam Args JSON payload expected by the prompt handler.
|
|
19
|
+
* @module platform/mcp
|
|
20
|
+
* @since 8.17.0
|
|
21
|
+
*/
|
|
22
|
+
export type PromptProps<Args extends undefined = any> = FnPromptProps<Args> | ClassPromptProps<Args>;
|
|
23
|
+
declare function mapOptions<Args extends undefined = any>(options: PromptProps<Args>): {
|
|
24
|
+
argsSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
25
|
+
handler: PromptCallback<Args>;
|
|
26
|
+
description?: string | undefined;
|
|
27
|
+
title?: string | undefined;
|
|
28
|
+
name: string;
|
|
29
|
+
} | {
|
|
30
|
+
argsSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
31
|
+
handler: PromptCallback<Args>;
|
|
32
|
+
description?: string | undefined;
|
|
33
|
+
title?: string | undefined;
|
|
34
|
+
name: string;
|
|
35
|
+
token: Type | AbstractType<any>;
|
|
36
|
+
propertyKey: string | symbol;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Normalized settings registered in the DI container for an MCP prompt.
|
|
40
|
+
*
|
|
41
|
+
* @module platform/mcp
|
|
42
|
+
* @since 8.17.0
|
|
43
|
+
*/
|
|
44
|
+
export type PromptsSettings = ReturnType<typeof mapOptions>;
|
|
45
|
+
/**
|
|
46
|
+
* Registers an MCP prompt provider with the Ts.ED injector and returns the associated token.
|
|
47
|
+
*
|
|
48
|
+
* @typeParam Args JSON payload expected by the prompt.
|
|
49
|
+
* @param options Functional or class-based prompt configuration.
|
|
50
|
+
* @returns The DI token representing the registered prompt provider.
|
|
51
|
+
* @module platform/mcp
|
|
52
|
+
* @since 8.17.0
|
|
53
|
+
*
|
|
54
|
+
* ### Usage
|
|
55
|
+
* ```ts
|
|
56
|
+
* definePrompt({
|
|
57
|
+
* name: "weather",
|
|
58
|
+
* description: "Summaries today's forecast",
|
|
59
|
+
* handler: async () => ({content: [{type: "text", text: "Sunny"}]})
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function definePrompt<Args extends undefined = any>(options: PromptProps<Args>): import("@tsed/di").FactoryTokenProvider<{
|
|
64
|
+
argsSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
65
|
+
handler: PromptCallback<Args>;
|
|
66
|
+
description?: string | undefined;
|
|
67
|
+
title?: string | undefined;
|
|
68
|
+
name: string;
|
|
69
|
+
} | {
|
|
70
|
+
argsSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
71
|
+
handler: PromptCallback<Args>;
|
|
72
|
+
description?: string | undefined;
|
|
73
|
+
title?: string | undefined;
|
|
74
|
+
name: string;
|
|
75
|
+
token: Type | AbstractType<any>;
|
|
76
|
+
propertyKey: string | symbol;
|
|
77
|
+
}>;
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ReadResourceCallback, ResourceMetadata, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type TokenProvider } from "@tsed/di";
|
|
3
|
+
type ResourceBaseProps = ResourceMetadata & {
|
|
4
|
+
name: string;
|
|
5
|
+
handler: ReadResourceCallback;
|
|
6
|
+
token?: TokenProvider;
|
|
7
|
+
propertyKey?: string | symbol;
|
|
8
|
+
};
|
|
9
|
+
type ResourceReadProps = ResourceBaseProps & {
|
|
10
|
+
uri: string;
|
|
11
|
+
};
|
|
12
|
+
type ResourceTemplateProps = ResourceBaseProps & {
|
|
13
|
+
template: ResourceTemplate;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Configuration accepted by {@link defineResource}, supporting either URI-based or template-based resources.
|
|
17
|
+
*
|
|
18
|
+
* @module platform/mcp
|
|
19
|
+
* @since 8.17.0
|
|
20
|
+
*/
|
|
21
|
+
export type ResourceProps = ResourceReadProps | ResourceTemplateProps;
|
|
22
|
+
/**
|
|
23
|
+
* Registers an MCP resource provider with the Ts.ED injector and returns its token.
|
|
24
|
+
*
|
|
25
|
+
* @param options Resource metadata describing either a static URI or a template builder.
|
|
26
|
+
* @returns The DI token referencing the registered resource provider.
|
|
27
|
+
* @module platform/mcp
|
|
28
|
+
* @since 8.17.0
|
|
29
|
+
*
|
|
30
|
+
* ### Usage
|
|
31
|
+
* ```ts
|
|
32
|
+
* defineResource({
|
|
33
|
+
* name: "docs",
|
|
34
|
+
* uri: "file:///var/data/docs",
|
|
35
|
+
* handler: async () => ({contents: [{uri: "file:///var/data/docs/readme.md"}]})
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function defineResource(options: ResourceReadProps): TokenProvider;
|
|
40
|
+
export declare function defineResource(options: ResourceTemplateProps): TokenProvider;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
3
|
+
import type { CallToolResult, ServerNotification, ServerRequest, Tool } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
import { type AbstractType, type Type } from "@tsed/core";
|
|
5
|
+
import { JsonSchema } from "@tsed/schema";
|
|
6
|
+
/**
|
|
7
|
+
* Signature implemented by MCP tool handlers invoked through {@link defineTool}.
|
|
8
|
+
*
|
|
9
|
+
* @typeParam Args JSON payload accepted by the handler.
|
|
10
|
+
* @module platform/mcp
|
|
11
|
+
* @since 8.17.0
|
|
12
|
+
*/
|
|
13
|
+
export type ToolCallback<Args = undefined> = (args: Args, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => CallToolResult | Promise<CallToolResult>;
|
|
14
|
+
type ToolConfig = Parameters<McpServer["registerTool"]>[1];
|
|
15
|
+
type BaseToolProps<Input, Output = undefined> = Omit<ToolConfig, "inputSchema" | "outputSchema"> & {
|
|
16
|
+
inputSchema?: JsonSchema<Input> | (() => JsonSchema<Input>) | Tool["inputSchema"];
|
|
17
|
+
outputSchema?: JsonSchema<Output> | Tool["outputSchema"];
|
|
18
|
+
};
|
|
19
|
+
type FnToolProps<Input, Output = undefined> = BaseToolProps<Input, Output> & {
|
|
20
|
+
name: string;
|
|
21
|
+
handler: ToolCallback<Input>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Configuration accepted when decorating class methods as MCP tools.
|
|
25
|
+
*
|
|
26
|
+
* @module platform/mcp
|
|
27
|
+
* @since 8.17.0
|
|
28
|
+
*/
|
|
29
|
+
export type ClassToolProps<Input, Output = undefined> = BaseToolProps<Input, Output> & {
|
|
30
|
+
name?: string;
|
|
31
|
+
token: Type | AbstractType<any>;
|
|
32
|
+
propertyKey: string | symbol;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Union of functional and class-based tool definitions.
|
|
36
|
+
*
|
|
37
|
+
* @module platform/mcp
|
|
38
|
+
* @since 8.17.0
|
|
39
|
+
*/
|
|
40
|
+
export type ToolProps<Input, Output = undefined> = FnToolProps<Input, Output> | ClassToolProps<Input, Output>;
|
|
41
|
+
/**
|
|
42
|
+
* Registers an MCP tool provider and wraps its handler with error logging plus schema conversion.
|
|
43
|
+
*
|
|
44
|
+
* @typeParam Input JSON payload expected by the tool.
|
|
45
|
+
* @typeParam Output Structured output returned by the handler.
|
|
46
|
+
* @param options Functional or class-based tool configuration.
|
|
47
|
+
* @returns The DI token referencing the registered tool provider.
|
|
48
|
+
* @module platform/mcp
|
|
49
|
+
* @since 8.17.0
|
|
50
|
+
*
|
|
51
|
+
* ### Usage
|
|
52
|
+
* ```ts
|
|
53
|
+
* defineTool({
|
|
54
|
+
* name: "add",
|
|
55
|
+
* handler: async ({a, b}) => ({content: [{type: "text", text: String(a + b)}]})
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function defineTool<Input, Output = undefined>(options: ToolProps<Input, Output>): import("@tsed/di").FactoryTokenProvider<{
|
|
60
|
+
name: string | undefined;
|
|
61
|
+
inputSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
62
|
+
outputSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
63
|
+
handler(args: Input, extra: RequestHandlerExtra<ServerRequest, ServerNotification>): Promise<{
|
|
64
|
+
[x: string]: unknown;
|
|
65
|
+
content: ({
|
|
66
|
+
type: "text";
|
|
67
|
+
text: string;
|
|
68
|
+
annotations?: {
|
|
69
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
70
|
+
priority?: number | undefined;
|
|
71
|
+
lastModified?: string | undefined;
|
|
72
|
+
} | undefined;
|
|
73
|
+
_meta?: {
|
|
74
|
+
[x: string]: unknown;
|
|
75
|
+
} | undefined;
|
|
76
|
+
} | {
|
|
77
|
+
type: "image";
|
|
78
|
+
data: string;
|
|
79
|
+
mimeType: string;
|
|
80
|
+
annotations?: {
|
|
81
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
82
|
+
priority?: number | undefined;
|
|
83
|
+
lastModified?: string | undefined;
|
|
84
|
+
} | undefined;
|
|
85
|
+
_meta?: {
|
|
86
|
+
[x: string]: unknown;
|
|
87
|
+
} | undefined;
|
|
88
|
+
} | {
|
|
89
|
+
type: "audio";
|
|
90
|
+
data: string;
|
|
91
|
+
mimeType: string;
|
|
92
|
+
annotations?: {
|
|
93
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
94
|
+
priority?: number | undefined;
|
|
95
|
+
lastModified?: string | undefined;
|
|
96
|
+
} | undefined;
|
|
97
|
+
_meta?: {
|
|
98
|
+
[x: string]: unknown;
|
|
99
|
+
} | undefined;
|
|
100
|
+
} | {
|
|
101
|
+
uri: string;
|
|
102
|
+
name: string;
|
|
103
|
+
type: "resource_link";
|
|
104
|
+
description?: string | undefined;
|
|
105
|
+
mimeType?: string | undefined;
|
|
106
|
+
size?: number | undefined;
|
|
107
|
+
annotations?: {
|
|
108
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
109
|
+
priority?: number | undefined;
|
|
110
|
+
lastModified?: string | undefined;
|
|
111
|
+
} | undefined;
|
|
112
|
+
_meta?: {
|
|
113
|
+
[x: string]: unknown;
|
|
114
|
+
} | undefined;
|
|
115
|
+
icons?: {
|
|
116
|
+
src: string;
|
|
117
|
+
mimeType?: string | undefined;
|
|
118
|
+
sizes?: string[] | undefined;
|
|
119
|
+
theme?: "light" | "dark" | undefined;
|
|
120
|
+
}[] | undefined;
|
|
121
|
+
title?: string | undefined;
|
|
122
|
+
} | {
|
|
123
|
+
type: "resource";
|
|
124
|
+
resource: {
|
|
125
|
+
uri: string;
|
|
126
|
+
text: string;
|
|
127
|
+
mimeType?: string | undefined;
|
|
128
|
+
_meta?: {
|
|
129
|
+
[x: string]: unknown;
|
|
130
|
+
} | undefined;
|
|
131
|
+
} | {
|
|
132
|
+
uri: string;
|
|
133
|
+
blob: string;
|
|
134
|
+
mimeType?: string | undefined;
|
|
135
|
+
_meta?: {
|
|
136
|
+
[x: string]: unknown;
|
|
137
|
+
} | undefined;
|
|
138
|
+
};
|
|
139
|
+
annotations?: {
|
|
140
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
141
|
+
priority?: number | undefined;
|
|
142
|
+
lastModified?: string | undefined;
|
|
143
|
+
} | undefined;
|
|
144
|
+
_meta?: {
|
|
145
|
+
[x: string]: unknown;
|
|
146
|
+
} | undefined;
|
|
147
|
+
})[];
|
|
148
|
+
_meta?: {
|
|
149
|
+
[x: string]: unknown;
|
|
150
|
+
progressToken?: string | number | undefined;
|
|
151
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
152
|
+
taskId: string;
|
|
153
|
+
} | undefined;
|
|
154
|
+
} | undefined;
|
|
155
|
+
structuredContent?: {
|
|
156
|
+
[x: string]: unknown;
|
|
157
|
+
} | undefined;
|
|
158
|
+
isError?: boolean | undefined;
|
|
159
|
+
} | {
|
|
160
|
+
content: never[];
|
|
161
|
+
structuredContent: {
|
|
162
|
+
code: string;
|
|
163
|
+
message: any;
|
|
164
|
+
};
|
|
165
|
+
}>;
|
|
166
|
+
description?: string | undefined;
|
|
167
|
+
_meta?: Record<string, unknown> | undefined;
|
|
168
|
+
annotations?: import("@modelcontextprotocol/sdk/types.js").ToolAnnotations;
|
|
169
|
+
title?: string | undefined;
|
|
170
|
+
} | {
|
|
171
|
+
name: string | undefined;
|
|
172
|
+
inputSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
173
|
+
outputSchema: import("zod").ZodObject<import("zod/v4/core").$ZodLooseShape, import("zod/v4/core").$strip> | undefined;
|
|
174
|
+
handler(args: Input, extra: RequestHandlerExtra<ServerRequest, ServerNotification>): Promise<{
|
|
175
|
+
[x: string]: unknown;
|
|
176
|
+
content: ({
|
|
177
|
+
type: "text";
|
|
178
|
+
text: string;
|
|
179
|
+
annotations?: {
|
|
180
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
181
|
+
priority?: number | undefined;
|
|
182
|
+
lastModified?: string | undefined;
|
|
183
|
+
} | undefined;
|
|
184
|
+
_meta?: {
|
|
185
|
+
[x: string]: unknown;
|
|
186
|
+
} | undefined;
|
|
187
|
+
} | {
|
|
188
|
+
type: "image";
|
|
189
|
+
data: string;
|
|
190
|
+
mimeType: string;
|
|
191
|
+
annotations?: {
|
|
192
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
193
|
+
priority?: number | undefined;
|
|
194
|
+
lastModified?: string | undefined;
|
|
195
|
+
} | undefined;
|
|
196
|
+
_meta?: {
|
|
197
|
+
[x: string]: unknown;
|
|
198
|
+
} | undefined;
|
|
199
|
+
} | {
|
|
200
|
+
type: "audio";
|
|
201
|
+
data: string;
|
|
202
|
+
mimeType: string;
|
|
203
|
+
annotations?: {
|
|
204
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
205
|
+
priority?: number | undefined;
|
|
206
|
+
lastModified?: string | undefined;
|
|
207
|
+
} | undefined;
|
|
208
|
+
_meta?: {
|
|
209
|
+
[x: string]: unknown;
|
|
210
|
+
} | undefined;
|
|
211
|
+
} | {
|
|
212
|
+
uri: string;
|
|
213
|
+
name: string;
|
|
214
|
+
type: "resource_link";
|
|
215
|
+
description?: string | undefined;
|
|
216
|
+
mimeType?: string | undefined;
|
|
217
|
+
size?: number | undefined;
|
|
218
|
+
annotations?: {
|
|
219
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
220
|
+
priority?: number | undefined;
|
|
221
|
+
lastModified?: string | undefined;
|
|
222
|
+
} | undefined;
|
|
223
|
+
_meta?: {
|
|
224
|
+
[x: string]: unknown;
|
|
225
|
+
} | undefined;
|
|
226
|
+
icons?: {
|
|
227
|
+
src: string;
|
|
228
|
+
mimeType?: string | undefined;
|
|
229
|
+
sizes?: string[] | undefined;
|
|
230
|
+
theme?: "light" | "dark" | undefined;
|
|
231
|
+
}[] | undefined;
|
|
232
|
+
title?: string | undefined;
|
|
233
|
+
} | {
|
|
234
|
+
type: "resource";
|
|
235
|
+
resource: {
|
|
236
|
+
uri: string;
|
|
237
|
+
text: string;
|
|
238
|
+
mimeType?: string | undefined;
|
|
239
|
+
_meta?: {
|
|
240
|
+
[x: string]: unknown;
|
|
241
|
+
} | undefined;
|
|
242
|
+
} | {
|
|
243
|
+
uri: string;
|
|
244
|
+
blob: string;
|
|
245
|
+
mimeType?: string | undefined;
|
|
246
|
+
_meta?: {
|
|
247
|
+
[x: string]: unknown;
|
|
248
|
+
} | undefined;
|
|
249
|
+
};
|
|
250
|
+
annotations?: {
|
|
251
|
+
audience?: ("user" | "assistant")[] | undefined;
|
|
252
|
+
priority?: number | undefined;
|
|
253
|
+
lastModified?: string | undefined;
|
|
254
|
+
} | undefined;
|
|
255
|
+
_meta?: {
|
|
256
|
+
[x: string]: unknown;
|
|
257
|
+
} | undefined;
|
|
258
|
+
})[];
|
|
259
|
+
_meta?: {
|
|
260
|
+
[x: string]: unknown;
|
|
261
|
+
progressToken?: string | number | undefined;
|
|
262
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
263
|
+
taskId: string;
|
|
264
|
+
} | undefined;
|
|
265
|
+
} | undefined;
|
|
266
|
+
structuredContent?: {
|
|
267
|
+
[x: string]: unknown;
|
|
268
|
+
} | undefined;
|
|
269
|
+
isError?: boolean | undefined;
|
|
270
|
+
} | {
|
|
271
|
+
content: never[];
|
|
272
|
+
structuredContent: {
|
|
273
|
+
code: string;
|
|
274
|
+
message: any;
|
|
275
|
+
};
|
|
276
|
+
}>;
|
|
277
|
+
description?: string | undefined;
|
|
278
|
+
_meta?: Record<string, unknown> | undefined;
|
|
279
|
+
annotations?: import("@modelcontextprotocol/sdk/types.js").ToolAnnotations;
|
|
280
|
+
title?: string | undefined;
|
|
281
|
+
token: Type | AbstractType<any>;
|
|
282
|
+
propertyKey: string | symbol;
|
|
283
|
+
}>;
|
|
284
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by @tsed/barrels.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./constants/constants.js";
|
|
5
|
+
export * from "./decorators/prompt.js";
|
|
6
|
+
export * from "./decorators/resource.js";
|
|
7
|
+
export * from "./decorators/tool.js";
|
|
8
|
+
export * from "./fn/definePrompt.js";
|
|
9
|
+
export * from "./fn/defineResource.js";
|
|
10
|
+
export * from "./fn/defineTool.js";
|
|
11
|
+
export * from "./interfaces/PlatformMcpSettings.js";
|
|
12
|
+
export * from "./services/McpServerFactory.js";
|
|
13
|
+
export * from "./services/PlatformMcpModule.js";
|
|
14
|
+
export * from "./utils/json-schema-to-zod/cli.js";
|
|
15
|
+
export * from "./utils/json-schema-to-zod/index.js";
|
|
16
|
+
export * from "./utils/json-schema-to-zod/jsonSchemaToZod.js";
|
|
17
|
+
export * from "./utils/json-schema-to-zod/parsers/parseAllOf.js";
|
|
18
|
+
export * from "./utils/json-schema-to-zod/parsers/parseAnyOf.js";
|
|
19
|
+
export * from "./utils/json-schema-to-zod/parsers/parseArray.js";
|
|
20
|
+
export * from "./utils/json-schema-to-zod/parsers/parseBoolean.js";
|
|
21
|
+
export * from "./utils/json-schema-to-zod/parsers/parseConst.js";
|
|
22
|
+
export * from "./utils/json-schema-to-zod/parsers/parseDefault.js";
|
|
23
|
+
export * from "./utils/json-schema-to-zod/parsers/parseEnum.js";
|
|
24
|
+
export * from "./utils/json-schema-to-zod/parsers/parseIfThenElse.js";
|
|
25
|
+
export * from "./utils/json-schema-to-zod/parsers/parseMultipleType.js";
|
|
26
|
+
export * from "./utils/json-schema-to-zod/parsers/parseNot.js";
|
|
27
|
+
export * from "./utils/json-schema-to-zod/parsers/parseNull.js";
|
|
28
|
+
export * from "./utils/json-schema-to-zod/parsers/parseNullable.js";
|
|
29
|
+
export * from "./utils/json-schema-to-zod/parsers/parseNumber.js";
|
|
30
|
+
export * from "./utils/json-schema-to-zod/parsers/parseObject.js";
|
|
31
|
+
export * from "./utils/json-schema-to-zod/parsers/parseOneOf.js";
|
|
32
|
+
export * from "./utils/json-schema-to-zod/parsers/parseSchema.js";
|
|
33
|
+
export * from "./utils/json-schema-to-zod/parsers/parseString.js";
|
|
34
|
+
export * from "./utils/json-schema-to-zod/Types.js";
|
|
35
|
+
export * from "./utils/json-schema-to-zod/utils/cliTools.js";
|
|
36
|
+
export * from "./utils/json-schema-to-zod/utils/half.js";
|
|
37
|
+
export * from "./utils/json-schema-to-zod/utils/jsdocs.js";
|
|
38
|
+
export * from "./utils/json-schema-to-zod/utils/omit.js";
|
|
39
|
+
export * from "./utils/json-schema-to-zod/utils/withMessage.js";
|
|
40
|
+
export * from "./utils/toZod.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { StreamableHTTPServerTransportOptions } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
2
|
+
import type { TokenProvider } from "@tsed/di";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration fragment accepted under `configuration.mcp` to wire the Platform MCP module.
|
|
5
|
+
*
|
|
6
|
+
* @module platform/mcp
|
|
7
|
+
* @since 8.17.0
|
|
8
|
+
*/
|
|
9
|
+
export interface PlatformMcpSettings {
|
|
10
|
+
/**
|
|
11
|
+
* Mount path for the MCP endpoint. Defaults to `/mcp`.
|
|
12
|
+
*/
|
|
13
|
+
path?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Whether the HTTP endpoint should be enabled. Defaults to `true`.
|
|
16
|
+
*/
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Optional name reported to MCP clients. Falls back to the Ts.ED app name.
|
|
20
|
+
*/
|
|
21
|
+
name?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional version reported to MCP clients. Falls back to the Ts.ED app version.
|
|
24
|
+
*/
|
|
25
|
+
version?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Optional tokens registered through configuration.
|
|
28
|
+
*/
|
|
29
|
+
tools?: TokenProvider[];
|
|
30
|
+
resources?: TokenProvider[];
|
|
31
|
+
prompts?: TokenProvider[];
|
|
32
|
+
/**
|
|
33
|
+
* Optional transport options for the MCP server.
|
|
34
|
+
*/
|
|
35
|
+
transportOptions?: StreamableHTTPServerTransportOptions;
|
|
36
|
+
}
|
|
37
|
+
declare global {
|
|
38
|
+
namespace TsED {
|
|
39
|
+
interface Configuration {
|
|
40
|
+
mcp?: PlatformMcpSettings;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
/**
|
|
3
|
+
* Injectable MCP server instance configured with registered tools, resources, and prompts.
|
|
4
|
+
*
|
|
5
|
+
* @module platform/mcp
|
|
6
|
+
* @since 8.17.0
|
|
7
|
+
*/
|
|
8
|
+
export declare const MCP_SERVER: import("@tsed/di").FactoryTokenProvider<McpServer>;
|
|
9
|
+
/**
|
|
10
|
+
* Type alias referencing the MCP server provider token.
|
|
11
|
+
*
|
|
12
|
+
* @module platform/mcp
|
|
13
|
+
* @since 8.17.0
|
|
14
|
+
*/
|
|
15
|
+
export type MCP_SERVER = typeof MCP_SERVER;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type OnRoutesInit, PlatformContext, type PlatformRouteDetails } from "@tsed/platform-http";
|
|
3
|
+
import type { PlatformMcpSettings } from "../interfaces/PlatformMcpSettings.js";
|
|
4
|
+
/**
|
|
5
|
+
* Platform module that mounts the MCP HTTP endpoint and forwards requests to the configured server instance.
|
|
6
|
+
*
|
|
7
|
+
* @module platform/mcp
|
|
8
|
+
* @since 8.17.0
|
|
9
|
+
*/
|
|
10
|
+
export declare class PlatformMcpModule implements OnRoutesInit {
|
|
11
|
+
protected settings: PlatformMcpSettings;
|
|
12
|
+
protected app: import("@tsed/platform-http").PlatformApplication<TsED.Application>;
|
|
13
|
+
protected server: McpServer;
|
|
14
|
+
$onRoutesInit(): void;
|
|
15
|
+
$logRoutes(routes: PlatformRouteDetails[]): (false | PlatformRouteDetails | {
|
|
16
|
+
method: string;
|
|
17
|
+
name: string;
|
|
18
|
+
url: string;
|
|
19
|
+
})[];
|
|
20
|
+
protected dispatch($ctx: PlatformContext): Promise<void>;
|
|
21
|
+
private isEnabled;
|
|
22
|
+
}
|