Skip to main content
Glama

memory_query

Access and filter stored observations using keywords, dates, tags, or agents. Retrieve relevant data efficiently for enhanced decision-making and problem-solving in AI-driven workflows.

Instructions

Query the memory store with advanced filters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
afterNoISO date to filter observations after
agentNoAgent that created the observations
beforeNoISO date to filter observations before
keywordNoText to search for in observations
limitNoMaximum number of results to return
tagNoTag to filter observations by

Implementation Reference

  • Registers the MCP tool 'memory_query' with the FastMCP server, including description, Zod parameter schema, and execute handler.
    server.addTool({
      name: 'memory_query',
      description: 'Query the memory store with advanced filters',
      parameters: z.object({
        keyword: z.string().optional().describe("Text to search for in observations"),
        before: z.string().optional().describe("ISO date to filter observations before"),
        after: z.string().optional().describe("ISO date to filter observations after"),
        tag: z.string().optional().describe("Tag to filter observations by"),
        agent: z.string().optional().describe("Agent that created the observations"),
        limit: z.number().optional().describe("Maximum number of results to return")
      }),
      execute: async (args) => {
        const results = await memoryStore.query({
          keyword: args.keyword,
          time: {
            before: args.before,
            after: args.after
          },
          tag: args.tag,
          agent: args.agent,
          limit: args.limit
        });
        
        return JSON.stringify({
          observations: results,
          count: results.length,
          message: `Found ${results.length} matching observations.`
        });
      }
    });
  • Defines the MemoryQuery TypeScript interface used for querying observations, matching the tool's parameter structure.
    export interface MemoryQuery {
      keyword?: string;
      time?: {
        before?: string;
        after?: string;
      };
      tag?: string;
      agent?: string;
      limit?: number;
    }
  • The execute handler for the memory_query tool, which maps arguments to MemoryQuery and calls memoryStore.query, returning JSON results.
    execute: async (args) => {
      const results = await memoryStore.query({
        keyword: args.keyword,
        time: {
          before: args.before,
          after: args.after
        },
        tag: args.tag,
        agent: args.agent,
        limit: args.limit
      });
      
      return JSON.stringify({
        observations: results,
        count: results.length,
        message: `Found ${results.length} matching observations.`
      });
    }
  • Core implementation of the query method in JsonlMemoryStore, which iterates over all entities and observations, applies filters for keyword, time, tag, and limit, returning matching results.
    async query(query: MemoryQuery): Promise<{
      entityName: string;
      observation: Observation;
    }[]> {
      await this.getLoadingPromise();
    
      const results: { entityName: string; observation: Observation }[] = [];
      const keyword = query.keyword?.toLowerCase();
    
      for (const [entityName, entity] of this.enhancedEntities.entries()) {
        for (const observation of entity.observations) {
          let matches = true;
    
          // Filter by keyword
          if (keyword && !observation.text.toLowerCase().includes(keyword)) {
            matches = false;
          }
    
          // Filter by time range
          if (query.time) {
            const obsTime = new Date(observation.timestamp).getTime();
            if (query.time.after && obsTime < new Date(query.time.after).getTime()) {
              matches = false;
            }
            if (query.time.before && obsTime > new Date(query.time.before).getTime()) {
              matches = false;
            }
          }
    
          // Filter by tag (would require additional metadata tracking)
          // This is a placeholder for future implementation
          if (query.tag) {
            // Not implemented yet
            // For now, we'll just check if the tag appears in the text
            if (!observation.text.toLowerCase().includes(query.tag.toLowerCase())) {
              matches = false;
            }
          }
    
          // Filter by agent (would require additional metadata tracking)
          // This is a placeholder for future implementation
          if (query.agent) {
            // Not implemented yet
            matches = false;
          }
    
          if (matches) {
            results.push({
              entityName,
              observation
            });
          }
        }
      }
    
      // Apply limit if specified
      if (query.limit && query.limit > 0) {
        return results.slice(0, query.limit);
      }
    
      return results;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a query operation but doesn't describe what the tool returns (e.g., format, structure), whether it's paginated, if there are rate limits, authentication requirements, or error conditions. The phrase 'advanced filters' is too vague to provide meaningful behavioral insight.

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?

The description is a single sentence that efficiently states the core function. However, it could be more front-loaded with critical context (e.g., what type of data is queried). There's no wasted text, but it may be too brief given the tool's complexity and lack of annotations.

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

Completeness2/5

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

Given 6 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'memory store' contains, what format results return, or how this differs from other query tools. For a query tool with multiple parameters and siblings offering similar functionality, more context is needed to guide proper usage.

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 all 6 parameters are documented in the schema. The description adds no additional parameter information beyond what's already in the schema (e.g., it doesn't explain how filters combine, precedence, or special syntax). Baseline score of 3 is appropriate when the schema does the heavy lifting.

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

Purpose3/5

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

The description 'Query the memory store with advanced filters' states a general purpose (querying) but is vague about what specific resource is being queried. It mentions 'memory store' but doesn't clarify if this refers to observations, entities, tasks, or other data types available in the system. Compared to siblings like 'search_nodes' or 'read_graph', the distinction is unclear.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'search_nodes', 'read_graph', or 'show_memory_path'. The description mentions 'advanced filters' but doesn't specify what makes this tool different from other query/search tools in the sibling list. There's no mention of prerequisites, limitations, or typical use cases.

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

Related 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/flight505/mcp-think-tank'

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