fix: coerce MCP integer arguments to native Python int
ChromaDB requires native `int` for `n_results`, but the MCP JSON-RPC transport can deliver JSON integers as floats or strings depending on the client implementation. This causes `mempalace_search` (and any tool with integer params like `max_hops`, `last_n`) to fail with: "Expected requested number of results to be a int, got 3 in query." Fix: auto-coerce tool arguments based on the declared `input_schema` types before calling handlers. This covers all current and future tools generically. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -725,6 +725,17 @@ def handle_request(request):
|
||||
"id": req_id,
|
||||
"error": {"code": -32601, "message": f"Unknown tool: {tool_name}"},
|
||||
}
|
||||
# Coerce argument types based on input_schema.
|
||||
# MCP JSON transport may deliver integers as floats or strings;
|
||||
# ChromaDB and Python slicing require native int.
|
||||
schema_props = TOOLS[tool_name]["input_schema"].get("properties", {})
|
||||
for key, value in list(tool_args.items()):
|
||||
prop_schema = schema_props.get(key, {})
|
||||
declared_type = prop_schema.get("type")
|
||||
if declared_type == "integer" and not isinstance(value, int):
|
||||
tool_args[key] = int(value)
|
||||
elif declared_type == "number" and not isinstance(value, (int, float)):
|
||||
tool_args[key] = float(value)
|
||||
try:
|
||||
result = TOOLS[tool_name]["handler"](**tool_args)
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user