Skip to main content
Glama

relay_write

Write a message to a shared AD4M perspective, making it instantly visible across all terminals connected to the same AD4M executor.

Instructions

Write a cross-terminal relay message to AD4M. Both terminals share the same AD4M executor so state is immediately visible.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
perspective_uuidYesPerspective UUID (use ClaudeMemory UUID)
messageYesMessage to relay
session_idNoTerminal/session identifier (default: 'default')

Implementation Reference

  • src/index.ts:460-483 (registration)
    Registration of the 'relay_write' tool via server.tool() with name, description, and Zod schema.
    server.tool("relay_write",
      "Write a cross-terminal relay message to AD4M. Both terminals share the same AD4M executor so state is immediately visible.",
      {
        perspective_uuid: z.string().describe("Perspective UUID (use ClaudeMemory UUID)"),
        message:          z.string().describe("Message to relay"),
        session_id:       z.string().optional().describe("Terminal/session identifier (default: 'default')"),
      },
      async ({ perspective_uuid, message, session_id = "default" }) => {
        const data = await gql(
          `mutation M($uuid: String!, $link: LinkInput!) {
             perspectiveAddLink(uuid: $uuid, link: $link) {
               author timestamp data { source predicate target }
             }
           }`,
          { uuid: perspective_uuid, link: {
              source:    `franc://relay/${session_id}`,
              predicate: "franc://relay",
              target:    `literal://${message}`,
            }
          }
        );
        return ok(data.perspectiveAddLink);
      }
    );
  • Input schema for relay_write: perspective_uuid (string), message (string), session_id (optional string, defaults to 'default').
    {
      perspective_uuid: z.string().describe("Perspective UUID (use ClaudeMemory UUID)"),
      message:          z.string().describe("Message to relay"),
      session_id:       z.string().optional().describe("Terminal/session identifier (default: 'default')"),
    },
  • Handler function that executes the relay_write logic: sends a GraphQL mutation to add a link with source=franc://relay/{session_id}, predicate=franc://relay, target=literal://{message}.
    async ({ perspective_uuid, message, session_id = "default" }) => {
      const data = await gql(
        `mutation M($uuid: String!, $link: LinkInput!) {
           perspectiveAddLink(uuid: $uuid, link: $link) {
             author timestamp data { source predicate target }
           }
         }`,
        { uuid: perspective_uuid, link: {
            source:    `franc://relay/${session_id}`,
            predicate: "franc://relay",
            target:    `literal://${message}`,
          }
        }
      );
      return ok(data.perspectiveAddLink);
    }
  • Helper function 'ok' that wraps data in the MCP text content response format, used by the relay_write handler to return results.
    function ok(data: unknown) {
      return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] };
    }
  • Helper function 'gql' that sends GraphQL queries to the AD4M executor, used by the relay_write handler to persist the relay message.
    async function gql(query: string, variables: Record<string, unknown> = {}): Promise<GqlResult> {
      const resp = await fetch(AD4M_GQL, {
        method:  "POST",
        headers: { "Content-Type": "application/json" },
        body:    JSON.stringify({ query, variables }),
        signal:  AbortSignal.timeout(10_000),
      });
      if (!resp.ok) throw new Error(`AD4M HTTP ${resp.status}: ${await resp.text()}`);
      const json = await resp.json() as { data?: GqlResult; errors?: { message: string }[] };
      if (json.errors?.length) {
        const msg = json.errors[0].message;
        if (msg.includes("ECONNREFUSED") || msg.includes("fetch failed")) {
          throw new Error("AD4M executor not reachable. Start it with: ad4m serve --port 4000");
        }
        if (msg.includes("Unauthorized") || msg.includes("not unlocked")) {
          throw new Error(`Agent is locked. Unlock with:\ncurl -X POST ${AD4M_GQL} -H 'Content-Type: application/json' -d '{"query":"mutation { agentUnlock(passphrase: \\"YOUR_PASSPHRASE\\") { isUnlocked } }"}'`);
        }
        throw new Error(msg);
      }
      return json.data ?? {};
    }
Behavior2/5

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

No annotations are provided, placing full burden on the description. It discloses that state is immediately visible across terminals, a useful behavioral trait. However, it omits details on mutation effects, error handling, or side effects, which are important for a write operation.

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?

Two sentences with no redundancy. The first sentence front-loads the purpose and unique characteristic of shared executor. Every word contributes to understanding.

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?

For a simple write operation with 3 parameters fully described in the schema and no output schema, the description provides the key behavioral context (immediate visibility) but lacks guidance on when to use, error scenarios, or interaction with sibling tools. It is minimally adequate.

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?

Schema description coverage is 100%, so the baseline is 3. The description does not add meaningful semantics beyond what the schema already provides; it simply mentions writing a message but does not elaborate on parameter usage or constraints.

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 the tool writes a cross-terminal relay message to AD4M, with a specific verb and resource. It also adds a unique behavioral note about immediate visibility due to shared executor, distinguishing it from other tools.

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 inter-terminal communication via 'cross-terminal' and shared executor, but does not explicitly state when to use this over alternatives like relay_read or ad4m_write_memory. No exclusion criteria are provided.

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/thefranceway/mcp-ad4m'

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