Skip to main content
Glama

recall

Search persistent memory to retrieve relevant past information, user preferences, or previous session context using semantic queries.

Instructions

Search persistent memory for relevant past information. Use when you need to check if you've encountered something before, recall past context, retrieve user preferences, or access what was learned in previous sessions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesWhat to search for. Use natural language — the search is semantic, not keyword-based.
agent_idNoIdentifier for this agent instancedefault
user_idNoUser identifier to include user-scoped memories
scopeNoSearch scope: agent (only this agent's memories), user (include user-scoped), org (include org-scoped)
tagsNoFilter by tags
limitNoMaximum number of memories to return

Implementation Reference

  • MCP tool handler for "recall" that calls the internal API endpoint.
    async ({ query, agent_id, user_id, scope, tags, limit }) => {
      const result = await apiCall("/memories/recall", "POST", {
        agent_id,
        user_id,
        query,
        scope,
        tags,
        limit,
      });
    
      const memories = (
        result as {
          memories: Array<{
            id: string;
            content: string;
            relevance_score: number;
            tags: string[];
  • Definition and registration of the "recall" tool using the MCP server SDK.
    server.tool(
      "recall",
      "Search persistent memory for relevant past information. Use when you need to check if you've encountered something before, recall past context, retrieve user preferences, or access what was learned in previous sessions.",
      {
        query: z
          .string()
          .describe(
            "What to search for. Use natural language — the search is semantic, not keyword-based.",
          ),
        agent_id: z
          .string()
          .default("default")
          .describe("Identifier for this agent instance"),
        user_id: z
          .string()
          .optional()
          .describe("User identifier to include user-scoped memories"),
        scope: z
          .enum(["agent", "user", "org"])
          .optional()
          .describe(
            "Search scope: agent (only this agent's memories), user (include user-scoped), org (include org-scoped)",
          ),
        tags: z
          .array(z.string())
          .optional()
          .describe("Filter by tags"),
        limit: z
          .number()
          .int()
          .min(1)
          .max(20)
          .default(5)
          .describe("Maximum number of memories to return"),
      },
  • Validation schema for the /recall API route.
    const recallSchema = z.object({
      agent_id: z.string().min(1).max(200),
      user_id: z.string().max(200).optional(),
      query: z.string().min(1).max(5000),
      scope: z.enum(["agent", "user", "org"]).optional(),
      tags: z.array(z.string().max(100)).max(20).optional(),
      limit: z.number().int().min(1).max(50).default(10),
    });
  • Service function that executes the core recall logic, including vector embedding search.
    export async function recall(params: RecallParams): Promise<MemoryWithScore[]> {
      const {
        apiKeyId,
        agentId,
        userId,
        orgId,
        query,
        scope,
        tags,
        limit = 10,
      } = params;
    
      const queryVector = await embed(query);
    
      // Fetch candidate memories with parameterized queries (no sql.unsafe!)
      const candidates = await sql`
        SELECT
          id, agent_id, user_id, org_id, scope, content, tags, embedding, created_at, updated_at
        FROM memories
        WHERE api_key_id = ${apiKeyId}
          AND deleted_at IS NULL
          AND embedding IS NOT NULL
          AND agent_id = ${agentId}
        ORDER BY created_at DESC
        LIMIT 500
      `;
    
      // Also fetch scope-expanded memories if needed
      let scopeMemories: any[] = [];
      if (scope === "org" && orgId) {
        scopeMemories = await sql`
          SELECT
            id, agent_id, user_id, org_id, scope, content, tags, embedding, created_at, updated_at
          FROM memories
          WHERE api_key_id = ${apiKeyId}
            AND deleted_at IS NULL
            AND embedding IS NOT NULL
            AND scope = 'org' AND org_id = ${orgId}
            AND agent_id != ${agentId}
          ORDER BY created_at DESC
          LIMIT 200
        `;
      } else if (scope === "user" && userId) {
        scopeMemories = await sql`
          SELECT
            id, agent_id, user_id, org_id, scope, content, tags, embedding, created_at, updated_at
          FROM memories
          WHERE api_key_id = ${apiKeyId}
            AND deleted_at IS NULL
            AND embedding IS NOT NULL
            AND scope = 'user' AND user_id = ${userId}
            AND agent_id != ${agentId}
          ORDER BY created_at DESC
          LIMIT 200
        `;
      }
    
      const allCandidates = [...(candidates as any[]), ...(scopeMemories as any[])];
    
      // Filter by tags if specified
      let filtered = allCandidates;
      if (tags && tags.length > 0) {
        filtered = allCandidates.filter((m: any) => {
          const memTags = m.tags || [];
          return tags.some((t) => memTags.includes(t));
        });
      }
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/AlekseiMarchenko/central-intelligence'

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