@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
|
@@ -3,7 +3,7 @@ import { s } from "@tsed/schema";
|
|
|
3
3
|
import { context, inject, injectable, logger } from "@tsed/di";
|
|
4
4
|
import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
|
|
5
5
|
import { constantCase } from "change-case";
|
|
6
|
-
import {
|
|
6
|
+
import { fromJsonSchema } from "../utils/fromJsonSchema.js";
|
|
7
7
|
function mapOptions(options) {
|
|
8
8
|
let handler = undefined;
|
|
9
9
|
const name = options.name || ("propertyKey" in options ? String(options.propertyKey) : undefined);
|
|
@@ -23,7 +23,7 @@ function mapOptions(options) {
|
|
|
23
23
|
return {
|
|
24
24
|
...options,
|
|
25
25
|
name,
|
|
26
|
-
argsSchema:
|
|
26
|
+
argsSchema: fromJsonSchema(isArrowFn(options.argsSchema) ? options.argsSchema() : options.argsSchema, {
|
|
27
27
|
useAlias: true,
|
|
28
28
|
groups: [name, "prompt"]
|
|
29
29
|
}),
|
package/lib/esm/fn/defineTool.js
CHANGED
|
@@ -4,7 +4,7 @@ import { context, inject, injectable, logger } from "@tsed/di";
|
|
|
4
4
|
import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
|
|
5
5
|
import { constantCase } from "change-case";
|
|
6
6
|
import { deserialize } from "@tsed/json-mapper";
|
|
7
|
-
import {
|
|
7
|
+
import { fromJsonSchema } from "../utils/fromJsonSchema.js";
|
|
8
8
|
import { asToolResponse } from "../utils/asToolResponse.js";
|
|
9
9
|
function getOutputSchema(methodStore) {
|
|
10
10
|
const schema = methodStore.operation.getResponseOf(200)?.getMedia("application/json")?.get("schema");
|
|
@@ -64,17 +64,17 @@ export function defineTool(options) {
|
|
|
64
64
|
return {
|
|
65
65
|
...opts,
|
|
66
66
|
name: opts.name,
|
|
67
|
-
inputSchema:
|
|
67
|
+
inputSchema: fromJsonSchema(inputSchema, {
|
|
68
68
|
groups: [opts.name, "tools"],
|
|
69
69
|
useAlias: true
|
|
70
70
|
}),
|
|
71
|
-
outputSchema:
|
|
71
|
+
outputSchema: fromJsonSchema(opts.outputSchema, {
|
|
72
72
|
groups: [opts.name, "tools"],
|
|
73
73
|
useAlias: true
|
|
74
74
|
}),
|
|
75
|
-
async handler(args,
|
|
75
|
+
async handler(args, ctx) {
|
|
76
76
|
try {
|
|
77
|
-
const result = await handler(deserializeInput(args, inputSchema, inputStore),
|
|
77
|
+
const result = await handler(deserializeInput(args, inputSchema, inputStore), ctx);
|
|
78
78
|
logger().info({
|
|
79
79
|
event: "MCP_TOOL_END",
|
|
80
80
|
tool: opts.name
|
package/lib/esm/index.js
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,6 @@
|
|
|
1
1
|
import { 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 } from "@modelcontextprotocol/server";
|
|
4
4
|
function collectTokens(type, configured = []) {
|
|
5
5
|
const tokens = new Set(configured);
|
|
6
6
|
injector()
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { application } from "@tsed/platform-http";
|
|
2
2
|
import { constant, inject, injectable } from "@tsed/di";
|
|
3
3
|
import { MCP_SERVER } from "./McpServerFactory.js";
|
|
4
|
-
import {
|
|
4
|
+
import { NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
|
|
5
5
|
import { useContextHandler } from "@tsed/platform-router";
|
|
6
6
|
/**
|
|
7
7
|
* Platform module that mounts the MCP HTTP endpoint and forwards requests to the configured server instance.
|
|
@@ -35,7 +35,7 @@ export class PlatformMcpModule {
|
|
|
35
35
|
].filter(Boolean);
|
|
36
36
|
}
|
|
37
37
|
async dispatch($ctx) {
|
|
38
|
-
const transport = new
|
|
38
|
+
const transport = new NodeStreamableHTTPServerTransport({
|
|
39
39
|
sessionIdGenerator: undefined,
|
|
40
40
|
enableJsonResponse: true,
|
|
41
41
|
...this.settings.transportOptions
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { fromJsonSchema as fromJSchema } from "@modelcontextprotocol/server";
|
|
2
|
+
import { JsonSchema, s } from "@tsed/schema";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a Ts.ED schema into the MCP SDK v2 Standard Schema adapter.
|
|
5
|
+
*
|
|
6
|
+
* @param schema Ts.ED or plain JSON Schema document.
|
|
7
|
+
* @param opts Compilation options applied to Ts.ED schemas.
|
|
8
|
+
* @module platform/mcp
|
|
9
|
+
* @since 8.17.0
|
|
10
|
+
*/
|
|
11
|
+
export function fromJsonSchema(schema, opts) {
|
|
12
|
+
if (!schema) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const jsonSchema = schema instanceof JsonSchema ? s.compile(schema, { inlineRefs: true, ...opts }) : schema;
|
|
16
|
+
return fromJSchema(jsonSchema);
|
|
17
|
+
}
|