list_agents
Retrieve available agents and their details to facilitate communication and extended capabilities via the A2A MCP Server.
Instructions
List available agents with their agent cards.
Returns:
Dict with agents and their cards
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- a2a_mcp_server/server.py:151-188 (handler)The handler function for the 'list_agents' tool. It iterates over registered servers, fetches agent cards using fetch_agent_card, and returns a dictionary with agent names and their card data. Registered via @mcp.tool() decorator.@mcp.tool() async def list_agents() -> Dict[str, Any]: """ List available agents with their agent cards. Returns: Dict with agents and their cards """ try: logger.debug("list_agents called") logger.debug(f"Current registry: {state.registry}") # Use the A2ACardResolver to fetch agent cards agents = {} for name, url in state.registry.items(): try: logger.debug(f"Fetching card for {name} from {url}") card = await fetch_agent_card(url) if card: # Store the card data in a format suitable for JSON response agents[name] = card.model_dump() # Update the cache with the fetched card state.cache[name] = card else: logger.error(f"Failed to fetch agent card for {name}") except Exception as e: logger.exception(f"Error fetching card for {name}: {e}") logger.info(f"Listing {len(agents)} agents") return { "agent_count": len(agents), "agents": agents } except Exception as e: logger.exception(f"Error in list_agents: {str(e)}") return {"status": "error", "message": f"Error: {str(e)}"}
- a2a_mcp_server/server.py:151-151 (registration)The @mcp.tool() decorator registers the list_agents function as an MCP tool.@mcp.tool()
- a2a_mcp_server/server.py:46-64 (helper)Helper function used by list_agents to fetch individual agent cards from A2A servers.async def fetch_agent_card(url: str) -> Optional[AgentCard]: """Fetch agent card from an A2A server using A2ACardResolver.""" try: logger.debug(f"Fetching agent card from {url}") # Use the A2ACardResolver from a2a_min to get the agent card card_resolver = A2ACardResolver(url) try: card = card_resolver.get_agent_card() logger.debug(f"Received agent card: {card}") return card except Exception as e: logger.error(f"Failed to fetch agent card: {str(e)}") return None except Exception as e: logger.exception(f"Error fetching agent card from {url}: {e}") return None
- a2a_mcp_server/server.py:153-158 (schema)Docstring defining the tool's purpose and return type, used for schema inference in MCP.""" List available agents with their agent cards. Returns: Dict with agents and their cards """