Skip to main content
Glama
regismesquita

A2A MCP Server

call_agent

Send prompts to A2A protocol agents through Claude Desktop to access extended capabilities and agent interactions.

Instructions

Call an agent with a prompt.

Args:
    agent_name: Name of the agent to call
    prompt: Prompt to send to the agent
    
Returns:
    Dict with response from the agent

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_nameYes
promptYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'call_agent' tool. It verifies the agent in the registry, fetches the agent card if necessary, connects to the A2A server using A2aMinClient, sends the prompt as a message, and returns the task response including artifacts.
    @mcp.tool()
    async def call_agent(agent_name: str, prompt: str) -> Dict[str, Any]:
        """
        Call an agent with a prompt.
        
        Args:
            agent_name: Name of the agent to call
            prompt: Prompt to send to the agent
            
        Returns:
            Dict with response from the agent
        """
        try:
            logger.debug(f"call_agent called with agent_name={agent_name}, prompt={prompt[:50]}...")
            logger.debug(f"Current registry: {state.registry}")
            
            # Verify the agent exists
            if agent_name not in state.registry:
                logger.warning(f"Agent '{agent_name}' not found in registry")
                return {
                    "status": "error",
                    "message": f"Agent '{agent_name}' not found in registry"
                }
            
            # Get the URL for the agent
            url = state.registry[agent_name]
            logger.debug(f"Using URL: {url}")
            
            try:
                # Get or create agent card if needed
                if agent_name not in state.cache:
                    logger.debug(f"Agent card not in cache, fetching for {agent_name}")
                    card = await fetch_agent_card(url)
                    if card:
                        state.cache[agent_name] = card
                    else:
                        logger.error(f"Failed to fetch agent card for {agent_name}")
                        return {
                            "status": "error",
                            "message": f"Failed to fetch agent card for {agent_name}"
                        }
                
                # Create a client using A2aMinClient
                try:
                    # Connect to the A2A server
                    logger.debug(f"Connecting to A2A server at {url}")
                    client = A2aMinClient.connect(url)
                    
                    # Prepare message and send
                    logger.debug(f"Sending message to agent {agent_name}: {prompt[:50]}...")
                    task_id = str(uuid.uuid4())
                    session_id = str(uuid.uuid4())
                    
                    # Send the message and get response
                    task = await client.send_message(
                        message=prompt,
                        task_id=task_id,
                        session_id=session_id
                    )
                    
                    # Process and return the response
                    logger.debug(f"Received task response: {task}")
                    
                    response_data = {
                        "status": "success",
                        "task_id": task.id,
                        "state": task.status.state if hasattr(task, 'status') else "unknown",
                        "artifacts": []
                    }
                    
                    # Extract artifacts
                    artifacts = task.artifacts if hasattr(task, 'artifacts') else []
                    if artifacts:
                        logger.debug(f"Received {len(artifacts)} artifacts")
                        for artifact in artifacts:
                            artifact_data = {
                                "name": artifact.name,
                                "content": []
                            }
                            
                            for part in artifact.parts:
                                part_type = part.type
                                if part_type == "text":
                                    artifact_data["content"].append({
                                        "type": "text", 
                                        "text": part.text
                                    })
                                elif part_type == "file":
                                    file_data = part.file
                                    artifact_data["content"].append({
                                        "type": "file", 
                                        "name": file_data.name,
                                        "mime_type": file_data.mimeType
                                    })
                                elif part_type == "data":
                                    artifact_data["content"].append({
                                        "type": "data", 
                                        "data": part.data
                                    })
                            
                            response_data["artifacts"].append(artifact_data)
                    
                    logger.info(f"Successfully called agent {agent_name}")
                    return response_data
                    
                except Exception as e:
                    logger.exception(f"Error using A2aMinClient: {e}")
                    return {
                        "status": "error",
                        "message": f"Error calling agent with A2aMinClient: {str(e)}"
                    }
            
            except Exception as e:
                logger.exception(f"Error calling agent {agent_name}: {e}")
                return {
                    "status": "error",
                    "message": f"Error calling agent: {str(e)}"
                }
        except Exception as e:
            logger.exception(f"Error in call_agent: {str(e)}")
            return {"status": "error", "message": f"Error: {str(e)}"}
  • Input schema defined in the tool's docstring: agent_name (str), prompt (str). Output is Dict[str, Any] with status, task_id, state, artifacts.
    """
    Call an agent with a prompt.
    
    Args:
        agent_name: Name of the agent to call
        prompt: Prompt to send to the agent
        
    Returns:
        Dict with response from the agent
    """
  • The @mcp.tool() decorator registers the call_agent function as an MCP tool.
    @mcp.tool()
  • Helper function used by call_agent to fetch and cache the agent's card if not already cached.
    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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action but lacks critical details: it doesn't specify if this is a read-only or mutative operation, what permissions or authentication are required, potential rate limits, error handling, or what the 'call' entails (e.g., synchronous/asynchronous). This leaves significant gaps for an AI agent to understand the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by structured sections for args and returns. It avoids unnecessary fluff, with each sentence serving a clear purpose. However, the 'Returns' section could be more informative, and overall it's slightly terse but efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 parameters, no annotations, but with an output schema), the description is minimally adequate. The output schema likely covers return values, reducing the need for detailed return explanations. However, it lacks context on behavioral aspects (e.g., side effects, error cases) and usage guidelines, making it incomplete for safe and effective tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description lists the parameters ('agent_name' and 'prompt') and provides basic semantics (e.g., 'Name of the agent to call'), which adds value beyond the input schema's 0% description coverage. However, it doesn't elaborate on constraints (e.g., format of agent names, prompt length limits) or provide examples, so it only partially compensates for the schema's lack of detail.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Call an agent') and the resource ('with a prompt'), making the purpose immediately understandable. It distinguishes this from sibling tools like 'list_agents' by focusing on interaction rather than listing. However, it doesn't specify what 'calling' entails (e.g., is it an API call, a simulation, or a direct execution?), which prevents a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing to know agent names from 'list_agents'), nor does it differentiate from sibling tools like 'a2a_server_registry'. The description assumes the user already understands the context, offering no explicit usage instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/regismesquita/MCP_A2A'

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