fix: skip arg whitelist for handlers accepting **kwargs (#572) (#684)

* fix: skip arg whitelist for handlers accepting **kwargs (#572)

The schema-based argument filter (from #647) strips all kwargs not
declared in input_schema. This breaks handlers that accept **kwargs
for pass-through to ChromaDB or other backends.

Add inspect.Parameter.VAR_KEYWORD check before filtering — handlers
with **kwargs receive all arguments unfiltered.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: guard inspect.signature failure, default to filtering

Wrap inspect.signature() in try/except — on failure, default to
filtering (safe fallback). Addresses Copilot feedback on fragility.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeffrey Hein
2026-04-12 14:23:39 -07:00
committed by GitHub
parent 6e2ced3287
commit 862a07b198
+13
View File
@@ -1350,7 +1350,20 @@ def handle_request(request):
} }
# Whitelist arguments to declared schema properties only. # Whitelist arguments to declared schema properties only.
# Prevents callers from spoofing internal params like added_by/source_file. # Prevents callers from spoofing internal params like added_by/source_file.
# Skip filtering if handler explicitly accepts **kwargs (pass-through).
# Default to filtering on inspect failure (safe fallback).
import inspect
schema_props = TOOLS[tool_name]["input_schema"].get("properties", {}) schema_props = TOOLS[tool_name]["input_schema"].get("properties", {})
try:
handler = TOOLS[tool_name]["handler"]
sig = inspect.signature(handler)
accepts_var_keyword = any(
p.kind == inspect.Parameter.VAR_KEYWORD for p in sig.parameters.values()
)
except (ValueError, TypeError):
accepts_var_keyword = False
if not accepts_var_keyword:
tool_args = {k: v for k, v in tool_args.items() if k in schema_props} tool_args = {k: v for k, v in tool_args.items() if k in schema_props}
# Coerce argument types based on input_schema. # Coerce argument types based on input_schema.
# MCP JSON transport may deliver integers as floats or strings; # MCP JSON transport may deliver integers as floats or strings;