Skip to main content
Glama

context

Retrieve relevant memories, past decisions, and project knowledge at session start or topic switches to provide necessary background for conversations.

Instructions

Load relevant memories for the current task, designed for session bootstrapping. This is a read-only operation identical to recall internally, but optimized for broad context loading rather than specific questions. Call context at the start of every conversation, passing a description of what you are working on, to retrieve past decisions, preferences, and project knowledge. Also call when switching topics mid-session. Use context (not recall) for "what do I need to know about X?" and recall for "what specifically was decided about Y?". Returns up to max_memories results ranked by relevance. Costs 1 operation. Returns empty list (not error) if no relevant memories exist.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
current_contextYesDescription of what you are currently working on. Be specific: 'refactoring the authentication middleware in the Express API' retrieves better context than 'working on auth'. This is the search query for memory retrieval.
agent_idNoAgent instance identifier. Must match the agent_id used when storing memories. Default: 'default'.default
user_idNoUser identifier. When provided, also retrieves user-scoped memories shared by other agents.
max_memoriesNoMaximum memories to return, 1-20. Default 5. Use 10-15 at session start for broad context loading, 3-5 for topic switches.

Implementation Reference

  • MCP server handler for the 'context' tool. Receives current_context, agent_id, user_id, max_memories parameters, calls the API endpoint /memories/context, formats the results and returns relevant memories with relevance scores.
    // Tool 4: context
    server.tool(
      "context",
      `Load relevant memories for the current task, designed for session bootstrapping. This is a read-only operation identical to recall internally, but optimized for broad context loading rather than specific questions. Call context at the start of every conversation, passing a description of what you are working on, to retrieve past decisions, preferences, and project knowledge. Also call when switching topics mid-session. Use context (not recall) for "what do I need to know about X?" and recall for "what specifically was decided about Y?". Returns up to max_memories results ranked by relevance. Costs 1 operation. Returns empty list (not error) if no relevant memories exist.`,
      {
        current_context: z
          .string()
          .describe(
            "Description of what you are currently working on. Be specific: 'refactoring the authentication middleware in the Express API' retrieves better context than 'working on auth'. This is the search query for memory retrieval.",
          ),
        agent_id: z
          .string()
          .default("default")
          .describe("Agent instance identifier. Must match the agent_id used when storing memories. Default: 'default'."),
        user_id: z
          .string()
          .optional()
          .describe("User identifier. When provided, also retrieves user-scoped memories shared by other agents."),
        max_memories: z
          .number()
          .int()
          .min(1)
          .max(20)
          .default(5)
          .describe("Maximum memories to return, 1-20. Default 5. Use 10-15 at session start for broad context loading, 3-5 for topic switches."),
      },
      async ({ current_context, agent_id, user_id, max_memories }) => {
        const result = await apiCall("/memories/context", "POST", {
          agent_id,
          user_id,
          current_context,
          max_memories,
        });
    
        const memories = (
          result as {
            memories: Array<{
              id: string;
              content: string;
              relevance_score: number;
              scope: string;
            }>;
          }
        ).memories;
    
        if (memories.length === 0) {
          return {
            content: [
              {
                type: "text" as const,
                text: "No relevant past context found. This appears to be a new topic.",
              },
            ],
          };
        }
    
        const formatted = memories
          .map(
            (m, i) =>
              `[${i + 1}] (relevance: ${(m.relevance_score * 100).toFixed(1)}%)\n${m.content}`,
          )
          .join("\n\n");
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Loaded ${memories.length} relevant memories from past sessions:\n\n${formatted}`,
            },
          ],
        };
      },
    );
  • API route handler for POST /memories/context. Validates input using Zod schema, calls memoriesService.recall() with broader scope (org > user > agent), and returns matching memories.
    app.post("/context", async (c) => {
      const body = await c.req.json();
      const parsed = contextSchema.safeParse(body);
      if (!parsed.success) {
        return c.json({ error: "Invalid request", details: parsed.error.issues }, 400);
      }
    
      const { agent_id, user_id, current_context, max_memories } = parsed.data;
      const apiKeyId = c.get("apiKeyId");
      const orgId = c.get("orgId");
      const rawApiKey = c.get("rawApiKey");
    
      // Recall with broader scope to get max context
      const memories = await memoriesService.recall({
        apiKeyId,
        rawApiKey,
        agentId: agent_id,
        userId: user_id,
        orgId,
        query: current_context,
        scope: orgId ? "org" : user_id ? "user" : "agent",
        limit: max_memories,
      });
    
      return c.json({ memories });
    });
  • Zod input schema definition for the 'context' tool in the MCP server. Defines current_context (required string), agent_id (default 'default'), user_id (optional), and max_memories (default 5, max 20).
    `Load relevant memories for the current task, designed for session bootstrapping. This is a read-only operation identical to recall internally, but optimized for broad context loading rather than specific questions. Call context at the start of every conversation, passing a description of what you are working on, to retrieve past decisions, preferences, and project knowledge. Also call when switching topics mid-session. Use context (not recall) for "what do I need to know about X?" and recall for "what specifically was decided about Y?". Returns up to max_memories results ranked by relevance. Costs 1 operation. Returns empty list (not error) if no relevant memories exist.`,
    {
      current_context: z
        .string()
        .describe(
          "Description of what you are currently working on. Be specific: 'refactoring the authentication middleware in the Express API' retrieves better context than 'working on auth'. This is the search query for memory retrieval.",
        ),
      agent_id: z
        .string()
        .default("default")
        .describe("Agent instance identifier. Must match the agent_id used when storing memories. Default: 'default'."),
      user_id: z
        .string()
        .optional()
        .describe("User identifier. When provided, also retrieves user-scoped memories shared by other agents."),
      max_memories: z
        .number()
        .int()
        .min(1)
        .max(20)
        .default(5)
        .describe("Maximum memories to return, 1-20. Default 5. Use 10-15 at session start for broad context loading, 3-5 for topic switches."),
    },
  • Zod validation schema for the POST /memories/context API endpoint. Validates agent_id, user_id, current_context, and max_memories with constraints.
    // POST /memories/context
    const contextSchema = z.object({
      agent_id: z.string().min(1).max(200),
      user_id: z.string().max(200).optional(),
      current_context: z.string().min(1).max(5000),
      max_memories: z.number().int().min(1).max(20).default(5),
    });
  • MCP manifest registration for the 'context' tool. Defines the tool name, description, endpoint URLs, and input schema for discovery.
    {
      name: "context",
      description: "Auto-load relevant memories for the current task. Describe what you're working on, get back everything relevant.",
      endpoint: "POST /memories/context",
      x402_endpoint: "POST /x402/context",
      input: {
        agent_id: { type: "string", required: true },
        query: { type: "string", required: true, description: "Current task description" },
      },
    },
Behavior5/5

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

No annotations provided, so description carries full burden. Discloses read-only nature ('read-only operation'), cost ('Costs 1 operation'), return behavior ('Returns up to max_memories results ranked by relevance'), and edge case handling ('Returns empty list (not error) if no relevant memories exist').

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?

Eight sentences with zero waste: purpose, recall differentiation, two temporal usage rules, recall comparison, return format, cost, and empty-list behavior. Front-loaded with the core action and well-structured for scanning.

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?

No output schema exists, but description adequately explains return values ('up to max_memories results ranked by relevance', 'empty list'). Covers sibling differentiation, parameter guidance, and operational costs sufficient for a read-only retrieval tool.

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?

Despite 100% schema coverage (baseline 3), adds valuable usage semantics: concrete example for current_context ('refactoring the authentication middleware...' vs 'working on auth') and specific dosage guidance for max_memories ('Use 10-15 at session start... 3-5 for topic switches').

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?

Opens with specific verb+resource ('Load relevant memories') and explicitly states purpose ('designed for session bootstrapping'). Immediately distinguishes from sibling tool recall ('optimized for broad context loading rather than specific questions'), clarifying the unique scope.

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 instructions ('Call context at the start of every conversation', 'Also call when switching topics mid-session') and explicit when-not-to-use/alternative guidance ('Use context (not recall) for... and recall for...'), directly contrasting with the sibling recall tool.

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/AlekseiMarchenko/central-intelligence'

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