Skip to content

Commit df23604

Browse files
krissdingclaude
andcommitted
fix(mcp): strip null values from tool call arguments before sending
Some MCP servers (e.g. awslabs eks-mcp-server) distinguish between null and absent for optional parameters. When the LLM passes null for an optional field, treat it as "not provided" by stripping top-level null values from arguments before calling the MCP server. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 4ecb45b commit df23604

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/agents/agent-bundle-mcp-runtime.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ import { loadEmbeddedAgentMcpConfig } from "./embedded-agent-mcp.js";
3737
import { isMcpConfigRecord } from "./mcp-config-shared.js";
3838
import { resolveMcpTransport } from "./mcp-transport.js";
3939

40+
function stripNullValues(args: Record<string, unknown>): Record<string, unknown> {
41+
const result: Record<string, unknown> = {};
42+
for (const [key, value] of Object.entries(args)) {
43+
if (value !== null) {
44+
result[key] = value;
45+
}
46+
}
47+
return result;
48+
}
49+
4050
type BundleMcpSession = {
4151
serverName: string;
4252
client: Client;
@@ -902,7 +912,7 @@ export function createSessionMcpRuntime(params: {
902912
(await session.client.callTool(
903913
{
904914
name: toolName,
905-
arguments: isMcpConfigRecord(input) ? input : {},
915+
arguments: isMcpConfigRecord(input) ? stripNullValues(input) : {},
906916
},
907917
undefined,
908918
{ timeout: session.requestTimeoutMs },

0 commit comments

Comments
 (0)