Files
Netcatty/electron/mcp/normalizeMcpCallArguments.cjs
T
bincxz ba88ea7e4f fix(mcp): accept omitted arguments for no-arg tools
MCP allows clients to omit tools/call arguments or send {}. Empty Zod
object schemas rejected the omitted case, so external agents could not
call get_environment and other no-arg tools.

Closes #3049
2026-08-18 14:59:22 +08:00

28 lines
766 B
JavaScript

"use strict";
/**
* MCP tools/call `arguments` is optional. Clients may omit it for no-arg
* tools or send {}. The SDK still parses omitted args as `undefined`, and
* Zod object schemas reject that. Treat missing/null as {}.
*/
function normalizeMcpToolArguments(args) {
return args == null ? {} : args;
}
function normalizeMcpJsonRpcMessage(message) {
if (!message || typeof message !== "object") return message;
if (message.method !== "tools/call") return message;
const params = message.params;
if (!params || typeof params !== "object" || Array.isArray(params)) return message;
if (params.arguments == null) {
params.arguments = {};
}
return message;
}
module.exports = {
normalizeMcpToolArguments,
normalizeMcpJsonRpcMessage,
};