Skip to main content
Glama

list_tools

Discover and retrieve all available tools from the connected MCP server, including their descriptions and input schemas for accurate 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

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_tools' MCP tool. It verifies the connection, calls list_tools on the client, formats the tools with their input schemas, adds metadata, and handles connection and execution errors gracefully.
    @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), }, }
  • Import of the tools module in server.py which triggers the @mcp.tool decorator registration for list_tools and other tools.
    # This MUST happen after mcp instance is imported but before the server runs from .tools import connection, tools, resources, prompts, llm
  • Creation of the shared FastMCP instance 'mcp' used for @mcp.tool decorator registrations.
    from fastmcp import FastMCP # Create the shared FastMCP server instance mcp = FastMCP(name="mcp-test-mcp")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/rdwj/mcp-test-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server