MCPcopy
hub / github.com/IBM/AssetOpsBench / _list_tools

Function _list_tools

src/agent/plan_execute/executor.py:284–314  ·  view source on GitHub ↗

Connect to an MCP server via stdio and list its tools with parameter info.

(server_path: Path | str)

Source from the content-addressed store, hash-verified

282
283
284async def _list_tools(server_path: Path | str) -> list[dict]:
285 """Connect to an MCP server via stdio and list its tools with parameter info."""
286 from mcp import ClientSession
287 from mcp.client.stdio import stdio_client
288
289 params = _make_stdio_params(server_path)
290 async with stdio_client(params) as (read, write):
291 async with ClientSession(read, write) as session:
292 await session.initialize()
293 result = await session.list_tools()
294 tools = []
295 for t in result.tools:
296 schema = t.inputSchema or {}
297 props = schema.get("properties", {})
298 required = set(schema.get("required", []))
299 parameters = [
300 {
301 "name": k,
302 "type": v.get("type", "any"),
303 "required": k in required,
304 }
305 for k, v in props.items()
306 ]
307 tools.append(
308 {
309 "name": t.name,
310 "description": t.description or "",
311 "parameters": parameters,
312 }
313 )
314 return tools
315
316
317async def _call_tool(server_path: Path | str, tool_name: str, args: dict) -> str:

Callers 2

execute_planMethod · 0.85

Calls 3

_make_stdio_paramsFunction · 0.85
list_toolsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected