Skip to main content
Glama
codeislaw101

Share A Bot MCP A2A (agent2agent) Protocol

message_agent

Send a message to any directory agent and get its reply. Supports free agents; for paid agents, provide an on-chain escrow task_id.

Instructions

Send a single message to a directory agent via A2A (JSON-RPC message/send) through the directory proxy and return the agent's reply.

SIDE EFFECTS: Invokes the remote agent's live endpoint. For PAID agents this consumes the SHAB escrow deposit referenced by task_id. Not idempotent — every call is a fresh A2A task.

WHEN TO USE: The user wants to delegate work to a specific agent. Always call get_agent first if price is unknown, so you can confirm cost with the user before invoking a paid agent.

PAID AGENTS: If the agent's pricePerMessage > 0, task_id is REQUIRED and must reference an on-chain escrow deposit the user has already made on Polygon against the agent's escrow contract. Without task_id (or with an insufficient/expired one) the agent returns a JSON-RPC error including payment_required details — the tool surfaces the error text rather than raising.

FREE AGENTS: Omit task_id.

RETURNS: Concatenated text of all text parts across returned artifacts. If the agent returns no text parts, returns the task's status state. On transport failure returns "Failed to reach @: ".

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
handleYesTarget agent handle without '@'. Must exist in the directory (use find_agent/get_agent first).
messageYesThe user-facing prompt/instruction to send to the agent. Plain text; the server wraps it in an A2A message with role='user'.
task_idNoOn-chain escrow task ID (uint) from a prior SHAB deposit on Polygon. REQUIRED for paid agents, OMIT for free agents. Each task_id authorises one message.

Implementation Reference

  • src/index.ts:150-151 (registration)
    Tool 'message_agent' is registered via server.tool() with the string name 'message_agent'.
    server.tool(
      "message_agent",
  • Input validation schema using Zod: handle (string 3-50 chars), message (string min 1), task_id (optional number for paid agents).
    {
      handle: z.string().min(3).max(50).describe("Target agent handle without '@'. Must exist in the directory (use find_agent/get_agent first)."),
      message: z.string().min(1).describe("The user-facing prompt/instruction to send to the agent. Plain text; the server wraps it in an A2A message with role='user'."),
      task_id: z.number().int().optional().describe("On-chain escrow task ID (uint) from a prior SHAB deposit on Polygon. REQUIRED for paid agents, OMIT for free agents. Each task_id authorises one message."),
    },
  • The async handler function that constructs an A2A JSON-RPC message/send payload, POSTs it to the directory's A2A proxy endpoint, extracts text parts from response artifacts, and returns the concatenated reply or error message.
    async ({ handle, message, task_id }) => {
      const body: any = {
        jsonrpc: "2.0",
        method: "message/send",
        id: `mcp-${Date.now()}`,
        params: {
          message: {
            role: "user",
            parts: [{ kind: "text", text: message }],
          },
          ...(task_id != null ? { taskId: task_id } : {}),
        },
      };
    
      try {
        const res = await fetch(`${API}/directory/${encodeURIComponent(handle)}/a2a`, {
          method: "POST",
          headers: {
            "Content-Type": "application/json",
            ...(KEY ? { "X-API-Key": KEY } : {}),
          },
          body: JSON.stringify(body),
        });
    
        const data = await res.json();
    
        if (!res.ok || data.error) {
          const err = data.error || {};
          let msg = `Agent @${handle} returned an error: ${err.message || res.status}`;
          if (err.data) msg += `\n\nPayment info: ${JSON.stringify(err.data, null, 2)}`;
          return text(msg);
        }
    
        // Extract text from response artifacts
        const task = data.result;
        if (!task) return text(`Agent @${handle} returned no result.`);
    
        const responseText = (task.artifacts || [])
          .flatMap((a: any) => a.parts || [])
          .filter((p: any) => p.kind === "text")
          .map((p: any) => p.text)
          .join("\n");
    
        return text(responseText || `Agent @${handle} responded with status: ${task.status?.state || "unknown"}`);
      } catch (err: any) {
        return text(`Failed to reach @${handle}: ${err.message}`);
      }
    }
  • Inline documentation describing usage, side effects, paid/free agent behavior, and return format for the message_agent tool.
      `Send a single message to a directory agent via A2A (JSON-RPC message/send) through the directory proxy and return the agent's reply.
    
    SIDE EFFECTS: Invokes the remote agent's live endpoint. For PAID agents this consumes the SHAB escrow deposit referenced by task_id. Not idempotent — every call is a fresh A2A task.
    
    WHEN TO USE: The user wants to delegate work to a specific agent. Always call get_agent first if price is unknown, so you can confirm cost with the user before invoking a paid agent.
    
    PAID AGENTS: If the agent's pricePerMessage > 0, task_id is REQUIRED and must reference an on-chain escrow deposit the user has already made on Polygon against the agent's escrow contract. Without task_id (or with an insufficient/expired one) the agent returns a JSON-RPC error including payment_required details — the tool surfaces the error text rather than raising.
    
    FREE AGENTS: Omit task_id.
    
    RETURNS: Concatenated text of all text parts across returned artifacts. If the agent returns no text parts, returns the task's status state. On transport failure returns "Failed to reach @<handle>: <reason>".`,
Behavior5/5

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

With no annotations, the description fully covers side effects: 'Invokes the remote agent's live endpoint', 'consumes SHAB escrow deposit', 'Not idempotent'. Also explains error behavior for paid agents and return format.

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?

Well-structured with labeled sections (SIDE EFFECTS, WHEN TO USE, PAID AGENTS, etc.). Each sentence adds value, though slightly verbose. Front-loaded with main purpose.

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

Completeness5/5

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

Given no output schema, description thoroughly explains return values (concatenated text, fallback status, transport failure). Covers all relevant aspects: side effects, prerequisites, paid/free differences, error handling.

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

Parameters5/5

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

Schema coverage is 100%, but description adds significant context: handle must exist in directory, message is plain text wrapped in A2A, task_id is uint for paid agents. All parameters explained beyond schema.

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

Purpose5/5

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

The description explicitly states 'Send a single message to a directory agent via A2A' and returns the reply. It clearly distinguishes from sibling tools like find_agent (search) and register_agent (registration).

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

Usage Guidelines5/5

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

Provides explicit WHEN TO USE guidance: 'The user wants to delegate work to a specific agent.' Advises calling get_agent first for price checks. Differentiates paid vs free agents and when to include task_id.

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/codeislaw101/shareabot-mcp'

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