Skip to main content
Glama

send_message

Send messages to A2A agents for communication and task management. Specify agent URL, message content, and optional session ID for multi-turn conversations.

Instructions

Send a message to an A2A agent.

Args: agent_url: URL of the A2A agent message: Message to send session_id: Optional session ID for multi-turn conversations

Returns: Agent's response with task_id for future reference

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_urlYes
messageYes
session_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'send_message' MCP tool. Decorated with @mcp.tool() which registers it automatically in FastMCP. Sends a message to a registered A2A agent via A2AClient.send_task, generates task_id, stores mapping, extracts and returns response details including state, message, and artifacts.
    @mcp.tool()
    async def send_message(
        agent_url: str,
        message: str,
        session_id: Optional[str] = None,
        ctx: Context = None,
    ) -> Dict[str, Any]:
        """
        Send a message to an A2A agent.
        
        Args:
            agent_url: URL of the A2A agent
            message: Message to send
            session_id: Optional session ID for multi-turn conversations
            
        Returns:
            Agent's response with task_id for future reference
        """
        if agent_url not in registered_agents:
            return {
                "status": "error",
                "message": f"Agent not registered: {agent_url}",
            }
        
        # Create a client for the agent
        client = A2AClient(url=agent_url)
        
        try:
            # Generate a task ID
            task_id = str(uuid.uuid4())
            
            # Store the mapping of task_id to agent_url for later reference
            task_agent_mapping[task_id] = agent_url
            
            # Create the message
            a2a_message = Message(
                role="user",
                parts=[TextPart(text=message)],
            )
            
            if ctx:
                await ctx.info(f"Sending message to agent: {message}")
            
            # Create payload as a single dictionary
            payload = {
                "id": task_id,
                "message": a2a_message,
            }
            if session_id:
                payload["sessionId"] = session_id
            
            # Send the task with the payload
            result = await client.send_task(payload)
            
            # Save task mapping to disk
            save_to_json(task_agent_mapping, TASK_AGENT_MAPPING_FILE)
            
            # Debug: Print the raw response for analysis
            if ctx:
                await ctx.info(f"Raw response: {result}")
                
            # Create a response dictionary with as much info as we can extract
            response = {
                "status": "success",
                "task_id": task_id,
            }
            
            # Add any available fields from the result
            if hasattr(result, "sessionId"):
                response["session_id"] = result.sessionId
            else:
                response["session_id"] = None
                
            # Try to get the state
            try:
                if hasattr(result, "status") and hasattr(result.status, "state"):
                    response["state"] = result.status.state
                else:
                    response["state"] = "unknown"
            except Exception as e:
                response["state"] = f"error_getting_state: {str(e)}"
                
            # Try to extract response message
            try:
                if hasattr(result, "status") and hasattr(result.status, "message") and result.status.message:
                    response_text = ""
                    for part in result.status.message.parts:
                        if part.type == "text":
                            response_text += part.text
                    if response_text:
                        response["message"] = response_text
            except Exception as e:
                response["message_error"] = f"Error extracting message: {str(e)}"
            
            # Try to get artifacts
            try:
                if hasattr(result, "artifacts") and result.artifacts:
                    artifacts_data = []
                    for artifact in result.artifacts:
                        artifact_data = {
                            "name": artifact.name if hasattr(artifact, "name") else "unnamed_artifact",
                            "contents": [],
                        }
                        
                        for part in artifact.parts:
                            if part.type == "text":
                                artifact_data["contents"].append({
                                    "type": "text",
                                    "text": part.text,
                                })
                            elif part.type == "data":
                                artifact_data["contents"].append({
                                    "type": "data",
                                    "data": part.data,
                                })
                        
                        artifacts_data.append(artifact_data)
                    
                    response["artifacts"] = artifacts_data
            except Exception as e:
                response["artifacts_error"] = f"Error extracting artifacts: {str(e)}"
                
            return response
        except Exception as e:
            return {
                "status": "error",
                "message": f"Error sending message: {str(e)}",
            }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions that the tool returns a 'task_id for future reference', which hints at asynchronous behavior, but fails to disclose critical details like authentication requirements, rate limits, error handling, or whether this is a blocking call. For a communication tool with zero annotation coverage, this is a significant gap in behavioral context.

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

Conciseness5/5

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

The description is efficiently structured with a clear opening sentence followed by labeled 'Args' and 'Returns' sections. Every sentence earns its place by providing essential information without redundancy, making it easy to scan and understand quickly.

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

Completeness4/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 (3 parameters, no annotations, but with an output schema), the description is reasonably complete. It covers the purpose, parameters, and return value, and the output schema likely details the response structure, reducing the need for further explanation. However, it could better address behavioral aspects and sibling tool differentiation.

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

Parameters4/5

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

With 0% schema description coverage, the description compensates well by explaining all three parameters: 'agent_url' as the URL of the A2A agent, 'message' as the content to send, and 'session_id' as optional for multi-turn conversations. This adds meaningful context beyond the bare schema, though it doesn't specify formats or constraints for these parameters.

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 verb 'send' and the resource 'message to an A2A agent', making the purpose explicit. However, it doesn't distinguish this tool from its sibling 'send_message_stream', which likely handles streaming responses, leaving some ambiguity about when to choose one over the other.

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

Usage Guidelines3/5

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

The description implies usage for sending messages to A2A agents, with the optional 'session_id' hinting at multi-turn conversations. However, it lacks explicit guidance on when to use this tool versus 'send_message_stream' or other siblings like 'list_agents', and doesn't mention prerequisites or exclusions, leaving usage context somewhat vague.

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/GongRzhe/A2A-MCP-Server'

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