Spaces:
Paused
Paused
frdel commited on
Commit ·
717d8c7
1
Parent(s): 21051cf
mcp schema fix
Browse files- python/helpers/mcp_handler.py +39 -35
python/helpers/mcp_handler.py
CHANGED
|
@@ -704,48 +704,52 @@ class MCPConfig(BaseModel):
|
|
| 704 |
server_name = server.name
|
| 705 |
prompt += f"### {server_name}\n"
|
| 706 |
prompt += f"{server.description}\n\n"
|
|
|
|
| 707 |
|
| 708 |
-
for tool in
|
| 709 |
prompt += (
|
| 710 |
f"### {server_name}.{tool['name']}:\n"
|
| 711 |
f"{tool['description']}\n\n"
|
| 712 |
# f"#### Categories:\n"
|
| 713 |
# f"* kind: MCP Server Tool\n"
|
| 714 |
# f'* server: "{server_name}" ({server.description})\n\n'
|
| 715 |
-
f"#### Arguments:\n"
|
| 716 |
)
|
| 717 |
|
| 718 |
tool_args = ""
|
| 719 |
-
|
| 720 |
-
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
|
|
|
|
|
|
|
|
|
| 749 |
|
| 750 |
prompt += "\n"
|
| 751 |
|
|
@@ -757,9 +761,9 @@ class MCPConfig(BaseModel):
|
|
| 757 |
f' "thoughts": ["..."],\n'
|
| 758 |
# f' "reflection": ["..."],\n' # TODO: this should be a prompt file with placeholders
|
| 759 |
f" \"tool_name\": \"{server_name}.{tool['name']}\",\n"
|
| 760 |
-
f' "tool_args": {{\n'
|
| 761 |
-
f"{tool_args}"
|
| 762 |
-
f" }}\n"
|
| 763 |
f"}}\n"
|
| 764 |
f"~~~\n"
|
| 765 |
)
|
|
|
|
| 704 |
server_name = server.name
|
| 705 |
prompt += f"### {server_name}\n"
|
| 706 |
prompt += f"{server.description}\n\n"
|
| 707 |
+
tools = server.get_tools()
|
| 708 |
|
| 709 |
+
for tool in tools:
|
| 710 |
prompt += (
|
| 711 |
f"### {server_name}.{tool['name']}:\n"
|
| 712 |
f"{tool['description']}\n\n"
|
| 713 |
# f"#### Categories:\n"
|
| 714 |
# f"* kind: MCP Server Tool\n"
|
| 715 |
# f'* server: "{server_name}" ({server.description})\n\n'
|
| 716 |
+
# f"#### Arguments:\n"
|
| 717 |
)
|
| 718 |
|
| 719 |
tool_args = ""
|
| 720 |
+
input_schema = json.dumps(tool["input_schema"]) if tool["input_schema"] else ""
|
| 721 |
+
# properties: dict[str, Any] = tool["input_schema"]["properties"]
|
| 722 |
+
# for key, value in properties.items():
|
| 723 |
+
# optional = False
|
| 724 |
+
# examples = ""
|
| 725 |
+
# description = ""
|
| 726 |
+
# type = ""
|
| 727 |
+
# if "anyOf" in value:
|
| 728 |
+
# for nested_value in value["anyOf"]:
|
| 729 |
+
# if "type" in nested_value and nested_value["type"] != "null":
|
| 730 |
+
# optional = True
|
| 731 |
+
# value = nested_value
|
| 732 |
+
# break
|
| 733 |
+
# tool_args += f" \"{key}\": \"...\",\n"
|
| 734 |
+
# if "examples" in value:
|
| 735 |
+
# examples = f"(examples: {value['examples']})"
|
| 736 |
+
# if "description" in value:
|
| 737 |
+
# description = f": {value['description']}"
|
| 738 |
+
# if "type" in value:
|
| 739 |
+
# if optional:
|
| 740 |
+
# type = f"{value['type']}, optional"
|
| 741 |
+
# else:
|
| 742 |
+
# type = f"{value['type']}"
|
| 743 |
+
# else:
|
| 744 |
+
# if optional:
|
| 745 |
+
# type = "string, optional"
|
| 746 |
+
# else:
|
| 747 |
+
# type = "string"
|
| 748 |
+
# prompt += (
|
| 749 |
+
# f" * {key} ({type}){description} {examples}\n"
|
| 750 |
+
# )
|
| 751 |
+
|
| 752 |
+
prompt += f"#### Input schema for tool_args:\n{input_schema}\n"
|
| 753 |
|
| 754 |
prompt += "\n"
|
| 755 |
|
|
|
|
| 761 |
f' "thoughts": ["..."],\n'
|
| 762 |
# f' "reflection": ["..."],\n' # TODO: this should be a prompt file with placeholders
|
| 763 |
f" \"tool_name\": \"{server_name}.{tool['name']}\",\n"
|
| 764 |
+
f' "tool_args": {{ !follow schema above }}\n'
|
| 765 |
+
# f"{tool_args}"
|
| 766 |
+
# f" }}\n"
|
| 767 |
f"}}\n"
|
| 768 |
f"~~~\n"
|
| 769 |
)
|