mcp schema fix

frdel committed Jun 5, 2025 at 14:08 UTC 29d83b51c8e44abdbfec671eeab5bfd265bffcf7
1 file changed +39 -35
python/helpers/mcp_handler.py
+39 -35
@@ -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 + tools = server.get_tools()
708
708 - for tool in server.get_tools():
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'
715 - f"#### Arguments:\n"
716 + # f"#### Arguments:\n"
717 )
718
719 tool_args = ""
719 - properties: dict[str, Any] = tool["input_schema"]["properties"]
720 - for key, value in properties.items():
721 - optional = False
722 - examples = ""
723 - description = ""
724 - type = ""
725 - if "anyOf" in value:
726 - for nested_value in value["anyOf"]:
727 - if "type" in nested_value and nested_value["type"] != "null":
728 - optional = True
729 - value = nested_value
730 - break
731 - tool_args += f" \"{key}\": \"...\",\n"
732 - if "examples" in value:
733 - examples = f"(examples: {value['examples']})"
734 - if "description" in value:
735 - description = f": {value['description']}"
736 - if "type" in value:
737 - if optional:
738 - type = f"{value['type']}, optional"
739 - else:
740 - type = f"{value['type']}"
741 - else:
742 - if optional:
743 - type = "string, optional"
744 - else:
745 - type = "string"
746 - prompt += (
747 - f" * {key} ({type}){description} {examples}\n"
748 - )
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
@@ -757,9 +761,9 @@ class MCPConfig(BaseModel):
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"
760 - f' "tool_args": {{\n'
761 - f"{tool_args}"
762 - f" }}\n"
764 + f' "tool_args": {{ !follow schema above }}\n'
765 + # f"{tool_args}"
766 + # f" }}\n"
767 f"}}\n"
768 f"~~~\n"
769 )