Skip to main content
Glama

ad4m_recall

Query semantic links in a Perspective using optional filters for source, predicate, or target to find specific relationships.

Instructions

Query links from a Perspective by source, predicate, or target. Omit any field to match all.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
perspective_uuidYesPerspective UUID to query
sourceNoFilter by source URI
predicateNoFilter by predicate URI
targetNoFilter by target URI

Implementation Reference

  • src/index.ts:326-350 (registration)
    Tool registration for 'ad4m_recall' on the MCP server. Defines schema with optional source/predicate/target filters and delegates to an inline async handler.
    // 5. ad4m_recall
    server.tool("ad4m_recall",
      "Query links from a Perspective by source, predicate, or target. Omit any field to match all.",
      {
        perspective_uuid: z.string().describe("Perspective UUID to query"),
        source:           z.string().optional().describe("Filter by source URI"),
        predicate:        z.string().optional().describe("Filter by predicate URI"),
        target:           z.string().optional().describe("Filter by target URI"),
      },
      async ({ perspective_uuid, source, predicate, target }) => {
        const query: Record<string, string> = {};
        if (source)    query.source    = source;
        if (predicate) query.predicate = predicate;
        if (target)    query.target    = target;
        const data = await gql(
          `query Q($uuid: String!, $q: LinkQuery!) {
             perspectiveQueryLinks(uuid: $uuid, query: $q) {
               author timestamp data { source predicate target }
             }
           }`,
          { uuid: perspective_uuid, q: query }
        );
        return ok(data.perspectiveQueryLinks);
      }
    );
  • Inline async handler for ad4m_recall: builds a LinkQuery from optional filter params, executes a GraphQL perspectiveQueryLinks query against the AD4M executor, and returns the matching links.
    async ({ perspective_uuid, source, predicate, target }) => {
      const query: Record<string, string> = {};
      if (source)    query.source    = source;
      if (predicate) query.predicate = predicate;
      if (target)    query.target    = target;
      const data = await gql(
        `query Q($uuid: String!, $q: LinkQuery!) {
           perspectiveQueryLinks(uuid: $uuid, query: $q) {
             author timestamp data { source predicate target }
           }
         }`,
        { uuid: perspective_uuid, q: query }
      );
      return ok(data.perspectiveQueryLinks);
    }
  • Zod schema for ad4m_recall: requires perspective_uuid (string), optional source/predicate/target (strings).
    {
      perspective_uuid: z.string().describe("Perspective UUID to query"),
      source:           z.string().optional().describe("Filter by source URI"),
      predicate:        z.string().optional().describe("Filter by predicate URI"),
      target:           z.string().optional().describe("Filter by target URI"),
    },
  • Generic GraphQL helper used by ad4m_recall to execute the perspectiveQueryLinks query against the AD4M executor.
    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 ?? {};
    }
  • Helper function that wraps results in the MCP content response format used by ad4m_recall to return data.
    function ok(data: unknown) {
      return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] };
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It only says 'Query links' without disclosing behavioral traits such as read-only nature, error handling, or performance implications. This is insufficient.

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 a single concise sentence with no unnecessary words. It is front-loaded and efficiently conveys the tool's purpose.

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 4 simple parameters and no output schema, the description is adequate but lacks detail on return values (structure of links). For a query tool, it is minimally complete but could be improved.

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 100% schema coverage, baseline is 3. The description adds 'Omit any field to match all', which clarifies parameter optionality and behavior beyond the schema. This adds meaningful value.

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 clearly states it queries links from a Perspective with optional filters by source, predicate, or target. It distinguishes from sibling tools like ad4m_write_memory (write) and ad4m_list_perspectives (list perspectives).

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 does not explicitly state when to use this tool vs alternatives like ad4m_classify or ad4m_get_neighbourhood. It implies usage for link queries but lacks guidance on exclusions or prerequisites.

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