Skip to main content
Glama

Memoria — Deterministic AI Memory & Code Intelligence MCP

Build Session Context

build_context
Read-onlyIdempotent

Assemble a token-budgeted <memory_context> XML/Markdown block from a namespace (read-only, idempotent; consumes 1 Read API call) and return { context, memories_used }. Ranks up to 500 namespace memories deterministically and packs lines greedily up to max(256, token_budget * 4) characters under "## Established Facts" (core/semantic) and "## Recent Context" (episodic/buffer). Use at session start or before planning a task to ground the model in one call; use recall_memories instead when you need raw memory objects and IDs.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "namespace": "<namespace>",
      "query": "<query>"
    },
    "name": "build_context"
  }
}

Input Schema

NameRequiredDescriptionDefault
queryYesActive task, feature, or session topic used to rank relevant facts and history.
namespaceYesLogical workspace namespace to ground context around (never prefix with "org:").
token_budgetNoMaximum token budget (~4 characters per token, default 4096) before truncating lower-ranked items.

Output Schema

NameRequiredDescriptionDefault
contextYesFormatted <memory_context>...</memory_context> block.
memories_usedYesNumber of memories packed within token_budget.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed5 schema fields changed
    • changedInput schema / properties / namespace / description
      Previous value: -"Workspace namespace to ground context around."New value: +"Logical workspace namespace to ground context around (never prefix with \"org:\")."
    • changedInput schema / properties / query / description
      Previous value: -"Task or topic query to assemble relevant context for."New value: +"Active task, feature, or session topic used to rank relevant facts and history."
    • addedInput schema / properties / token_budget / default
      Added value: +4096
    • changedInput schema / properties / token_budget / description
      Previous value: -"Maximum token budget for assembled context (default 4096)."New value: +"Maximum token budget (~4 characters per token, default 4096) before truncating lower-ranked items."
    • changedOutput schema / (root)
      Previous value: -nullNew value: +{
      +  "properties": {
      +    "context": {
      +      "description": "Formatted <memory_context>...</memory_context> block.",
      +      "type": "string"
      +    },
      +    "memories_used": {
      +      "description": "Number of memories packed within token_budget.",
      +      "type": "integer"
      +    }
      +  },
      +  "required": [
      +    "context",
      +    "memories_used"
      +  ],
      +  "type": "object"
      +}
  2. First observed

TDQS

A4.8/5.0
Behavior5/5

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

Beyond the readOnly/idempotent/non-destructive annotations, the description discloses cost ('consumes 1 Read API call'), determinism and the 500-memory ranking cap, the greedy packing rule with an explicit character formula, and the exact section layout of the output. This is substantive operational context the annotations cannot convey.

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?

Three sentences, front-loaded with the verb and return shape, then mechanics, then routing guidance — no filler. The middle sentence is dense with parenthetical and formula detail that slightly strains readability, but no sentence is expendable.

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?

For a 3-parameter tool with full schema coverage, complete annotations, and an output schema, the description covers purpose, cost, ranking behavior, output shape, and the sibling alternative. Nothing an agent needs to invoke it correctly is missing.

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?

Schema coverage is 100%, so the baseline is 3, but the description adds meaning beyond the schema by tying token_budget to an actual output size formula (max(256, token_budget * 4) characters) and by noting the namespace is ranked over up to 500 memories. The 'never prefix with org:' caveat lives in the schema, not repeated here.

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 opens with a specific verb and artifact: 'Assemble a token-budgeted <memory_context> XML/Markdown block from a namespace,' and explicitly contrasts itself with recall_memories for raw objects/IDs. An agent can distinguish it from every sibling without opening a schema.

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?

It states both when to use it ('at session start or before planning a task to ground the model in one call') and when not to ('use recall_memories instead when you need raw memory objects and IDs'). The alternative and the selecting condition are named outright.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.