Merge pull request #84 from AlexeySamosadov/fix/mcp-integer-coercion
fix: coerce MCP integer arguments to native Python int
This commit is contained in:
@@ -726,6 +726,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