refs #699: honor MCP tool input schemas
This commit is contained in:
@@ -154,26 +154,32 @@ def build_mcp_tool_arguments(
|
||||
if not isinstance(properties, Mapping):
|
||||
properties = {}
|
||||
|
||||
if tool.name == preferred_tool:
|
||||
return {"prompt": question, "limit": limit}
|
||||
if "prompt" in properties:
|
||||
args: dict[str, Any] = {"prompt": question}
|
||||
if "limit" in properties:
|
||||
args["limit"] = limit
|
||||
elif "max_rows" in properties:
|
||||
args["max_rows"] = limit
|
||||
return args
|
||||
if "question" in properties:
|
||||
args = {"question": question}
|
||||
if "max_rows" in properties:
|
||||
args["max_rows"] = limit
|
||||
elif "limit" in properties:
|
||||
args["limit"] = limit
|
||||
return args
|
||||
if "query" in properties:
|
||||
args = {"query": question}
|
||||
# A server's default/preferred tool still has to obey its discovered schema.
|
||||
# HMM tools use `query` and `term`; forcing the legacy `prompt`/`limit` shape
|
||||
# makes an otherwise valid tool fail argument validation.
|
||||
del preferred_tool
|
||||
input_name = next(
|
||||
(name for name in ("prompt", "question", "query", "term", "text") if name in properties),
|
||||
"",
|
||||
)
|
||||
if not input_name:
|
||||
required = tool.schema.get("required")
|
||||
if isinstance(required, list):
|
||||
input_name = next(
|
||||
(
|
||||
str(name)
|
||||
for name in required
|
||||
if isinstance(properties.get(str(name)), Mapping)
|
||||
and properties[str(name)].get("type") == "string"
|
||||
),
|
||||
"",
|
||||
)
|
||||
if input_name:
|
||||
args: dict[str, Any] = {input_name: question}
|
||||
if "max_evidence" in properties:
|
||||
args["max_evidence"] = min(limit, 10)
|
||||
elif "max_rows" in properties:
|
||||
args["max_rows"] = limit
|
||||
elif "limit" in properties:
|
||||
args["limit"] = limit
|
||||
return args
|
||||
|
||||
Reference in New Issue
Block a user