@tsed/platform-mcp 8.39.0 → 8.40.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsed/platform-mcp",
3
- "version": "8.39.0",
3
+ "version": "8.40.1",
4
4
  "description": "Model Context Protocol integration for Ts.ED HTTP adapters.",
5
5
  "source": "./src/http/index.ts",
6
6
  "type": "module",
@@ -49,13 +49,13 @@
49
49
  "uuid": ">=11.0.2"
50
50
  },
51
51
  "devDependencies": {
52
- "@tsed/barrels": "8.39.0",
53
- "@tsed/core": "8.39.0",
54
- "@tsed/di": "8.39.0",
55
- "@tsed/json-mapper": "8.39.0",
56
- "@tsed/platform-http": "8.39.0",
57
- "@tsed/schema": "8.39.0",
58
- "@tsed/typescript": "8.39.0",
52
+ "@tsed/barrels": "8.40.1",
53
+ "@tsed/core": "8.40.1",
54
+ "@tsed/di": "8.40.1",
55
+ "@tsed/json-mapper": "8.40.1",
56
+ "@tsed/platform-http": "8.40.1",
57
+ "@tsed/schema": "8.40.1",
58
+ "@tsed/typescript": "8.40.1",
59
59
  "typescript": "6.0.2",
60
60
  "vitest": "4.1.4"
61
61
  },
@@ -1,4 +1,4 @@
1
- import {Default, from, JsonSchema, Name, Property, s, string} from "@tsed/schema";
1
+ import {Default, from, JsonSchema, Name, Property, Returns, s, string} from "@tsed/schema";
2
2
  import {afterEach, beforeEach, describe, expect, it} from "vitest";
3
3
  import {PlatformTest} from "@tsed/platform-http/testing";
4
4
  import {defineTool} from "./defineTool.js";
@@ -22,6 +22,22 @@ class KnowledgeSearchRequest {
22
22
  }
23
23
  }
24
24
 
25
+ class ToolResult {
26
+ @Property()
27
+ id!: string;
28
+ }
29
+
30
+ class ClassTools {
31
+ async noReturns({a, b}: {a: number; b: number}) {
32
+ return {content: [{type: "text", text: String(a + b)}]};
33
+ }
34
+
35
+ @Returns(200, ToolResult)
36
+ async withReturns() {
37
+ return {id: "id"};
38
+ }
39
+ }
40
+
25
41
  describe("defineTool", () => {
26
42
  beforeEach(() => PlatformTest.create());
27
43
  afterEach(() => PlatformTest.reset());
@@ -186,4 +202,23 @@ describe("defineTool", () => {
186
202
 
187
203
  await runInContext(PlatformTest.createRequestContext(), () => definition.handler(args, {} as any));
188
204
  });
205
+
206
+ it("should not expose an output schema when the class method declares no @Returns", () => {
207
+ const token = defineTool({token: ClassTools, propertyKey: "noReturns", name: "no-returns"});
208
+
209
+ expect(inject<any>(token).outputSchema).toBeUndefined();
210
+ });
211
+
212
+ it("should expose the output schema declared with @Returns", () => {
213
+ const token = defineTool({token: ClassTools, propertyKey: "withReturns", name: "with-returns"});
214
+
215
+ expect(inject<any>(token).outputSchema["~standard"].jsonSchema.input({target: "draft-2020-12"})).toMatchObject({
216
+ type: "object",
217
+ properties: {
218
+ id: {
219
+ type: "string"
220
+ }
221
+ }
222
+ });
223
+ });
189
224
  });
@@ -63,10 +63,16 @@ type MappedToolOptions<Input, Output = unknown> = Omit<ToolProps<Input, Output>,
63
63
  outputStore?: JsonMethodStore;
64
64
  };
65
65
 
66
- function getOutputSchema<Output>(methodStore: JsonMethodStore): JsonSchema<Output> {
66
+ function getOutputSchema<Output>(methodStore: JsonMethodStore): JsonSchema<Output> | undefined {
67
67
  const schema: JsonSchema = methodStore.operation.getResponseOf(200)?.getMedia("application/json")?.get("schema");
68
68
 
69
- return schema?.itemSchema() as JsonSchema<Output>;
69
+ // Without @Returns, the schema is inferred from design:returntype (e.g. Promise) and is empty.
70
+ // An empty output schema would force the SDK to require structuredContent on every call.
71
+ if (!schema || !Object.keys(schema.toJSON()).length) {
72
+ return undefined;
73
+ }
74
+
75
+ return schema.itemSchema() as JsonSchema<Output>;
70
76
  }
71
77
 
72
78
  function getInputSchema<Input>(token: Type<any> | AbstractType<any>, propertyKey: string | symbol): JsonSchema<Input> {