Fix callServerTool to handle wrapped JSON-RPC responses

Some host implementations incorrectly return the full JSON-RPC envelope
(with result, jsonrpc, id fields) instead of just the unwrapped result.
This causes apps using callServerTool() to fail when accessing result.content.

This fix detects wrapped responses and unwraps them automatically.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Anton Pidkuiko MacBook 2025-12-05 23:12:26 +00:00
commit 9743051f06
No known key found for this signature in database

View file

@ -581,11 +581,17 @@ export class App extends Protocol<Request, Notification, Result> {
params: CallToolRequest["params"],
options?: RequestOptions,
): Promise<CallToolResult> {
return await this.request(
const response = await this.request(
{ method: "tools/call", params },
CallToolResultSchema,
options,
);
// TEMPORAL HACK: Some host implementations incorrectly return the full
// JSON-RPC envelope instead of just the result. Unwrap if needed.
if (response && "result" in response && "jsonrpc" in response) {
return (response as unknown as { result: CallToolResult }).result;
}
return response;
}
/**