@tsed/platform-mcp 8.28.1 → 8.28.2

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.
@@ -1,6 +1,7 @@
1
1
  import { isArrowFn } from "@tsed/core";
2
- import { inject, injectable } from "@tsed/di";
2
+ import { context, inject, injectable, logger } from "@tsed/di";
3
3
  import { JsonEntityStore } from "@tsed/schema";
4
+ import { constantCase } from "change-case";
4
5
  import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
5
6
  import { toZod } from "../utils/toZod.js";
6
7
  function mapOptions(options) {
@@ -30,7 +31,38 @@ export function definePrompt(options) {
30
31
  const provider = injectable(Symbol.for(`MCP:PROMPT:${options.name}`))
31
32
  .type(MCP_PROVIDER_TYPES.PROMPT)
32
33
  .factory(() => {
33
- return mapOptions(options);
34
+ const { handler, ...opts } = mapOptions(options);
35
+ return {
36
+ ...opts,
37
+ async handler(...args) {
38
+ try {
39
+ return await handler(...args);
40
+ }
41
+ catch (er) {
42
+ const code = er.name && er.status ? `E_MCP_PROMPT_${constantCase(er.name)}` : "E_MCP_PROMPT_ERROR";
43
+ logger().error({
44
+ event: "MCP_PROMPT_ERROR",
45
+ status_code: er.status,
46
+ code,
47
+ error_name: er.name,
48
+ message: er.message,
49
+ request_id: context().id,
50
+ prompt: opts.name
51
+ });
52
+ return {
53
+ description: er.message,
54
+ messages: [],
55
+ _meta: {
56
+ status_code: er.status,
57
+ code,
58
+ message: er.message,
59
+ request_id: context().id,
60
+ prompt: opts.name
61
+ }
62
+ };
63
+ }
64
+ }
65
+ };
34
66
  });
35
67
  return provider.token();
36
68
  }
@@ -1,5 +1,6 @@
1
- import { inject, injectable } from "@tsed/di";
1
+ import { context, inject, injectable, logger } from "@tsed/di";
2
2
  import { JsonEntityStore } from "@tsed/schema";
3
+ import { constantCase } from "change-case";
3
4
  import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
4
5
  function isClassResourceProps(options) {
5
6
  return "token" in options && "propertyKey" in options;
@@ -30,7 +31,45 @@ export function defineResource(options) {
30
31
  const provider = injectable(Symbol.for(`MCP:RESOURCE:${options.name}`))
31
32
  .type(MCP_PROVIDER_TYPES.RESOURCE)
32
33
  .factory(() => {
33
- return mapOptions(options);
34
+ const { handler, ...opts } = mapOptions(options);
35
+ return {
36
+ ...opts,
37
+ async handler(...args) {
38
+ try {
39
+ return await handler(...args);
40
+ }
41
+ catch (er) {
42
+ const safeErr = er && typeof er === "object"
43
+ ? er
44
+ : {
45
+ message: String(er),
46
+ name: undefined,
47
+ status: undefined
48
+ };
49
+ const code = safeErr.name && safeErr.status ? `E_MCP_RESOURCE_${constantCase(safeErr.name)}` : "E_MCP_RESOURCE_ERROR";
50
+ logger().error({
51
+ event: "MCP_RESOURCE_ERROR",
52
+ status_code: safeErr.status,
53
+ code,
54
+ error_name: safeErr.name,
55
+ message: safeErr.message,
56
+ request_id: context().id,
57
+ resource: opts.name
58
+ });
59
+ return {
60
+ contents: [],
61
+ _meta: {
62
+ status_code: safeErr.status,
63
+ code,
64
+ error_name: safeErr.name,
65
+ message: safeErr.message,
66
+ request_id: context().id,
67
+ resource: opts.name
68
+ }
69
+ };
70
+ }
71
+ }
72
+ };
34
73
  });
35
74
  return provider.token();
36
75
  }
@@ -1,6 +1,7 @@
1
1
  import { isArrowFn } from "@tsed/core";
2
- import { inject, injectable, logger } from "@tsed/di";
2
+ import { context, inject, injectable, logger } from "@tsed/di";
3
3
  import { JsonEntityStore } from "@tsed/schema";
4
+ import { constantCase } from "change-case";
4
5
  import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
5
6
  import { toZod } from "../utils/toZod.js";
6
7
  function getOutputSchema(methodStore) {
@@ -46,17 +47,24 @@ export function defineTool(options) {
46
47
  return await handler(args, extra);
47
48
  }
48
49
  catch (er) {
50
+ const code = er.name && er.status ? `E_MCP_TOOL_${constantCase(er.name)}` : "E_MCP_TOOL_ERROR";
49
51
  logger().error({
50
52
  event: "MCP_TOOL_ERROR",
51
- tool: opts.name,
52
- error_message: er?.message,
53
- stack: er?.stack
53
+ status_code: er.status,
54
+ code,
55
+ error_name: er.name,
56
+ message: er.message,
57
+ request_id: context().id,
58
+ tool: opts.name
54
59
  });
55
60
  return {
56
61
  content: [],
57
62
  structuredContent: {
58
- code: "E_MCP_TOOL_ERROR",
59
- message: er?.message
63
+ status_code: er.status,
64
+ code,
65
+ message: er.message,
66
+ request_id: context().id,
67
+ tool: opts.name
60
68
  }
61
69
  };
62
70
  }
@@ -19,10 +19,15 @@ export const MCP_SERVER = injectable(McpServer)
19
19
  const settings = constant("mcp", {}) || {};
20
20
  const name = settings.name || constant("name") || "tsed-mcp";
21
21
  const version = settings.version || constant("version") || "0.0.0";
22
+ const { websiteUrl, description, title, icons } = settings;
22
23
  const server = new McpServer({
24
+ websiteUrl,
25
+ description,
26
+ icons,
27
+ title,
23
28
  name,
24
29
  version
25
- });
30
+ }, settings?.serverOptions);
26
31
  const toolTokens = collectTokens(MCP_PROVIDER_TYPES.TOOL, settings.tools);
27
32
  toolTokens.forEach((token) => {
28
33
  const definition = inject(token);