@tsed/platform-mcp 8.33.0 → 8.35.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.
Files changed (35) hide show
  1. package/lib/esm/decorators/prompt.js +1 -1
  2. package/lib/esm/decorators/resource.js +1 -1
  3. package/lib/esm/decorators/tool.js +1 -1
  4. package/lib/esm/fn/definePrompt.js +3 -3
  5. package/lib/esm/fn/defineResource.js +3 -3
  6. package/lib/esm/fn/defineTool.js +6 -6
  7. package/lib/esm/services/McpServerFactory.js +1 -1
  8. package/lib/esm/services/PlatformMcpModule.js +3 -3
  9. package/lib/esm/utils/toZod.js +1 -1
  10. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  11. package/lib/types/decorators/resource.d.ts +1 -1
  12. package/lib/types/fn/definePrompt.d.ts +3 -3
  13. package/lib/types/fn/defineTool.d.ts +3 -3
  14. package/lib/types/interfaces/PlatformMcpSettings.d.ts +1 -1
  15. package/lib/types/services/PlatformMcpModule.d.ts +1 -1
  16. package/package.json +9 -10
  17. package/src/decorators/prompt.spec.ts +1 -2
  18. package/src/decorators/prompt.ts +1 -2
  19. package/src/decorators/resource.spec.ts +1 -2
  20. package/src/decorators/resource.ts +1 -2
  21. package/src/decorators/tool.spec.ts +1 -2
  22. package/src/decorators/tool.ts +1 -2
  23. package/src/fn/definePrompt.spec.ts +2 -3
  24. package/src/fn/definePrompt.ts +6 -7
  25. package/src/fn/defineResource.spec.ts +2 -3
  26. package/src/fn/defineResource.ts +4 -5
  27. package/src/fn/defineTool.spec.ts +4 -5
  28. package/src/fn/defineTool.ts +9 -10
  29. package/src/interfaces/PlatformMcpSettings.ts +1 -1
  30. package/src/services/McpServerFactory.ts +4 -5
  31. package/src/services/PlatformMcpModule.spec.ts +3 -5
  32. package/src/services/PlatformMcpModule.ts +4 -5
  33. package/src/utils/toZod.spec.ts +1 -2
  34. package/src/utils/toZod.ts +1 -1
  35. package/vitest.config.mts +1 -1
@@ -1,5 +1,5 @@
1
- import type { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
2
1
  import { type ClassResourceReadProps } from "../fn/defineResource.js";
2
+ import type { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
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,8 @@
1
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
2
- import type { GetPromptResult, ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
3
1
  import { type AbstractType, type Type } from "@tsed/core";
4
- import { type TokenProvider } from "@tsed/di";
2
+ import type { GetPromptResult, ServerNotification, ServerRequest } from "@modelcontextprotocol/sdk/types.js";
5
3
  import { JsonSchema } from "@tsed/schema";
4
+ import { type TokenProvider } from "@tsed/di";
5
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
6
6
  type BasePromptConfig = {
7
7
  title?: string;
8
8
  description?: string;
@@ -1,8 +1,8 @@
1
- import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
2
- import type { CallToolResult, ServerNotification, ServerRequest, Tool, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
3
1
  import { type AbstractType, type Type } from "@tsed/core";
4
- import { type TokenProvider } from "@tsed/di";
2
+ import type { CallToolResult, ServerNotification, ServerRequest, Tool, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
5
3
  import { JsonSchema } from "@tsed/schema";
4
+ import { type TokenProvider } from "@tsed/di";
5
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
6
6
  /**
7
7
  * Signature implemented by MCP tool handlers invoked through {@link defineTool}.
8
8
  *
@@ -1,6 +1,6 @@
1
+ import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
1
2
  import type { ServerOptions } from "@modelcontextprotocol/sdk/server/index.js";
2
3
  import type { StreamableHTTPServerTransportOptions } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
3
- import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
4
4
  import type { TokenProvider } from "@tsed/di";
5
5
  /**
6
6
  * Configuration fragment accepted under `configuration.mcp` to wire the Platform MCP module.
@@ -1,5 +1,5 @@
1
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
1
  import { type OnRoutesInit, PlatformContext, type PlatformRouteDetails } from "@tsed/platform-http";
2
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
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.
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@tsed/platform-mcp",
3
+ "version": "8.35.0",
3
4
  "description": "Model Context Protocol integration for Ts.ED HTTP adapters.",
4
- "type": "module",
5
- "version": "8.33.0",
6
5
  "source": "./src/index.ts",
6
+ "type": "module",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
9
9
  "typings": "./lib/types/index.d.ts",
@@ -32,14 +32,13 @@
32
32
  "zod": ">=4.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@tsed/barrels": "8.33.0",
36
- "@tsed/core": "8.33.0",
37
- "@tsed/di": "8.33.0",
38
- "@tsed/json-mapper": "8.33.0",
39
- "@tsed/platform-http": "8.33.0",
40
- "@tsed/schema": "8.33.0",
41
- "@tsed/typescript": "8.33.0",
42
- "eslint": "9.12.0",
35
+ "@tsed/barrels": "8.35.0",
36
+ "@tsed/core": "8.35.0",
37
+ "@tsed/di": "8.35.0",
38
+ "@tsed/json-mapper": "8.35.0",
39
+ "@tsed/platform-http": "8.35.0",
40
+ "@tsed/schema": "8.35.0",
41
+ "@tsed/typescript": "8.35.0",
43
42
  "typescript": "6.0.2",
44
43
  "vitest": "4.1.4"
45
44
  },
@@ -1,6 +1,5 @@
1
- import {DITest, inject, Injectable} from "@tsed/di";
1
+ import {DITest, Injectable, inject} from "@tsed/di";
2
2
  import {Description, Title} from "@tsed/schema";
3
-
4
3
  import {Prompt} from "./prompt.js";
5
4
 
6
5
  @Injectable()
@@ -1,6 +1,5 @@
1
- import {classOf} from "@tsed/core";
2
-
3
1
  import {type ClassPromptProps, definePrompt} from "../fn/definePrompt.js";
2
+ import {classOf} from "@tsed/core";
4
3
 
5
4
  /**
6
5
  * Options accepted by {@link Prompt} when decorating a class method. Matches {@link PromptProps} minus the handler reference.
@@ -1,6 +1,5 @@
1
- import {DITest, inject, Injectable} from "@tsed/di";
2
1
  import {ContentType, Description, Title} from "@tsed/schema";
3
-
2
+ import {DITest, Injectable, inject} from "@tsed/di";
4
3
  import {Resource} from "./resource.js";
5
4
 
6
5
  @Injectable()
@@ -1,9 +1,8 @@
1
+ import {type ClassResourceReadProps, type ClassResourceTemplateProps, defineResource} from "../fn/defineResource.js";
1
2
  import type {ResourceTemplate} from "@modelcontextprotocol/sdk/server/mcp.js";
2
3
  import {classOf} from "@tsed/core";
3
4
  import {isString} from "@tsed/core/utils/isString.js";
4
5
 
5
- import {type ClassResourceReadProps, type ClassResourceTemplateProps, defineResource} from "../fn/defineResource.js";
6
-
7
6
  /**
8
7
  * Options accepted by the {@link Resource} decorator beyond the handler binding fields, allowing callers to override metadata.
9
8
  *
@@ -1,6 +1,5 @@
1
- import {DITest, inject, Injectable} from "@tsed/di";
2
1
  import {CollectionOf, Default, Description, Name, Property, Returns} from "@tsed/schema";
3
-
2
+ import {DITest, Injectable, inject} from "@tsed/di";
4
3
  import {Tool} from "./tool.js";
5
4
 
6
5
  class Model {
@@ -1,6 +1,5 @@
1
- import {classOf} from "@tsed/core";
2
-
3
1
  import {type ClassToolProps, defineTool} from "../fn/defineTool.js";
2
+ import {classOf} from "@tsed/core";
4
3
 
5
4
  /**
6
5
  * Decorator that registers a class method as an MCP tool and binds it to the Ts.ED DI container.
@@ -1,8 +1,7 @@
1
- import {inject} from "@tsed/di";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
1
  import {afterEach, beforeEach, describe, expect, it} from "vitest";
4
-
2
+ import {PlatformTest} from "@tsed/platform-http/testing";
5
3
  import {definePrompt} from "./definePrompt.js";
4
+ import {inject} from "@tsed/di";
6
5
 
7
6
  describe("definePrompt", () => {
8
7
  beforeEach(() => PlatformTest.create());
@@ -1,11 +1,10 @@
1
- import type {RequestHandlerExtra} from "@modelcontextprotocol/sdk/shared/protocol.js";
1
+ import {type AbstractType, type Type, isArrowFn} from "@tsed/core";
2
2
  import type {GetPromptResult, ServerNotification, ServerRequest} from "@modelcontextprotocol/sdk/types.js";
3
- import {type AbstractType, isArrowFn, type Type} from "@tsed/core";
4
- import {context, inject, injectable, logger, type TokenProvider} from "@tsed/di";
5
- import {JsonEntityStore, JsonSchema} from "@tsed/schema";
6
- import {constantCase} from "change-case";
7
-
3
+ import {JsonSchema, s} from "@tsed/schema";
4
+ import {type TokenProvider, context, inject, injectable, logger} from "@tsed/di";
8
5
  import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
6
+ import type {RequestHandlerExtra} from "@modelcontextprotocol/sdk/shared/protocol.js";
7
+ import {constantCase} from "change-case";
9
8
  import {toZod} from "../utils/toZod.js";
10
9
 
11
10
  type BasePromptConfig = {
@@ -57,7 +56,7 @@ function mapOptions<Args = any>(options: PromptProps<Args>) {
57
56
  return instance[propertyKey](...args);
58
57
  }) as unknown as PromptHandler<Args>;
59
58
 
60
- const methodStore = JsonEntityStore.fromMethod(token, propertyKey);
59
+ const methodStore = s.store.method(token, propertyKey);
61
60
  options.description = options.description || methodStore.operation.get("description");
62
61
  options.title = options.title || methodStore.schema.get("title");
63
62
  }
@@ -1,8 +1,7 @@
1
- import {inject} from "@tsed/di";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
1
  import {afterEach, beforeEach, describe, expect, it} from "vitest";
4
-
2
+ import {PlatformTest} from "@tsed/platform-http/testing";
5
3
  import {defineResource} from "./defineResource.js";
4
+ import {inject} from "@tsed/di";
6
5
 
7
6
  describe("defineResource", () => {
8
7
  beforeEach(() => PlatformTest.create());
@@ -1,9 +1,8 @@
1
1
  import type {ReadResourceCallback, ResourceMetadata, ResourceTemplate} from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import {context, inject, injectable, logger, type TokenProvider} from "@tsed/di";
3
- import {JsonEntityStore} from "@tsed/schema";
4
- import {constantCase} from "change-case";
5
-
2
+ import {type TokenProvider, context, inject, injectable, logger} from "@tsed/di";
6
3
  import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
4
+ import {constantCase} from "change-case";
5
+ import {s} from "@tsed/schema";
7
6
 
8
7
  type ResourceMetadataProps = ResourceMetadata & {
9
8
  name: string;
@@ -57,7 +56,7 @@ function mapOptions(options: ResourceProps) {
57
56
  return instance[propertyKey](...args);
58
57
  };
59
58
 
60
- const methodStore = JsonEntityStore.fromMethod(token, propertyKey);
59
+ const methodStore = s.store.method(token, propertyKey);
61
60
  options.description = options.description || methodStore.operation.get("description");
62
61
  options.title = options.title || methodStore.schema.get("title");
63
62
  } else {
@@ -1,9 +1,8 @@
1
- import {inject} from "@tsed/di";
2
- import {PlatformTest} from "@tsed/platform-http/testing";
3
- import {Default, from, JsonSchema, Name, Property} from "@tsed/schema";
1
+ import {Default, JsonSchema, Name, Property, from} from "@tsed/schema";
4
2
  import {afterEach, beforeEach, describe, expect, it} from "vitest";
5
-
3
+ import {PlatformTest} from "@tsed/platform-http/testing";
6
4
  import {defineTool} from "./defineTool.js";
5
+ import {inject} from "@tsed/di";
7
6
 
8
7
  class KnowledgeSearchRequest {
9
8
  @Property()
@@ -75,7 +74,7 @@ describe("defineTool", () => {
75
74
  it("should expose aliased input schema properties", () => {
76
75
  const token = defineTool<any>({
77
76
  name: "aliased-tool",
78
- inputSchema: JsonSchema.from({
77
+ inputSchema: new JsonSchema({
79
78
  type: "object",
80
79
  properties: {
81
80
  prop: {
@@ -1,12 +1,11 @@
1
- import type {RequestHandlerExtra} from "@modelcontextprotocol/sdk/shared/protocol.js";
1
+ import {type AbstractType, type Type, isArrowFn, isClass} from "@tsed/core";
2
2
  import type {CallToolResult, ServerNotification, ServerRequest, Tool, ToolAnnotations} from "@modelcontextprotocol/sdk/types.js";
3
- import {type AbstractType, isArrowFn, isClass, type Type} from "@tsed/core";
4
- import {context, inject, injectable, logger, type TokenProvider} from "@tsed/di";
5
- import {deserialize} from "@tsed/json-mapper";
6
- import {JsonEntityStore, JsonMethodStore, JsonSchema} from "@tsed/schema";
7
- import {constantCase} from "change-case";
8
-
3
+ import {JsonEntityStore, JsonMethodStore, JsonSchema, s} from "@tsed/schema";
4
+ import {type TokenProvider, context, inject, injectable, logger} from "@tsed/di";
9
5
  import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
6
+ import type {RequestHandlerExtra} from "@modelcontextprotocol/sdk/shared/protocol.js";
7
+ import {constantCase} from "change-case";
8
+ import {deserialize} from "@tsed/json-mapper";
10
9
  import {toZod} from "../utils/toZod.js";
11
10
 
12
11
  /**
@@ -70,7 +69,7 @@ function getOutputSchema<Output>(methodStore: JsonMethodStore): JsonSchema<Outpu
70
69
  }
71
70
 
72
71
  function getInputSchema<Input>(token: Type<any> | AbstractType<any>, propertyKey: string | symbol): JsonSchema<Input> {
73
- return JsonEntityStore.from(token, propertyKey, 0).schema?.itemSchema() as JsonSchema<Input>;
72
+ return s.store(token, propertyKey, 0).schema?.itemSchema() as JsonSchema<Input>;
74
73
  }
75
74
 
76
75
  function resolveInputSchema<Input>(inputSchema: JsonSchema<Input> | (() => JsonSchema<Input>) | Tool["inputSchema"] | undefined) {
@@ -101,13 +100,13 @@ function mapOptions<Input, Output = undefined>(options: ToolProps<Input, Output>
101
100
 
102
101
  if ("propertyKey" in options) {
103
102
  const {token, propertyKey} = options;
104
- inputStore = JsonEntityStore.from(token, propertyKey, 0);
103
+ inputStore = s.store(token, propertyKey, 0);
105
104
  handler = (args: Input, extra: any) => {
106
105
  const instance = inject(options.token) as any;
107
106
  return instance[options.propertyKey](args, extra);
108
107
  };
109
108
 
110
- const methodStore = JsonEntityStore.fromMethod(token, propertyKey);
109
+ const methodStore = s.store.method(token, propertyKey);
111
110
  options.description = options.description || methodStore.operation.get("description");
112
111
  options.inputSchema =
113
112
  options.inputSchema || ((inputStore.schema?.itemSchema() || getInputSchema(token, propertyKey)) as JsonSchema<Input>);
@@ -1,6 +1,6 @@
1
+ import type {Implementation} from "@modelcontextprotocol/sdk/types.js";
1
2
  import type {ServerOptions} from "@modelcontextprotocol/sdk/server/index.js";
2
3
  import type {StreamableHTTPServerTransportOptions} from "@modelcontextprotocol/sdk/server/streamableHttp.js";
3
- import type {Implementation} from "@modelcontextprotocol/sdk/types.js";
4
4
  import type {TokenProvider} from "@tsed/di";
5
5
 
6
6
  /**
@@ -1,12 +1,11 @@
1
- import type {ResourceTemplate} from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import {McpServer} from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import {constant, inject, injectable, injector, type TokenProvider} from "@tsed/di";
4
-
1
+ import {type TokenProvider, constant, inject, injectable, injector} from "@tsed/di";
5
2
  import {MCP_PROVIDER_TYPES} from "../constants/constants.js";
3
+ import {McpServer} from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import type {PlatformMcpSettings} from "../interfaces/PlatformMcpSettings.js";
6
5
  import type {PromptsSettings} from "../fn/definePrompt.js";
7
6
  import type {ResourceSettings} from "../fn/defineResource.js";
7
+ import type {ResourceTemplate} from "@modelcontextprotocol/sdk/server/mcp.js";
8
8
  import type {ToolProps} from "../fn/defineTool.js";
9
- import type {PlatformMcpSettings} from "../interfaces/PlatformMcpSettings.js";
10
9
 
11
10
  function collectTokens(type: string, configured: TokenProvider[] = []): TokenProvider[] {
12
11
  const tokens = new Set<TokenProvider>(configured);
@@ -1,11 +1,9 @@
1
+ import {afterEach, beforeEach, describe, expect, it, vi} from "vitest";
1
2
  import {EventEmitter} from "node:events";
2
-
3
3
  import {PlatformFastifyResponse} from "@tsed/platform-fastify";
4
- import {application} from "@tsed/platform-http";
5
- import {PlatformTest} from "@tsed/platform-http/testing";
6
- import {afterEach, beforeEach, describe, expect, it, vi} from "vitest";
7
-
8
4
  import {PlatformMcpModule} from "./PlatformMcpModule.js";
5
+ import {PlatformTest} from "@tsed/platform-http/testing";
6
+ import {application} from "@tsed/platform-http";
9
7
 
10
8
  const {TestTransport, transportInstances} = vi.hoisted(() => {
11
9
  const transportInstances: TestTransport[] = [];
@@ -1,12 +1,11 @@
1
+ import {type OnRoutesInit, PlatformContext, type PlatformRouteDetails, application} from "@tsed/platform-http";
2
+ import {constant, inject, injectable} from "@tsed/di";
3
+ import {MCP_SERVER} from "./McpServerFactory.js";
1
4
  import type {McpServer} from "@modelcontextprotocol/sdk/server/mcp.js";
5
+ import type {PlatformMcpSettings} from "../interfaces/PlatformMcpSettings.js";
2
6
  import {StreamableHTTPServerTransport} from "@modelcontextprotocol/sdk/server/streamableHttp.js";
3
- import {constant, inject, injectable} from "@tsed/di";
4
- import {application, type OnRoutesInit, PlatformContext, type PlatformRouteDetails} from "@tsed/platform-http";
5
7
  import {useContextHandler} from "@tsed/platform-router";
6
8
 
7
- import type {PlatformMcpSettings} from "../interfaces/PlatformMcpSettings.js";
8
- import {MCP_SERVER} from "./McpServerFactory.js";
9
-
10
9
  /**
11
10
  * Platform module that mounts the MCP HTTP endpoint and forwards requests to the configured server instance.
12
11
  *
@@ -1,5 +1,4 @@
1
1
  import {JsonSchema, s, string} from "@tsed/schema";
2
-
3
2
  import {toZod} from "./toZod.js";
4
3
 
5
4
  describe("toZod", () => {
@@ -14,7 +13,7 @@ describe("toZod", () => {
14
13
  });
15
14
 
16
15
  it("should preserve aliases when useAlias is enabled", () => {
17
- const schema = JsonSchema.from({
16
+ const schema = new JsonSchema({
18
17
  type: "object",
19
18
  properties: {
20
19
  prop: {
@@ -1,6 +1,6 @@
1
1
  import {JsonSchema, JsonSchemaOptions} from "@tsed/schema";
2
+ import {type ZodObject, z} from "zod";
2
3
  import {jsonSchemaToZod} from "json-schema-to-zod";
3
- import {z, type ZodObject} from "zod";
4
4
 
5
5
  function transform(schema: JsonSchema, opts?: JsonSchemaOptions): ZodObject {
6
6
  const schemaFactory = new Function("z", `return ${jsonSchemaToZod(schema.toJSON(opts), {zodVersion: 4})}`) as (zod: unknown) => ZodObject;
package/vitest.config.mts CHANGED
@@ -1,6 +1,6 @@
1
+ import {defineConfig} from "vitest/config";
1
2
  // @ts-ignore
2
3
  import {presets} from "@tsed/vitest/presets";
3
- import {defineConfig} from "vitest/config";
4
4
 
5
5
  export default defineConfig({
6
6
  ...presets,