@tsed/platform-mcp 8.38.2 → 8.38.5
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/common/fn/definePrompt.js +4 -2
- package/lib/esm/common/fn/defineResource.js +4 -6
- package/lib/esm/common/fn/defineTool.js +2 -4
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/common/fn/definePrompt.spec.ts +19 -1
- package/src/common/fn/definePrompt.ts +5 -2
- package/src/common/fn/defineResource.spec.ts +20 -1
- package/src/common/fn/defineResource.ts +5 -7
- package/src/common/fn/defineTool.spec.ts +18 -1
- package/src/common/fn/defineTool.ts +3 -5
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isArrowFn } from "@tsed/core";
|
|
2
2
|
import { s } from "@tsed/schema";
|
|
3
|
-
import { context, inject, injectable
|
|
3
|
+
import { context, inject, injectable } from "@tsed/di";
|
|
4
4
|
import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
|
|
5
5
|
import { constantCase } from "change-case";
|
|
6
6
|
import { fromJsonSchema } from "../utils/fromJsonSchema.js";
|
|
@@ -39,11 +39,13 @@ export function definePrompt(options) {
|
|
|
39
39
|
...opts,
|
|
40
40
|
async handler(...args) {
|
|
41
41
|
try {
|
|
42
|
+
context()?.set("mcp", opts);
|
|
43
|
+
context()?.set("mcp_args", args);
|
|
42
44
|
return await handler(...args);
|
|
43
45
|
}
|
|
44
46
|
catch (er) {
|
|
45
47
|
const code = er.name && er.status ? `E_MCP_PROMPT_${constantCase(er.name)}` : "E_MCP_PROMPT_ERROR";
|
|
46
|
-
|
|
48
|
+
context().logger.error({
|
|
47
49
|
event: "MCP_PROMPT_ERROR",
|
|
48
50
|
status_code: er.status,
|
|
49
51
|
code,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { context, inject, injectable
|
|
1
|
+
import { context, inject, injectable } from "@tsed/di";
|
|
2
2
|
import { MCP_PROVIDER_TYPES } from "../constants/constants.js";
|
|
3
3
|
import { constantCase } from "change-case";
|
|
4
4
|
import { s } from "@tsed/schema";
|
|
@@ -37,11 +37,9 @@ export function defineResource(options) {
|
|
|
37
37
|
...opts,
|
|
38
38
|
async handler(...args) {
|
|
39
39
|
try {
|
|
40
|
+
context()?.set("mcp", opts);
|
|
41
|
+
context()?.set("mcp_args", args);
|
|
40
42
|
const result = await handler(...args);
|
|
41
|
-
logger().info({
|
|
42
|
-
event: "MCP_TOOL_END",
|
|
43
|
-
tool: opts.name
|
|
44
|
-
});
|
|
45
43
|
return asResourceResponse(args[0]?.toString(), result);
|
|
46
44
|
}
|
|
47
45
|
catch (er) {
|
|
@@ -53,7 +51,7 @@ export function defineResource(options) {
|
|
|
53
51
|
status: undefined
|
|
54
52
|
};
|
|
55
53
|
const code = safeErr.name && safeErr.status ? `E_MCP_RESOURCE_${constantCase(safeErr.name)}` : "E_MCP_RESOURCE_ERROR";
|
|
56
|
-
|
|
54
|
+
context().logger.error({
|
|
57
55
|
event: "MCP_RESOURCE_ERROR",
|
|
58
56
|
status_code: safeErr.status,
|
|
59
57
|
code,
|
|
@@ -74,11 +74,9 @@ export function defineTool(options) {
|
|
|
74
74
|
}),
|
|
75
75
|
async handler(args, ctx) {
|
|
76
76
|
try {
|
|
77
|
+
context()?.set("mcp", opts);
|
|
78
|
+
context()?.set("mcp_args", args);
|
|
77
79
|
const result = await handler(deserializeInput(args, inputSchema, inputStore), ctx);
|
|
78
|
-
logger().info({
|
|
79
|
-
event: "MCP_TOOL_END",
|
|
80
|
-
tool: opts.name
|
|
81
|
-
});
|
|
82
80
|
return asToolResponse(result);
|
|
83
81
|
}
|
|
84
82
|
catch (er) {
|