list_tools
Discover all available tools on the connected MCP server to understand their capabilities and input requirements for accurate tool invocation.
Instructions
List all tools available on the connected MCP server.
Retrieves comprehensive information about all tools exposed by the target server, including full input schemas to enable accurate tool invocation.
Returns: Dictionary with tool listing including: - success: True on successful retrieval - tools: List of tool objects with name, description, and full input_schema - metadata: Total count, server info, timing information
Raises: Returns error dict if not connected or retrieval fails
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function for the 'list_tools' MCP tool. It is decorated with @mcp.tool for automatic registration. The function retrieves the list of tools from the connected target MCP server using client.list_tools(), processes them into a structured dictionary with input schemas, adds metadata, and handles connection and execution errors appropriately.@mcp.tool async def list_tools(ctx: Context) -> dict[str, Any]: """List all tools available on the connected MCP server. Retrieves comprehensive information about all tools exposed by the target server, including full input schemas to enable accurate tool invocation. Returns: Dictionary with tool listing including: - success: True on successful retrieval - tools: List of tool objects with name, description, and full input_schema - metadata: Total count, server info, timing information Raises: Returns error dict if not connected or retrieval fails """ start_time = time.perf_counter() try: # Verify connection exists client, state = ConnectionManager.require_connection() # User-facing progress update await ctx.info("Listing tools from connected MCP server") # Detailed technical log logger.info("Listing tools from connected MCP server") # Get tools from the server tools_result = await client.list_tools() elapsed_ms = (time.perf_counter() - start_time) * 1000 # Convert tools to dictionary format with full schemas # Note: client.list_tools() returns a list directly, not an object with .tools tools_list = [] for tool in tools_result: # inputSchema is already a dict, not a Pydantic model input_schema = tool.inputSchema if hasattr(tool, "inputSchema") and tool.inputSchema else {} tool_dict = { "name": tool.name, "description": tool.description if tool.description else "", "input_schema": input_schema, } tools_list.append(tool_dict) metadata = { "total_tools": len(tools_list), "server_url": state.server_url, "retrieved_at": time.time(), "request_time_ms": round(elapsed_ms, 2), } # Add server info if available if state.server_info: metadata["server_name"] = state.server_info.get("name", "unknown") metadata["server_version"] = state.server_info.get("version") # User-facing success update await ctx.info(f"Retrieved {len(tools_list)} tools from server") # Detailed technical log logger.info( f"Retrieved {len(tools_list)} tools from server", extra={ "tool_count": len(tools_list), "server_url": state.server_url, "duration_ms": elapsed_ms, }, ) return { "success": True, "tools": tools_list, "metadata": metadata, } except ConnectionError as e: elapsed_ms = (time.perf_counter() - start_time) * 1000 # User-facing error update await ctx.error(f"Not connected: {str(e)}") # Detailed technical log logger.error(f"Not connected: {str(e)}", extra={"duration_ms": elapsed_ms}) return { "success": False, "error": { "error_type": "not_connected", "message": str(e), "details": {}, "suggestion": "Use connect_to_server() to establish a connection first", }, "tools": [], "metadata": { "request_time_ms": round(elapsed_ms, 2), }, } except Exception as e: elapsed_ms = (time.perf_counter() - start_time) * 1000 # User-facing error update await ctx.error(f"Failed to list tools: {str(e)}") # Detailed technical log logger.exception("Failed to list tools", extra={"duration_ms": elapsed_ms}) # Increment error counter ConnectionManager.increment_stat("errors") return { "success": False, "error": { "error_type": "execution_error", "message": f"Failed to list tools: {str(e)}", "details": {"exception_type": type(e).__name__}, "suggestion": "Check that the server supports the tools capability and is responding correctly", }, "tools": [], "metadata": { "request_time_ms": round(elapsed_ms, 2), }, }
- node-wrapper/python-src/src/mcp_test_mcp/server.py:97-99 (registration)Import of the tools module in the main server.py file, which triggers the execution of the @mcp.tool decorators in tools/tools.py, thereby registering the list_tools tool with the FastMCP server instance.# This MUST happen after mcp instance is imported but before the server runs from .tools import connection, tools, resources, prompts, llm
- Re-export of the list_tools function from the tools submodule in the package __init__.py, making it available when importing from the tools package.from .tools import call_tool, list_tools