@tsed/platform-mcp 8.36.0 → 8.37.0-rc.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/fn/definePrompt.js +2 -2
- package/lib/esm/fn/defineTool.js +5 -5
- package/lib/esm/index.js +1 -1
- package/lib/esm/services/McpServerFactory.js +1 -1
- package/lib/esm/services/PlatformMcpModule.js +2 -2
- package/lib/esm/utils/fromJsonSchema.js +17 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/decorators/resource.d.ts +1 -1
- package/lib/types/fn/definePrompt.d.ts +4 -5
- package/lib/types/fn/defineResource.d.ts +17 -18
- package/lib/types/fn/defineTool.d.ts +2 -3
- package/lib/types/index.d.ts +1 -1
- package/lib/types/interfaces/PlatformMcpSettings.d.ts +2 -3
- package/lib/types/services/McpServerFactory.d.ts +1 -1
- package/lib/types/services/PlatformMcpModule.d.ts +1 -1
- package/lib/types/utils/asResourceResponse.d.ts +1 -1
- package/lib/types/utils/asToolResponse.d.ts +1 -1
- package/lib/types/utils/fromJsonSchema.d.ts +10 -0
- package/package.json +15 -13
- package/readme.md +1 -1
- package/src/decorators/resource.ts +1 -1
- package/src/fn/definePrompt.ts +5 -6
- package/src/fn/defineResource.ts +1 -2
- package/src/fn/defineTool.spec.ts +3 -5
- package/src/fn/defineTool.ts +7 -8
- package/src/index.ts +1 -1
- package/src/interfaces/PlatformMcpSettings.ts +2 -3
- package/src/services/McpServerFactory.ts +1 -2
- package/src/services/PlatformMcpModule.spec.ts +2 -2
- package/src/services/PlatformMcpModule.ts +3 -3
- package/src/utils/asResourceResponse.ts +1 -1
- package/src/utils/asToolResponse.ts +1 -1
- package/src/utils/fromJsonSchema.spec.ts +68 -0
- package/src/utils/fromJsonSchema.ts +20 -0
- package/vitest.config.mts +0 -1
- package/lib/esm/utils/toZod.js +0 -19
- package/lib/types/utils/toZod.d.ts +0 -12
- package/src/utils/toZod.spec.ts +0 -63
- package/src/utils/toZod.ts +0 -24
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ClassResourceReadProps } from "../fn/defineResource.js";
|
|
2
|
-
import type { ResourceTemplate } from "@modelcontextprotocol/
|
|
2
|
+
import type { ResourceTemplate } from "@modelcontextprotocol/server";
|
|
3
3
|
/**
|
|
4
4
|
* Options accepted by the {@link Resource} decorator beyond the handler binding fields, allowing callers to override metadata.
|
|
5
5
|
*
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type AbstractType, type Type } from "@tsed/core";
|
|
2
|
-
import type { GetPromptResult,
|
|
2
|
+
import type { GetPromptResult, ServerContext } from "@modelcontextprotocol/server";
|
|
3
3
|
import { JsonSchema } from "@tsed/schema";
|
|
4
4
|
import { type TokenProvider } from "@tsed/di";
|
|
5
|
-
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
6
5
|
type BasePromptConfig = {
|
|
7
6
|
title?: string;
|
|
8
7
|
description?: string;
|
|
@@ -11,7 +10,7 @@ type BasePromptProps<Args> = BasePromptConfig & {
|
|
|
11
10
|
name: string;
|
|
12
11
|
argsSchema?: JsonSchema<Args> | (() => JsonSchema<Args>) | Record<string, unknown>;
|
|
13
12
|
};
|
|
14
|
-
export type PromptHandler<Args = undefined> = Args extends undefined ? (
|
|
13
|
+
export type PromptHandler<Args = undefined> = Args extends undefined ? (ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult> : (args: Args, ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>;
|
|
15
14
|
export type FnPromptProps<Args = any> = BasePromptProps<Args> & {
|
|
16
15
|
handler: PromptHandler<Args>;
|
|
17
16
|
};
|
|
@@ -30,13 +29,13 @@ export type ClassPromptProps<Args = any> = Omit<BasePromptProps<Args>, "name"> &
|
|
|
30
29
|
export type PromptProps<Args = any> = FnPromptProps<Args> | ClassPromptProps<Args>;
|
|
31
30
|
declare function mapOptions<Args = any>(options: PromptProps<Args>): {
|
|
32
31
|
name: string | undefined;
|
|
33
|
-
argsSchema: import("
|
|
32
|
+
argsSchema: import("@modelcontextprotocol/server").StandardSchemaWithJSON<unknown, unknown> | undefined;
|
|
34
33
|
handler: PromptHandler<Args>;
|
|
35
34
|
title?: string;
|
|
36
35
|
description?: string;
|
|
37
36
|
} | {
|
|
38
37
|
name: string | undefined;
|
|
39
|
-
argsSchema: import("
|
|
38
|
+
argsSchema: import("@modelcontextprotocol/server").StandardSchemaWithJSON<unknown, unknown> | undefined;
|
|
40
39
|
handler: PromptHandler<Args>;
|
|
41
40
|
description?: string | undefined;
|
|
42
41
|
title?: string | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type { ReadResourceCallback, ResourceMetadata, ResourceTemplate } from "@modelcontextprotocol/
|
|
2
|
-
import type { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
|
|
1
|
+
import type { ReadResourceCallback, ReadResourceResult, ResourceMetadata, ResourceTemplate } from "@modelcontextprotocol/server";
|
|
3
2
|
import { type TokenProvider } from "@tsed/di";
|
|
4
3
|
type ResourceMetadataProps = ResourceMetadata & {
|
|
5
4
|
name: string;
|
|
@@ -34,92 +33,92 @@ export type ResourceProps = FnResourceReadProps | FnResourceTemplateProps | Clas
|
|
|
34
33
|
declare function mapOptions(options: ResourceProps): {
|
|
35
34
|
name: string | undefined;
|
|
36
35
|
handler: ResourceCallback;
|
|
36
|
+
description?: string | undefined;
|
|
37
|
+
title?: string | undefined;
|
|
37
38
|
_meta?: {
|
|
38
39
|
[x: string]: unknown;
|
|
39
40
|
} | undefined;
|
|
40
|
-
description?: string | undefined;
|
|
41
41
|
annotations?: {
|
|
42
42
|
audience?: ("user" | "assistant")[] | undefined;
|
|
43
43
|
priority?: number | undefined;
|
|
44
44
|
lastModified?: string | undefined;
|
|
45
45
|
} | undefined;
|
|
46
|
+
mimeType?: string | undefined;
|
|
47
|
+
size?: number | undefined;
|
|
46
48
|
icons?: {
|
|
47
49
|
src: string;
|
|
48
50
|
mimeType?: string | undefined;
|
|
49
51
|
sizes?: string[] | undefined;
|
|
50
52
|
theme?: "light" | "dark" | undefined;
|
|
51
53
|
}[] | undefined;
|
|
52
|
-
title?: string | undefined;
|
|
53
|
-
mimeType?: string | undefined;
|
|
54
|
-
size?: number | undefined;
|
|
55
54
|
uri: string;
|
|
56
55
|
} | {
|
|
57
56
|
name: string | undefined;
|
|
58
57
|
handler: ResourceCallback;
|
|
58
|
+
description?: string | undefined;
|
|
59
|
+
title?: string | undefined;
|
|
59
60
|
_meta?: {
|
|
60
61
|
[x: string]: unknown;
|
|
61
62
|
} | undefined;
|
|
62
|
-
description?: string | undefined;
|
|
63
63
|
annotations?: {
|
|
64
64
|
audience?: ("user" | "assistant")[] | undefined;
|
|
65
65
|
priority?: number | undefined;
|
|
66
66
|
lastModified?: string | undefined;
|
|
67
67
|
} | undefined;
|
|
68
|
+
mimeType?: string | undefined;
|
|
69
|
+
size?: number | undefined;
|
|
68
70
|
icons?: {
|
|
69
71
|
src: string;
|
|
70
72
|
mimeType?: string | undefined;
|
|
71
73
|
sizes?: string[] | undefined;
|
|
72
74
|
theme?: "light" | "dark" | undefined;
|
|
73
75
|
}[] | undefined;
|
|
74
|
-
title?: string | undefined;
|
|
75
|
-
mimeType?: string | undefined;
|
|
76
|
-
size?: number | undefined;
|
|
77
76
|
template: ResourceTemplate;
|
|
78
77
|
} | {
|
|
79
78
|
name: string | undefined;
|
|
80
79
|
handler: ResourceCallback;
|
|
80
|
+
description?: string | undefined;
|
|
81
|
+
title?: string | undefined;
|
|
81
82
|
_meta?: {
|
|
82
83
|
[x: string]: unknown;
|
|
83
84
|
} | undefined;
|
|
84
|
-
description?: string | undefined;
|
|
85
85
|
annotations?: {
|
|
86
86
|
audience?: ("user" | "assistant")[] | undefined;
|
|
87
87
|
priority?: number | undefined;
|
|
88
88
|
lastModified?: string | undefined;
|
|
89
89
|
} | undefined;
|
|
90
|
+
mimeType?: string | undefined;
|
|
91
|
+
size?: number | undefined;
|
|
90
92
|
icons?: {
|
|
91
93
|
src: string;
|
|
92
94
|
mimeType?: string | undefined;
|
|
93
95
|
sizes?: string[] | undefined;
|
|
94
96
|
theme?: "light" | "dark" | undefined;
|
|
95
97
|
}[] | undefined;
|
|
96
|
-
title?: string | undefined;
|
|
97
|
-
mimeType?: string | undefined;
|
|
98
|
-
size?: number | undefined;
|
|
99
98
|
token: TokenProvider;
|
|
100
99
|
propertyKey: string | symbol;
|
|
101
100
|
uri: string;
|
|
102
101
|
} | {
|
|
103
102
|
name: string | undefined;
|
|
104
103
|
handler: ResourceCallback;
|
|
104
|
+
description?: string | undefined;
|
|
105
|
+
title?: string | undefined;
|
|
105
106
|
_meta?: {
|
|
106
107
|
[x: string]: unknown;
|
|
107
108
|
} | undefined;
|
|
108
|
-
description?: string | undefined;
|
|
109
109
|
annotations?: {
|
|
110
110
|
audience?: ("user" | "assistant")[] | undefined;
|
|
111
111
|
priority?: number | undefined;
|
|
112
112
|
lastModified?: string | undefined;
|
|
113
113
|
} | undefined;
|
|
114
|
+
mimeType?: string | undefined;
|
|
115
|
+
size?: number | undefined;
|
|
114
116
|
icons?: {
|
|
115
117
|
src: string;
|
|
116
118
|
mimeType?: string | undefined;
|
|
117
119
|
sizes?: string[] | undefined;
|
|
118
120
|
theme?: "light" | "dark" | undefined;
|
|
119
121
|
}[] | undefined;
|
|
120
|
-
title?: string | undefined;
|
|
121
|
-
mimeType?: string | undefined;
|
|
122
|
-
size?: number | undefined;
|
|
123
122
|
token: TokenProvider;
|
|
124
123
|
propertyKey: string | symbol;
|
|
125
124
|
template: ResourceTemplate;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { type AbstractType, type Type } from "@tsed/core";
|
|
2
|
-
import type { CallToolResult,
|
|
2
|
+
import type { CallToolResult, ServerContext, Tool, ToolAnnotations } from "@modelcontextprotocol/server";
|
|
3
3
|
import { JsonSchema } from "@tsed/schema";
|
|
4
4
|
import { type TokenProvider } from "@tsed/di";
|
|
5
|
-
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
6
5
|
/**
|
|
7
6
|
* Signature implemented by MCP tool handlers invoked through {@link defineTool}.
|
|
8
7
|
*
|
|
@@ -10,7 +9,7 @@ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/proto
|
|
|
10
9
|
* @module platform/mcp
|
|
11
10
|
* @since 8.17.0
|
|
12
11
|
*/
|
|
13
|
-
export type ToolCallback<Args = undefined, Output = unknown> = (args: Args,
|
|
12
|
+
export type ToolCallback<Args = undefined, Output = unknown> = (args: Args, ctx: ServerContext) => CallToolResult | Promise<CallToolResult> | Output | Promise<Output>;
|
|
14
13
|
type BaseToolConfig = {
|
|
15
14
|
title?: string;
|
|
16
15
|
description?: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,4 +13,4 @@ export * from "./services/McpServerFactory.js";
|
|
|
13
13
|
export * from "./services/PlatformMcpModule.js";
|
|
14
14
|
export * from "./utils/asResourceResponse.js";
|
|
15
15
|
export * from "./utils/asToolResponse.js";
|
|
16
|
-
export * from "./utils/
|
|
16
|
+
export * from "./utils/fromJsonSchema.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Implementation } from "@modelcontextprotocol/
|
|
2
|
-
import type {
|
|
3
|
-
import type { StreamableHTTPServerTransportOptions } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
1
|
+
import type { Implementation, ServerOptions } from "@modelcontextprotocol/server";
|
|
2
|
+
import type { StreamableHTTPServerTransportOptions } from "@modelcontextprotocol/node";
|
|
4
3
|
import type { TokenProvider } from "@tsed/di";
|
|
5
4
|
/**
|
|
6
5
|
* Configuration fragment accepted under `configuration.mcp` to wire the Platform MCP module.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type OnRoutesInit, PlatformContext, type PlatformRouteDetails } from "@tsed/platform-http";
|
|
2
|
-
import type
|
|
2
|
+
import { type McpServer } from "@modelcontextprotocol/server";
|
|
3
3
|
import type { PlatformMcpSettings } from "../interfaces/PlatformMcpSettings.js";
|
|
4
4
|
/**
|
|
5
5
|
* Platform module that mounts the MCP HTTP endpoint and forwards requests to the configured server instance.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReadResourceResult } from "@modelcontextprotocol/
|
|
1
|
+
import type { ReadResourceResult } from "@modelcontextprotocol/server";
|
|
2
2
|
export declare function asResourceResponse(uri: string, payload: Record<string, unknown> | ReadResourceResult, opts?: {
|
|
3
3
|
isError?: boolean;
|
|
4
4
|
}): ReadResourceResult;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type JsonSchemaOptions } from "@tsed/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a Ts.ED schema into the MCP SDK v2 Standard Schema adapter.
|
|
4
|
+
*
|
|
5
|
+
* @param schema Ts.ED or plain JSON Schema document.
|
|
6
|
+
* @param opts Compilation options applied to Ts.ED schemas.
|
|
7
|
+
* @module platform/mcp
|
|
8
|
+
* @since 8.17.0
|
|
9
|
+
*/
|
|
10
|
+
export declare function fromJsonSchema<T = unknown>(schema: unknown, opts?: JsonSchemaOptions): import("@modelcontextprotocol/server").StandardSchemaWithJSON<T, T> | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/platform-mcp",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.37.0-rc.1",
|
|
4
4
|
"description": "Model Context Protocol integration for Ts.ED HTTP adapters.",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -24,21 +24,20 @@
|
|
|
24
24
|
"test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@modelcontextprotocol/
|
|
27
|
+
"@modelcontextprotocol/node": "^2.0.0-beta.4",
|
|
28
|
+
"@modelcontextprotocol/server": "^2.0.0-beta.4",
|
|
28
29
|
"change-case": ">=5.4.4",
|
|
29
|
-
"json-schema-to-zod": ">=2.8.1",
|
|
30
30
|
"tslib": ">=2.7.0",
|
|
31
|
-
"uuid": ">=11.0.2"
|
|
32
|
-
"zod": ">=4.0.0"
|
|
31
|
+
"uuid": ">=11.0.2"
|
|
33
32
|
},
|
|
34
33
|
"devDependencies": {
|
|
35
|
-
"@tsed/barrels": "8.
|
|
36
|
-
"@tsed/core": "8.
|
|
37
|
-
"@tsed/di": "8.
|
|
38
|
-
"@tsed/json-mapper": "8.
|
|
39
|
-
"@tsed/platform-http": "8.
|
|
40
|
-
"@tsed/schema": "8.
|
|
41
|
-
"@tsed/typescript": "8.
|
|
34
|
+
"@tsed/barrels": "8.37.0-rc.1",
|
|
35
|
+
"@tsed/core": "8.37.0-rc.1",
|
|
36
|
+
"@tsed/di": "8.37.0-rc.1",
|
|
37
|
+
"@tsed/json-mapper": "8.37.0-rc.1",
|
|
38
|
+
"@tsed/platform-http": "8.37.0-rc.1",
|
|
39
|
+
"@tsed/schema": "8.37.0-rc.1",
|
|
40
|
+
"@tsed/typescript": "8.37.0-rc.1",
|
|
42
41
|
"typescript": "6.0.2",
|
|
43
42
|
"vitest": "4.1.4"
|
|
44
43
|
},
|
|
@@ -72,5 +71,8 @@
|
|
|
72
71
|
},
|
|
73
72
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/platform/platform-mcp",
|
|
74
73
|
"author": "Romain Lenzotti",
|
|
75
|
-
"license": "MIT"
|
|
74
|
+
"license": "MIT",
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"tag": "rc"
|
|
77
|
+
}
|
|
76
78
|
}
|
package/readme.md
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
- A `PlatformMcpModule` that mounts a configurable `/mcp` endpoint on top of `@tsed/platform-http`.
|
|
35
35
|
- Functional helpers (`defineTool`, `defineResource`, `definePrompt`) to register MCP handlers via DI tokens.
|
|
36
36
|
- Decorators (`@Tool`, `@Prompt`, `@Resource`) for declarative registration inside services/controllers.
|
|
37
|
-
- Shared utilities (`MCP_SERVER`, transport helpers) that wire
|
|
37
|
+
- Shared utilities (`MCP_SERVER`, transport helpers) that wire the MCP SDK v2 server packages into Ts.ED's dependency injection system.
|
|
38
38
|
|
|
39
39
|
## Installation
|
|
40
40
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {type ClassResourceReadProps, type ClassResourceTemplateProps, defineResource} from "../fn/defineResource.js";
|
|
2
|
-
import type {ResourceTemplate} from "@modelcontextprotocol/
|
|
2
|
+
import type {ResourceTemplate} from "@modelcontextprotocol/server";
|
|
3
3
|
import {classOf} from "@tsed/core";
|
|
4
4
|
import {isString} from "@tsed/core/utils/isString.js";
|
|
5
5
|
|
package/src/fn/definePrompt.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {type AbstractType, isArrowFn, type Type} from "@tsed/core";
|
|
2
|
-
import type {GetPromptResult,
|
|
2
|
+
import type {GetPromptResult, ServerContext} from "@modelcontextprotocol/server";
|
|
3
3
|
import {JsonSchema, s} from "@tsed/schema";
|
|
4
4
|
import {context, inject, injectable, logger, type TokenProvider} from "@tsed/di";
|
|
5
5
|
import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
|
|
6
|
-
import type {RequestHandlerExtra} from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
7
6
|
import {constantCase} from "change-case";
|
|
8
|
-
import {
|
|
7
|
+
import {fromJsonSchema} from "../utils/fromJsonSchema.js";
|
|
9
8
|
|
|
10
9
|
type BasePromptConfig = {
|
|
11
10
|
title?: string;
|
|
@@ -18,8 +17,8 @@ type BasePromptProps<Args> = BasePromptConfig & {
|
|
|
18
17
|
};
|
|
19
18
|
|
|
20
19
|
export type PromptHandler<Args = undefined> = Args extends undefined
|
|
21
|
-
? (
|
|
22
|
-
: (args: Args,
|
|
20
|
+
? (ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>
|
|
21
|
+
: (args: Args, ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>;
|
|
23
22
|
|
|
24
23
|
export type FnPromptProps<Args = any> = BasePromptProps<Args> & {
|
|
25
24
|
handler: PromptHandler<Args>;
|
|
@@ -64,7 +63,7 @@ function mapOptions<Args = any>(options: PromptProps<Args>) {
|
|
|
64
63
|
return {
|
|
65
64
|
...options,
|
|
66
65
|
name,
|
|
67
|
-
argsSchema:
|
|
66
|
+
argsSchema: fromJsonSchema(isArrowFn(options.argsSchema) ? options.argsSchema() : options.argsSchema, {
|
|
68
67
|
useAlias: true,
|
|
69
68
|
groups: [name!, "prompt"]
|
|
70
69
|
}),
|
package/src/fn/defineResource.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {ReadResourceCallback, ResourceMetadata, ResourceTemplate} from "@modelcontextprotocol/
|
|
2
|
-
import type {ReadResourceResult} from "@modelcontextprotocol/sdk/types.js";
|
|
1
|
+
import type {ReadResourceCallback, ReadResourceResult, ResourceMetadata, ResourceTemplate} from "@modelcontextprotocol/server";
|
|
3
2
|
import {context, inject, injectable, logger, type TokenProvider} from "@tsed/di";
|
|
4
3
|
import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
|
|
5
4
|
import {constantCase} from "change-case";
|
|
@@ -89,16 +89,14 @@ describe("defineTool", () => {
|
|
|
89
89
|
|
|
90
90
|
const definition = inject<any>(token);
|
|
91
91
|
|
|
92
|
-
expect(definition.inputSchema.
|
|
93
|
-
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
92
|
+
expect(definition.inputSchema["~standard"].jsonSchema.input({target: "draft-2020-12"})).toEqual({
|
|
94
93
|
type: "object",
|
|
95
94
|
properties: {
|
|
96
95
|
aliasProp: {
|
|
97
96
|
type: "string"
|
|
98
97
|
}
|
|
99
98
|
},
|
|
100
|
-
required: ["aliasProp"]
|
|
101
|
-
additionalProperties: false
|
|
99
|
+
required: ["aliasProp"]
|
|
102
100
|
});
|
|
103
101
|
});
|
|
104
102
|
|
|
@@ -113,7 +111,7 @@ describe("defineTool", () => {
|
|
|
113
111
|
|
|
114
112
|
const definition = inject<any>(token);
|
|
115
113
|
|
|
116
|
-
expect(definition.outputSchema.
|
|
114
|
+
expect(definition.outputSchema["~standard"].jsonSchema.input({target: "draft-2020-12"})).toMatchObject({
|
|
117
115
|
type: "object",
|
|
118
116
|
properties: {
|
|
119
117
|
aliasProp: {
|
package/src/fn/defineTool.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {type AbstractType, isArrowFn, isClass, type Type} from "@tsed/core";
|
|
2
|
-
import type {CallToolResult,
|
|
2
|
+
import type {CallToolResult, ServerContext, Tool, ToolAnnotations} from "@modelcontextprotocol/server";
|
|
3
3
|
import {JsonEntityStore, JsonMethodStore, JsonSchema, s} from "@tsed/schema";
|
|
4
4
|
import {context, inject, injectable, logger, type TokenProvider} from "@tsed/di";
|
|
5
5
|
import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
|
|
6
|
-
import type {RequestHandlerExtra} from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
7
6
|
import {constantCase} from "change-case";
|
|
8
7
|
import {deserialize} from "@tsed/json-mapper";
|
|
9
|
-
import {
|
|
8
|
+
import {fromJsonSchema} from "../utils/fromJsonSchema.js";
|
|
10
9
|
import {asToolResponse} from "../utils/asToolResponse.js";
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -18,7 +17,7 @@ import {asToolResponse} from "../utils/asToolResponse.js";
|
|
|
18
17
|
*/
|
|
19
18
|
export type ToolCallback<Args = undefined, Output = unknown> = (
|
|
20
19
|
args: Args,
|
|
21
|
-
|
|
20
|
+
ctx: ServerContext
|
|
22
21
|
) => CallToolResult | Promise<CallToolResult> | Output | Promise<Output>;
|
|
23
22
|
|
|
24
23
|
type BaseToolConfig = {
|
|
@@ -154,17 +153,17 @@ export function defineTool<Input, Output = unknown>(options: ToolProps<Input, Ou
|
|
|
154
153
|
return {
|
|
155
154
|
...opts,
|
|
156
155
|
name: opts.name,
|
|
157
|
-
inputSchema:
|
|
156
|
+
inputSchema: fromJsonSchema(inputSchema, {
|
|
158
157
|
groups: [opts.name!, "tools"],
|
|
159
158
|
useAlias: true
|
|
160
159
|
}),
|
|
161
|
-
outputSchema:
|
|
160
|
+
outputSchema: fromJsonSchema(opts.outputSchema, {
|
|
162
161
|
groups: [opts.name!, "tools"],
|
|
163
162
|
useAlias: true
|
|
164
163
|
}),
|
|
165
|
-
async handler(args: Input,
|
|
164
|
+
async handler(args: Input, ctx: ServerContext) {
|
|
166
165
|
try {
|
|
167
|
-
const result = await handler(deserializeInput(args, inputSchema, inputStore),
|
|
166
|
+
const result = await handler(deserializeInput(args, inputSchema, inputStore), ctx);
|
|
168
167
|
|
|
169
168
|
logger().info({
|
|
170
169
|
event: "MCP_TOOL_END",
|
package/src/index.ts
CHANGED
|
@@ -13,4 +13,4 @@ export * from "./services/McpServerFactory.js";
|
|
|
13
13
|
export * from "./services/PlatformMcpModule.js";
|
|
14
14
|
export * from "./utils/asResourceResponse.js";
|
|
15
15
|
export * from "./utils/asToolResponse.js";
|
|
16
|
-
export * from "./utils/
|
|
16
|
+
export * from "./utils/fromJsonSchema.js";
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type {Implementation} from "@modelcontextprotocol/
|
|
2
|
-
import type {
|
|
3
|
-
import type {StreamableHTTPServerTransportOptions} from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
1
|
+
import type {Implementation, ServerOptions} from "@modelcontextprotocol/server";
|
|
2
|
+
import type {StreamableHTTPServerTransportOptions} from "@modelcontextprotocol/node";
|
|
4
3
|
import type {TokenProvider} from "@tsed/di";
|
|
5
4
|
|
|
6
5
|
/**
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {type TokenProvider, constant, inject, injectable, injector} from "@tsed/di";
|
|
2
2
|
import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
|
|
3
|
-
import {McpServer} from "@modelcontextprotocol/
|
|
3
|
+
import {McpServer, type ResourceTemplate} from "@modelcontextprotocol/server";
|
|
4
4
|
import type {PlatformMcpSettings} from "../interfaces/PlatformMcpSettings.js";
|
|
5
5
|
import type {PromptsSettings} from "../fn/definePrompt.js";
|
|
6
6
|
import type {ResourceSettings} from "../fn/defineResource.js";
|
|
7
|
-
import type {ResourceTemplate} from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
7
|
import type {ToolProps} from "../fn/defineTool.js";
|
|
9
8
|
|
|
10
9
|
function collectTokens(type: string, configured: TokenProvider[] = []): TokenProvider[] {
|
|
@@ -20,9 +20,9 @@ const {TestTransport, transportInstances} = vi.hoisted(() => {
|
|
|
20
20
|
return {TestTransport, transportInstances};
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
-
vi.mock("@modelcontextprotocol/
|
|
23
|
+
vi.mock("@modelcontextprotocol/node", () => {
|
|
24
24
|
return {
|
|
25
|
-
|
|
25
|
+
NodeStreamableHTTPServerTransport: TestTransport
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
28
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {type OnRoutesInit, PlatformContext, type PlatformRouteDetails, application} from "@tsed/platform-http";
|
|
2
2
|
import {constant, inject, injectable} from "@tsed/di";
|
|
3
3
|
import {MCP_SERVER} from "./McpServerFactory.js";
|
|
4
|
-
import type
|
|
4
|
+
import {type McpServer} from "@modelcontextprotocol/server";
|
|
5
5
|
import type {PlatformMcpSettings} from "../interfaces/PlatformMcpSettings.js";
|
|
6
|
-
import {
|
|
6
|
+
import {NodeStreamableHTTPServerTransport} from "@modelcontextprotocol/node";
|
|
7
7
|
import {useContextHandler} from "@tsed/platform-router";
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -45,7 +45,7 @@ export class PlatformMcpModule implements OnRoutesInit {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
protected async dispatch($ctx: PlatformContext) {
|
|
48
|
-
const transport = new
|
|
48
|
+
const transport = new NodeStreamableHTTPServerTransport({
|
|
49
49
|
sessionIdGenerator: undefined,
|
|
50
50
|
enableJsonResponse: true,
|
|
51
51
|
...this.settings.transportOptions
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {serialize} from "@tsed/json-mapper";
|
|
2
2
|
import {isObject} from "@tsed/core";
|
|
3
|
-
import {ReadResourceResult} from "@modelcontextprotocol/
|
|
3
|
+
import type {ReadResourceResult} from "@modelcontextprotocol/server";
|
|
4
4
|
|
|
5
5
|
export function asResourceResponse(
|
|
6
6
|
uri: string,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {serialize} from "@tsed/json-mapper";
|
|
2
2
|
import {isObject} from "@tsed/core";
|
|
3
|
-
import type {CallToolResult} from "@modelcontextprotocol/
|
|
3
|
+
import type {CallToolResult} from "@modelcontextprotocol/server";
|
|
4
4
|
|
|
5
5
|
export interface StructuredResponse<
|
|
6
6
|
T extends {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {JsonSchema, Property, s, string} from "@tsed/schema";
|
|
2
|
+
import {fromJsonSchema} from "./fromJsonSchema.js";
|
|
3
|
+
|
|
4
|
+
describe("fromJsonSchema", () => {
|
|
5
|
+
it("should wrap a Ts.ED JsonSchema with the MCP SDK adapter", () => {
|
|
6
|
+
const schema = s.object({
|
|
7
|
+
prop1: string()
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
const result = fromJsonSchema(schema);
|
|
11
|
+
|
|
12
|
+
expect(result?.["~standard"].jsonSchema.input({target: "draft-2020-12"})).toMatchObject({
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
prop1: {
|
|
16
|
+
type: "string"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should preserve aliases when compiling a Ts.ED JsonSchema", () => {
|
|
23
|
+
const schema = new JsonSchema({
|
|
24
|
+
type: "object",
|
|
25
|
+
properties: {
|
|
26
|
+
prop: {
|
|
27
|
+
type: "string"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: ["prop"]
|
|
31
|
+
}).addAlias("prop", "aliasProp");
|
|
32
|
+
|
|
33
|
+
const result = fromJsonSchema(schema, {useAlias: true});
|
|
34
|
+
|
|
35
|
+
expect(result?.["~standard"].jsonSchema.input({target: "draft-2020-12"})).toMatchObject({
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: {
|
|
38
|
+
aliasProp: {
|
|
39
|
+
type: "string"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
required: ["aliasProp"]
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should inline local schema references", () => {
|
|
47
|
+
class Child {
|
|
48
|
+
@Property()
|
|
49
|
+
id: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const result = fromJsonSchema(s.object({child: s.from(Child)}));
|
|
53
|
+
|
|
54
|
+
expect(result?.["~standard"].jsonSchema.input({target: "draft-2020-12"})).toMatchObject({
|
|
55
|
+
type: "object",
|
|
56
|
+
properties: {
|
|
57
|
+
child: {
|
|
58
|
+
type: "object",
|
|
59
|
+
properties: {
|
|
60
|
+
id: {
|
|
61
|
+
type: "string"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {fromJsonSchema as fromJSchema} from "@modelcontextprotocol/server";
|
|
2
|
+
import {JsonSchema, type JsonSchemaOptions, s} from "@tsed/schema";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Converts a Ts.ED schema into the MCP SDK v2 Standard Schema adapter.
|
|
6
|
+
*
|
|
7
|
+
* @param schema Ts.ED or plain JSON Schema document.
|
|
8
|
+
* @param opts Compilation options applied to Ts.ED schemas.
|
|
9
|
+
* @module platform/mcp
|
|
10
|
+
* @since 8.17.0
|
|
11
|
+
*/
|
|
12
|
+
export function fromJsonSchema<T = unknown>(schema: unknown, opts?: JsonSchemaOptions) {
|
|
13
|
+
if (!schema) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const jsonSchema = schema instanceof JsonSchema ? s.compile(schema, {inlineRefs: true, ...opts}) : schema;
|
|
18
|
+
|
|
19
|
+
return fromJSchema<T>(jsonSchema as any);
|
|
20
|
+
}
|
package/vitest.config.mts
CHANGED
package/lib/esm/utils/toZod.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { JsonSchema, s } from "@tsed/schema";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { jsonSchemaToZod } from "json-schema-to-zod";
|
|
4
|
-
function transform(schema, opts) {
|
|
5
|
-
const schemaFactory = new Function("z", `return ${jsonSchemaToZod(s.compile(schema, { inlineRefs: true, ...opts }), { zodVersion: 4 })}`);
|
|
6
|
-
return schemaFactory(z);
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Converts a {@link JsonSchema} produced by Ts.ED into an executable Zod validation object.
|
|
10
|
-
*
|
|
11
|
-
* @param schema JsonSchema instance or a pre-built Zod schema.
|
|
12
|
-
* @param opts
|
|
13
|
-
* @returns A Zod object when conversion is possible, otherwise the original schema.
|
|
14
|
-
* @module platform/mcp
|
|
15
|
-
* @since 8.17.0
|
|
16
|
-
*/
|
|
17
|
-
export function toZod(schema, opts) {
|
|
18
|
-
return schema && schema instanceof JsonSchema ? transform(schema, opts) : schema;
|
|
19
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { JsonSchemaOptions } from "@tsed/schema";
|
|
2
|
-
import { type ZodObject } from "zod";
|
|
3
|
-
/**
|
|
4
|
-
* Converts a {@link JsonSchema} produced by Ts.ED into an executable Zod validation object.
|
|
5
|
-
*
|
|
6
|
-
* @param schema JsonSchema instance or a pre-built Zod schema.
|
|
7
|
-
* @param opts
|
|
8
|
-
* @returns A Zod object when conversion is possible, otherwise the original schema.
|
|
9
|
-
* @module platform/mcp
|
|
10
|
-
* @since 8.17.0
|
|
11
|
-
*/
|
|
12
|
-
export declare function toZod(schema: unknown, opts?: JsonSchemaOptions): ZodObject | undefined;
|