Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/client-runtime/src/mcpApps/host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ describe("makeMcpAppHost", () => {
});

it("proxies tools/call and reports a refusal as a JSON-RPC error", async () => {
const calls: Array<unknown> = [];
const { host, sent } = setup({
callTool: async (input) => {
calls.push(input.arguments);
if (input.name === "delete_everything")
throw new McpAppHostRefusal({ message: "Declined by the user." });
return { content: [], structuredContent: { ok: true } };
Expand All @@ -217,7 +219,14 @@ describe("makeMcpAppHost", () => {
method: "tools/call",
params: { name: "delete_everything", arguments: {} },
});
host.receive({
jsonrpc: "2.0",
id: 9,
method: "tools/call",
params: { name: "refresh", arguments: { since: undefined, limit: 5 } },
});
await flush();
expect(calls.at(-1)).toStrictEqual({ limit: 5 });
expect(sent).toContainEqual({
jsonrpc: "2.0",
id: 7,
Expand Down
12 changes: 9 additions & 3 deletions packages/client-runtime/src/mcpApps/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,16 @@ export function makeMcpAppHost(options: McpAppHostOptions): McpAppHost {
fail(id, -32602, "tools/call needs a tool name and object arguments.");
return;
}
let jsonArgs: Record<string, unknown>;
try {
// postMessage keeps undefined and other non-JSON values the RPC encoding rejects.
jsonArgs = JSON.parse(JSON.stringify(args));
} catch {
fail(id, -32602, "tools/call arguments must be JSON.");
return;
}
answer(id, () =>
options
.callTool({ name, arguments: args as Record<string, unknown> })
.then(normalizeMcpAppToolResult),
options.callTool({ name, arguments: jsonArgs }).then(normalizeMcpAppToolResult),
);
return;
}
Expand Down
Loading