@lovable.dev/mcp-js 0.29.0-rc.1 → 0.29.0-rc.3
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/README.internal.md +22 -31
- package/README.md +23 -13
- package/dist/{authorize-BjNE3LPr.d.ts → authorize-9hTTG-qJ.d.cts} +2 -5
- package/dist/{authorize-BzZFS0zi.d.cts → authorize-DNUlPT7k.d.ts} +2 -5
- package/dist/{base-C8osWdMU.d.cts → base-7cq6HCPO.d.ts} +3 -2
- package/dist/{base-C8osWdMU.d.ts → base-CHNFFrMG.d.cts} +3 -2
- package/dist/cli/extract-manifest.cjs +25 -3
- package/dist/cli/extract-manifest.js +24 -2
- package/dist/{cors-BRv5KXKQ.cjs → cors-BDv7pyfD.cjs} +26 -30
- package/dist/{cors-BDTQQJE2.js → cors-kKiIJSyL.js} +21 -25
- package/dist/{errors-DSe96Ffd.js → errors-Bwd1L0Rf.js} +23 -8
- package/dist/{errors-CN6Da8iz.cjs → errors-Cr95rSkB.cjs} +23 -8
- package/dist/forwarded-Bnrwxbuj.js +25 -0
- package/dist/forwarded-OdBzzCMF.cjs +30 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{io-BYUyNFdn.d.ts → io-CDV3mud0.d.cts} +1 -1
- package/dist/{io-B_YLNWDL.d.cts → io-D_5cuaEL.d.ts} +1 -1
- package/dist/mcp-BSNdmnJl.cjs +353 -0
- package/dist/mcp-GT9WU7nd.js +348 -0
- package/dist/{package-BI5r4uGM.js → package-2ZppkCKf.js} +1 -1
- package/dist/{package-ClCIqol1.cjs → package-DAQNwT8T.cjs} +1 -1
- package/dist/protocols/mcp/index.cjs +1 -1
- package/dist/protocols/mcp/index.d.cts +3 -3
- package/dist/protocols/mcp/index.d.ts +3 -3
- package/dist/protocols/mcp/index.js +1 -1
- package/dist/protocols/oauth-metadata.cjs +18 -3
- package/dist/protocols/oauth-metadata.d.cts +4 -3
- package/dist/protocols/oauth-metadata.d.ts +4 -3
- package/dist/protocols/oauth-metadata.js +18 -3
- package/dist/stacks/supabase/index.cjs +7 -36
- package/dist/stacks/supabase/index.d.cts +1 -4
- package/dist/stacks/supabase/index.d.ts +1 -4
- package/dist/stacks/supabase/index.js +7 -36
- package/dist/stacks/supabase/vite.cjs +1 -1
- package/dist/stacks/supabase/vite.d.cts +1 -1
- package/dist/stacks/supabase/vite.d.ts +1 -1
- package/dist/stacks/supabase/vite.js +1 -1
- package/dist/stacks/tanstack/index.cjs +4 -25
- package/dist/stacks/tanstack/index.d.cts +3 -20
- package/dist/stacks/tanstack/index.d.ts +3 -20
- package/dist/stacks/tanstack/index.js +5 -24
- package/dist/stacks/tanstack/vite.cjs +5 -33
- package/dist/stacks/tanstack/vite.d.cts +5 -28
- package/dist/stacks/tanstack/vite.d.ts +5 -28
- package/dist/stacks/tanstack/vite.js +5 -33
- package/dist/{types-D1cgsnPu.d.cts → types-3CZPz364.d.cts} +54 -26
- package/dist/{types-D1cgsnPu.d.ts → types-3CZPz364.d.ts} +54 -26
- package/package.json +4 -11
- package/dist/forwarded-B3EBjHnA.js +0 -43
- package/dist/forwarded-BC_RHnn5.cjs +0 -48
- package/dist/gate-CAJSRt_t.cjs +0 -26
- package/dist/gate-uCVrbDBb.js +0 -21
- package/dist/list-tools-C1OiTDR9.js +0 -37
- package/dist/list-tools-C3AoI2Zw.d.cts +0 -8
- package/dist/list-tools-DES10avA.cjs +0 -48
- package/dist/list-tools-DXqSPvNY.d.ts +0 -8
- package/dist/mcp-C9B7o75m.cjs +0 -345
- package/dist/mcp-HDkUr85V.js +0 -340
- package/dist/protocols/rest/index.cjs +0 -5
- package/dist/protocols/rest/index.d.cts +0 -9
- package/dist/protocols/rest/index.d.ts +0 -9
- package/dist/protocols/rest/index.js +0 -3
- package/dist/rest-BBdfHMGh.cjs +0 -134
- package/dist/rest-Cr7NhxL3.js +0 -129
- package/dist/tool-result-CK6hXO43.cjs +0 -89
- package/dist/tool-result-DfCk445b.js +0 -78
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { u as McpDefinition } from "../../types-D1cgsnPu.js";
|
|
2
|
-
import { t as MetricsRecorder } from "../../base-C8osWdMU.js";
|
|
3
|
-
import { t as McpRuntimeOptions } from "../../authorize-BjNE3LPr.js";
|
|
4
|
-
import { n as createListToolsHandler, t as RestListToolsHandler } from "../../list-tools-DXqSPvNY.js";
|
|
5
|
-
//#region src/protocols/rest/invoke-tool.d.ts
|
|
6
|
-
type RestInvokeToolHandler = (request: Request, toolName: string, recorder?: MetricsRecorder) => Promise<Response>;
|
|
7
|
-
declare function createInvokeToolHandler(mcp: McpDefinition, options?: McpRuntimeOptions): RestInvokeToolHandler;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { type RestInvokeToolHandler, type RestListToolsHandler, createInvokeToolHandler, createListToolsHandler };
|
package/dist/rest-BBdfHMGh.cjs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
const require_errors = require("./errors-CN6Da8iz.cjs");
|
|
2
|
-
const require_cors = require("./cors-BRv5KXKQ.cjs");
|
|
3
|
-
const require_tool_result = require("./tool-result-CK6hXO43.cjs");
|
|
4
|
-
const require_gate = require("./gate-CAJSRt_t.cjs");
|
|
5
|
-
require("./list-tools-DES10avA.cjs");
|
|
6
|
-
let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
|
|
7
|
-
//#region src/protocols/rest/invoke-tool.ts
|
|
8
|
-
const MAX_REFLECTED_TOOL_NAME = 256;
|
|
9
|
-
function safeReflectName(name) {
|
|
10
|
-
const text = String(name);
|
|
11
|
-
return text.length > MAX_REFLECTED_TOOL_NAME ? `${text.slice(0, MAX_REFLECTED_TOOL_NAME)}…` : text;
|
|
12
|
-
}
|
|
13
|
-
function isEmptyArgs(value) {
|
|
14
|
-
if (value == null) return true;
|
|
15
|
-
if (typeof value !== "object" || Array.isArray(value)) return false;
|
|
16
|
-
return Object.keys(value).length === 0;
|
|
17
|
-
}
|
|
18
|
-
function createInvokeToolHandler(mcp, options = {}) {
|
|
19
|
-
require_cors.assertRestResourceBinding(mcp, options);
|
|
20
|
-
const handle = async (request, authResult, recorder, toolName) => {
|
|
21
|
-
const endUserId = authResult.auth?.principal.sub;
|
|
22
|
-
const tool = mcp.tools.find((t) => t.name === toolName);
|
|
23
|
-
if (!tool) return new Response(JSON.stringify({ error: `unknown tool: ${safeReflectName(toolName)}` }), {
|
|
24
|
-
status: 404,
|
|
25
|
-
headers: require_cors.JSON_HEADERS
|
|
26
|
-
});
|
|
27
|
-
let rawArgs = {};
|
|
28
|
-
const text = await request.text();
|
|
29
|
-
if (text) try {
|
|
30
|
-
rawArgs = JSON.parse(text);
|
|
31
|
-
} catch {
|
|
32
|
-
return new Response(JSON.stringify({ error: "invalid JSON body" }), {
|
|
33
|
-
status: 400,
|
|
34
|
-
headers: require_cors.JSON_HEADERS
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
let args = rawArgs;
|
|
38
|
-
if (tool.inputSchema) try {
|
|
39
|
-
const parsed = await (0, _modelcontextprotocol_sdk_server_zod_compat_js.safeParseAsync)((0, _modelcontextprotocol_sdk_server_zod_compat_js.objectFromShape)(tool.inputSchema), rawArgs);
|
|
40
|
-
if (!parsed.success) return new Response(JSON.stringify({
|
|
41
|
-
error: "validation failed",
|
|
42
|
-
details: (0, _modelcontextprotocol_sdk_server_zod_compat_js.getParseErrorMessage)(parsed.error)
|
|
43
|
-
}), {
|
|
44
|
-
status: 400,
|
|
45
|
-
headers: require_cors.JSON_HEADERS
|
|
46
|
-
});
|
|
47
|
-
args = parsed.data;
|
|
48
|
-
} catch {
|
|
49
|
-
return new Response(JSON.stringify({
|
|
50
|
-
error: "schema error",
|
|
51
|
-
tool: toolName
|
|
52
|
-
}), {
|
|
53
|
-
status: 500,
|
|
54
|
-
headers: require_cors.JSON_HEADERS
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
else if (!isEmptyArgs(rawArgs)) return new Response(JSON.stringify({ error: "tool has no inputSchema; expected empty body" }), {
|
|
58
|
-
status: 400,
|
|
59
|
-
headers: require_cors.JSON_HEADERS
|
|
60
|
-
});
|
|
61
|
-
let result;
|
|
62
|
-
const start = require_cors.nowMs();
|
|
63
|
-
try {
|
|
64
|
-
result = await tool.handler(args, new require_errors.ToolContext(authResult.auth));
|
|
65
|
-
} catch (err) {
|
|
66
|
-
const callerMessage = require_errors.resolveToolErrorMessage(err);
|
|
67
|
-
if (callerMessage === void 0) {
|
|
68
|
-
await recorder.emit({
|
|
69
|
-
tool: tool.name,
|
|
70
|
-
method: "tools/call",
|
|
71
|
-
outcome: "handler_error",
|
|
72
|
-
durationMs: require_cors.nowMs() - start,
|
|
73
|
-
errorText: require_errors.errorSummary(err),
|
|
74
|
-
endUserId,
|
|
75
|
-
protocol: "rest"
|
|
76
|
-
});
|
|
77
|
-
return new Response(JSON.stringify({
|
|
78
|
-
error: "handler threw",
|
|
79
|
-
tool: toolName
|
|
80
|
-
}), {
|
|
81
|
-
status: 500,
|
|
82
|
-
headers: require_cors.JSON_HEADERS
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
result = {
|
|
86
|
-
content: [{
|
|
87
|
-
type: "text",
|
|
88
|
-
text: callerMessage
|
|
89
|
-
}],
|
|
90
|
-
isError: true
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (result == null) {
|
|
94
|
-
await recorder.emit({
|
|
95
|
-
tool: tool.name,
|
|
96
|
-
method: "tools/call",
|
|
97
|
-
outcome: "handler_error",
|
|
98
|
-
durationMs: require_cors.nowMs() - start,
|
|
99
|
-
endUserId,
|
|
100
|
-
protocol: "rest"
|
|
101
|
-
});
|
|
102
|
-
return new Response(JSON.stringify({ error: `tool "${toolName}" returned no result` }), {
|
|
103
|
-
status: 500,
|
|
104
|
-
headers: require_cors.JSON_HEADERS
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
result = await require_tool_result.finalizeToolResult(tool, result);
|
|
108
|
-
await recorder.emit({
|
|
109
|
-
tool: tool.name,
|
|
110
|
-
method: "tools/call",
|
|
111
|
-
outcome: result.isError ? "tool_error" : "ok",
|
|
112
|
-
durationMs: require_cors.nowMs() - start,
|
|
113
|
-
errorText: result.isError ? require_tool_result.extractTextContent(result.content) : void 0,
|
|
114
|
-
endUserId,
|
|
115
|
-
protocol: "rest"
|
|
116
|
-
});
|
|
117
|
-
return Response.json(result);
|
|
118
|
-
};
|
|
119
|
-
const gated = require_gate.createGatedHandler({
|
|
120
|
-
authorizer: require_cors.createRequestAuthorizer(mcp, options),
|
|
121
|
-
allowedOrigins: mcp.allowedOrigins,
|
|
122
|
-
methods: ["POST"],
|
|
123
|
-
methodNotAllowed: require_cors.methodNotAllowed,
|
|
124
|
-
handle
|
|
125
|
-
});
|
|
126
|
-
return (request, toolName, recorder) => gated(request, recorder, toolName);
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
|
-
Object.defineProperty(exports, "createInvokeToolHandler", {
|
|
130
|
-
enumerable: true,
|
|
131
|
-
get: function() {
|
|
132
|
-
return createInvokeToolHandler;
|
|
133
|
-
}
|
|
134
|
-
});
|
package/dist/rest-Cr7NhxL3.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { i as ToolContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-DSe96Ffd.js";
|
|
2
|
-
import { d as JSON_HEADERS, n as assertRestResourceBinding, p as methodNotAllowed, r as createRequestAuthorizer, u as nowMs } from "./cors-BDTQQJE2.js";
|
|
3
|
-
import { n as extractTextContent, t as finalizeToolResult } from "./tool-result-DfCk445b.js";
|
|
4
|
-
import { t as createGatedHandler } from "./gate-uCVrbDBb.js";
|
|
5
|
-
import "./list-tools-C1OiTDR9.js";
|
|
6
|
-
import { getParseErrorMessage, objectFromShape, safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
7
|
-
//#region src/protocols/rest/invoke-tool.ts
|
|
8
|
-
const MAX_REFLECTED_TOOL_NAME = 256;
|
|
9
|
-
function safeReflectName(name) {
|
|
10
|
-
const text = String(name);
|
|
11
|
-
return text.length > MAX_REFLECTED_TOOL_NAME ? `${text.slice(0, MAX_REFLECTED_TOOL_NAME)}…` : text;
|
|
12
|
-
}
|
|
13
|
-
function isEmptyArgs(value) {
|
|
14
|
-
if (value == null) return true;
|
|
15
|
-
if (typeof value !== "object" || Array.isArray(value)) return false;
|
|
16
|
-
return Object.keys(value).length === 0;
|
|
17
|
-
}
|
|
18
|
-
function createInvokeToolHandler(mcp, options = {}) {
|
|
19
|
-
assertRestResourceBinding(mcp, options);
|
|
20
|
-
const handle = async (request, authResult, recorder, toolName) => {
|
|
21
|
-
const endUserId = authResult.auth?.principal.sub;
|
|
22
|
-
const tool = mcp.tools.find((t) => t.name === toolName);
|
|
23
|
-
if (!tool) return new Response(JSON.stringify({ error: `unknown tool: ${safeReflectName(toolName)}` }), {
|
|
24
|
-
status: 404,
|
|
25
|
-
headers: JSON_HEADERS
|
|
26
|
-
});
|
|
27
|
-
let rawArgs = {};
|
|
28
|
-
const text = await request.text();
|
|
29
|
-
if (text) try {
|
|
30
|
-
rawArgs = JSON.parse(text);
|
|
31
|
-
} catch {
|
|
32
|
-
return new Response(JSON.stringify({ error: "invalid JSON body" }), {
|
|
33
|
-
status: 400,
|
|
34
|
-
headers: JSON_HEADERS
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
let args = rawArgs;
|
|
38
|
-
if (tool.inputSchema) try {
|
|
39
|
-
const parsed = await safeParseAsync(objectFromShape(tool.inputSchema), rawArgs);
|
|
40
|
-
if (!parsed.success) return new Response(JSON.stringify({
|
|
41
|
-
error: "validation failed",
|
|
42
|
-
details: getParseErrorMessage(parsed.error)
|
|
43
|
-
}), {
|
|
44
|
-
status: 400,
|
|
45
|
-
headers: JSON_HEADERS
|
|
46
|
-
});
|
|
47
|
-
args = parsed.data;
|
|
48
|
-
} catch {
|
|
49
|
-
return new Response(JSON.stringify({
|
|
50
|
-
error: "schema error",
|
|
51
|
-
tool: toolName
|
|
52
|
-
}), {
|
|
53
|
-
status: 500,
|
|
54
|
-
headers: JSON_HEADERS
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
else if (!isEmptyArgs(rawArgs)) return new Response(JSON.stringify({ error: "tool has no inputSchema; expected empty body" }), {
|
|
58
|
-
status: 400,
|
|
59
|
-
headers: JSON_HEADERS
|
|
60
|
-
});
|
|
61
|
-
let result;
|
|
62
|
-
const start = nowMs();
|
|
63
|
-
try {
|
|
64
|
-
result = await tool.handler(args, new ToolContext(authResult.auth));
|
|
65
|
-
} catch (err) {
|
|
66
|
-
const callerMessage = resolveToolErrorMessage(err);
|
|
67
|
-
if (callerMessage === void 0) {
|
|
68
|
-
await recorder.emit({
|
|
69
|
-
tool: tool.name,
|
|
70
|
-
method: "tools/call",
|
|
71
|
-
outcome: "handler_error",
|
|
72
|
-
durationMs: nowMs() - start,
|
|
73
|
-
errorText: errorSummary(err),
|
|
74
|
-
endUserId,
|
|
75
|
-
protocol: "rest"
|
|
76
|
-
});
|
|
77
|
-
return new Response(JSON.stringify({
|
|
78
|
-
error: "handler threw",
|
|
79
|
-
tool: toolName
|
|
80
|
-
}), {
|
|
81
|
-
status: 500,
|
|
82
|
-
headers: JSON_HEADERS
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
result = {
|
|
86
|
-
content: [{
|
|
87
|
-
type: "text",
|
|
88
|
-
text: callerMessage
|
|
89
|
-
}],
|
|
90
|
-
isError: true
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (result == null) {
|
|
94
|
-
await recorder.emit({
|
|
95
|
-
tool: tool.name,
|
|
96
|
-
method: "tools/call",
|
|
97
|
-
outcome: "handler_error",
|
|
98
|
-
durationMs: nowMs() - start,
|
|
99
|
-
endUserId,
|
|
100
|
-
protocol: "rest"
|
|
101
|
-
});
|
|
102
|
-
return new Response(JSON.stringify({ error: `tool "${toolName}" returned no result` }), {
|
|
103
|
-
status: 500,
|
|
104
|
-
headers: JSON_HEADERS
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
result = await finalizeToolResult(tool, result);
|
|
108
|
-
await recorder.emit({
|
|
109
|
-
tool: tool.name,
|
|
110
|
-
method: "tools/call",
|
|
111
|
-
outcome: result.isError ? "tool_error" : "ok",
|
|
112
|
-
durationMs: nowMs() - start,
|
|
113
|
-
errorText: result.isError ? extractTextContent(result.content) : void 0,
|
|
114
|
-
endUserId,
|
|
115
|
-
protocol: "rest"
|
|
116
|
-
});
|
|
117
|
-
return Response.json(result);
|
|
118
|
-
};
|
|
119
|
-
const gated = createGatedHandler({
|
|
120
|
-
authorizer: createRequestAuthorizer(mcp, options),
|
|
121
|
-
allowedOrigins: mcp.allowedOrigins,
|
|
122
|
-
methods: ["POST"],
|
|
123
|
-
methodNotAllowed,
|
|
124
|
-
handle
|
|
125
|
-
});
|
|
126
|
-
return (request, toolName, recorder) => gated(request, recorder, toolName);
|
|
127
|
-
}
|
|
128
|
-
//#endregion
|
|
129
|
-
export { createInvokeToolHandler as t };
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
const require_schema = require("./schema-D3vClxb7.cjs");
|
|
2
|
-
let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
|
|
3
|
-
//#region src/core/content.ts
|
|
4
|
-
/** Join the text of a result's `type: "text"` blocks into one string, dropping
|
|
5
|
-
* binary/resource blocks. Used to surface a `tool_error` message in the local
|
|
6
|
-
* log; never sent over the telemetry wire. Returns undefined when there is no
|
|
7
|
-
* text to show. */
|
|
8
|
-
function extractTextContent(content) {
|
|
9
|
-
if (!content) return void 0;
|
|
10
|
-
const text = content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim();
|
|
11
|
-
return text.length > 0 ? text : void 0;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/core/tool-result.ts
|
|
15
|
-
function normalizeResourceLinkIcon(icon) {
|
|
16
|
-
if (typeof icon.sizes !== "string") return icon;
|
|
17
|
-
const { sizes, ...rest } = icon;
|
|
18
|
-
const normalized = sizes.trim();
|
|
19
|
-
return normalized === "" ? rest : {
|
|
20
|
-
...rest,
|
|
21
|
-
sizes: normalized.split(/\s+/)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function normalizeToolContent(content) {
|
|
25
|
-
return (content ?? []).map((block) => {
|
|
26
|
-
if (block.type !== "resource_link" || block.icons === void 0) return block;
|
|
27
|
-
return {
|
|
28
|
-
...block,
|
|
29
|
-
icons: block.icons.map(normalizeResourceLinkIcon)
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function outputValidationError(text) {
|
|
34
|
-
return {
|
|
35
|
-
content: [{
|
|
36
|
-
type: "text",
|
|
37
|
-
text
|
|
38
|
-
}],
|
|
39
|
-
isError: true
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
43
|
-
if (value === null || typeof value === "boolean" || typeof value === "string") return true;
|
|
44
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
45
|
-
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
46
|
-
const prototype = Object.getPrototypeOf(value);
|
|
47
|
-
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return false;
|
|
48
|
-
ancestors.add(value);
|
|
49
|
-
const valid = Object.values(value).every((entry) => isJsonValue(entry, ancestors));
|
|
50
|
-
ancestors.delete(value);
|
|
51
|
-
return valid;
|
|
52
|
-
}
|
|
53
|
-
async function finalizeToolResult(tool, result) {
|
|
54
|
-
const content = normalizeToolContent(result.content);
|
|
55
|
-
let structuredContent = result.structuredContent;
|
|
56
|
-
if (tool.outputSchema && !result.isError) {
|
|
57
|
-
if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
|
|
58
|
-
try {
|
|
59
|
-
const parsed = await (0, _modelcontextprotocol_sdk_server_zod_compat_js.safeParseAsync)(require_schema.schemaFromDefinition(tool.outputSchema), structuredContent);
|
|
60
|
-
if (!parsed.success) return outputValidationError(`Output validation error: Invalid structured content for tool ${tool.name}: ${(0, _modelcontextprotocol_sdk_server_zod_compat_js.getParseErrorMessage)(parsed.error)}`);
|
|
61
|
-
structuredContent = parsed.data;
|
|
62
|
-
} catch {
|
|
63
|
-
return outputValidationError(`Output validation error: Could not validate structured content for tool ${tool.name}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (structuredContent !== void 0 && !isJsonValue(structuredContent)) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
|
|
67
|
-
if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
|
|
68
|
-
type: "text",
|
|
69
|
-
text: JSON.stringify(structuredContent)
|
|
70
|
-
});
|
|
71
|
-
return {
|
|
72
|
-
content,
|
|
73
|
-
structuredContent,
|
|
74
|
-
isError: result.isError
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
Object.defineProperty(exports, "extractTextContent", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function() {
|
|
81
|
-
return extractTextContent;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(exports, "finalizeToolResult", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function() {
|
|
87
|
-
return finalizeToolResult;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { n as schemaFromDefinition } from "./schema-CW1jKvio.js";
|
|
2
|
-
import { getParseErrorMessage, safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
3
|
-
//#region src/core/content.ts
|
|
4
|
-
/** Join the text of a result's `type: "text"` blocks into one string, dropping
|
|
5
|
-
* binary/resource blocks. Used to surface a `tool_error` message in the local
|
|
6
|
-
* log; never sent over the telemetry wire. Returns undefined when there is no
|
|
7
|
-
* text to show. */
|
|
8
|
-
function extractTextContent(content) {
|
|
9
|
-
if (!content) return void 0;
|
|
10
|
-
const text = content.filter((block) => block.type === "text").map((block) => block.text).join("\n").trim();
|
|
11
|
-
return text.length > 0 ? text : void 0;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
//#region src/core/tool-result.ts
|
|
15
|
-
function normalizeResourceLinkIcon(icon) {
|
|
16
|
-
if (typeof icon.sizes !== "string") return icon;
|
|
17
|
-
const { sizes, ...rest } = icon;
|
|
18
|
-
const normalized = sizes.trim();
|
|
19
|
-
return normalized === "" ? rest : {
|
|
20
|
-
...rest,
|
|
21
|
-
sizes: normalized.split(/\s+/)
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function normalizeToolContent(content) {
|
|
25
|
-
return (content ?? []).map((block) => {
|
|
26
|
-
if (block.type !== "resource_link" || block.icons === void 0) return block;
|
|
27
|
-
return {
|
|
28
|
-
...block,
|
|
29
|
-
icons: block.icons.map(normalizeResourceLinkIcon)
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
function outputValidationError(text) {
|
|
34
|
-
return {
|
|
35
|
-
content: [{
|
|
36
|
-
type: "text",
|
|
37
|
-
text
|
|
38
|
-
}],
|
|
39
|
-
isError: true
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
43
|
-
if (value === null || typeof value === "boolean" || typeof value === "string") return true;
|
|
44
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
45
|
-
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
46
|
-
const prototype = Object.getPrototypeOf(value);
|
|
47
|
-
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return false;
|
|
48
|
-
ancestors.add(value);
|
|
49
|
-
const valid = Object.values(value).every((entry) => isJsonValue(entry, ancestors));
|
|
50
|
-
ancestors.delete(value);
|
|
51
|
-
return valid;
|
|
52
|
-
}
|
|
53
|
-
async function finalizeToolResult(tool, result) {
|
|
54
|
-
const content = normalizeToolContent(result.content);
|
|
55
|
-
let structuredContent = result.structuredContent;
|
|
56
|
-
if (tool.outputSchema && !result.isError) {
|
|
57
|
-
if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
|
|
58
|
-
try {
|
|
59
|
-
const parsed = await safeParseAsync(schemaFromDefinition(tool.outputSchema), structuredContent);
|
|
60
|
-
if (!parsed.success) return outputValidationError(`Output validation error: Invalid structured content for tool ${tool.name}: ${getParseErrorMessage(parsed.error)}`);
|
|
61
|
-
structuredContent = parsed.data;
|
|
62
|
-
} catch {
|
|
63
|
-
return outputValidationError(`Output validation error: Could not validate structured content for tool ${tool.name}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (structuredContent !== void 0 && !isJsonValue(structuredContent)) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
|
|
67
|
-
if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
|
|
68
|
-
type: "text",
|
|
69
|
-
text: JSON.stringify(structuredContent)
|
|
70
|
-
});
|
|
71
|
-
return {
|
|
72
|
-
content,
|
|
73
|
-
structuredContent,
|
|
74
|
-
isError: result.isError
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
//#endregion
|
|
78
|
-
export { extractTextContent as n, finalizeToolResult as t };
|