MCPcopy Create free account
hub / github.com/agent0ai/agent-zero / get_tools_prompt

Method get_tools_prompt

helpers/mcp_handler.py:1091–1143  ·  view source on GitHub ↗

Get a prompt for all tools

(self, server_name: str = "")

Source from the content-addressed store, hash-verified

1089 return tools
1090
1091 def get_tools_prompt(self, server_name: str = "") -> str:
1092 """Get a prompt for all tools"""
1093
1094 # just to wait for pending initialization
1095 with self.__lock:
1096 pass
1097
1098 prompt = '## "Remote (MCP Server) Agent Tools" available:\n\n'
1099 server_names = []
1100 for server in self.servers:
1101 if not server_name or server.name == server_name:
1102 server_names.append(server.name)
1103
1104 if server_name and server_name not in server_names:
1105 raise ValueError(f"Server {server_name} not found")
1106
1107 for server in self.servers:
1108 if server.name in server_names:
1109 server_name = server.name
1110 prompt += f"### {server_name}\n"
1111 prompt += f"{server.description}\n"
1112 tools = server.get_tools()
1113
1114 for tool in tools:
1115 prompt += (
1116 f"\n### {server_name}.{tool['name']}:\n"
1117 f"{tool['description']}\n\n"
1118 # f"#### Categories:\n"
1119 # f"* kind: MCP Server Tool\n"
1120 # f'* server: "{server_name}" ({server.description})\n\n'
1121 # f"#### Arguments:\n"
1122 )
1123
1124 input_schema = (
1125 json.dumps(tool["input_schema"]) if tool["input_schema"] else ""
1126 )
1127
1128 prompt += f"#### Input schema for tool_args:\n{input_schema}\n"
1129
1130 prompt += "\n"
1131
1132 prompt += (
1133 f"#### Usage:\n"
1134 f"{{\n"
1135 # f' "observations": ["..."],\n' # TODO: this should be a prompt file with placeholders
1136 f' "thoughts": ["..."],\n'
1137 # f' "reflection": ["..."],\n' # TODO: this should be a prompt file with placeholders
1138 f" \"tool_name\": \"{server_name}.{tool['name']}\",\n"
1139 f' "tool_args": !follow schema above\n'
1140 f"}}\n"
1141 )
1142
1143 return prompt
1144
1145 def has_tool(self, tool_name: str) -> bool:
1146 """Check if a tool is available"""

Calls 1

get_toolsMethod · 0.45