Integration

Long-term memory for Mastra

Mastra is the TypeScript agent framework: typed agents, MCP-first tool model, fast. Add Engram to Mastra's `MCPClient` and the agent gains six tools (`engram_store_memory`, `engram_query_memory`, and friends) with hybrid retrieval and an explanation trace on every recall.

Install

Three steps: sign up for an Engram API key, paste a BYOK LLM-provider key on /models, then drop the snippet below into Mastra.

Three steps to memory in your agent

  1. Sign up. Free, no card. You'll land on a Getting Started page that walks the next two steps.
  2. Add your LLM key. Engram is BYOK. Paste an OpenAI / Anthropic / Groq / Together / Fireworks key and we'll route every extraction and query call through your provider. You pay your provider directly. We never see your inference.
  3. Paste the snippet below into your agent and restart it. Use Authorization: Bearer <api-key>with the API key from your portal.

engram-mastra: TypeScript agent framework

Wires Engram into Mastra's MCPClient as a tool source. Routed through mcp-remote stdio bridge until Engram ships native Streamable HTTP. Source: github.com/lumetra-io/engram-mastra.

  1. Install @mastra/mcp:
  2. Terminal
    npm install @mastra/mcp
  3. Export your API key:
  4. Terminal
    export ENGRAM_API_KEY="<api-key>"
  5. Register Engram as an MCP server and pass its tools to your Agent:
  6. TypeScript
    import { MCPClient } from "@mastra/mcp";
    import { Agent } from "@mastra/core/agent";
    
    const mcp = new MCPClient({
      servers: {
        engram: {
          command: "npx",
          args: [
            "-y",
            "mcp-remote",
            "https://mcp.lumetra.io/mcp/sse",
            "--transport",
            "sse-only",
            "--header",
            `Authorization:Bearer ${process.env.ENGRAM_API_KEY}`,
          ],
        },
      },
    });
    
    const agent = new Agent({
      name: "researcher",
      instructions: "Use engram_query_memory before answering. Use engram_store_memory to save facts worth remembering.",
      model: yourModel,
      tools: await mcp.getTools(),
    });

What you can do once memory's wired in

  • Add persistent memory to a Mastra agent without writing a custom Memory class
  • Share one bucket across multiple Mastra agents in a multi-agent workflow
  • Scope per-user buckets through `process.env.USER_BUCKET` resolved at runtime
  • Use Mastra's MCP-native tool routing to combine Engram with other MCP servers in the same agent

FAQ

Why a stdio bridge instead of a direct URL?

Mastra's `MCPClient` supports both stdio (`command` + `args`) and HTTP (`url`) transports. Engram's hosted MCP is SSE-only today, and `mcp-remote` is the stdio-to-SSE bridge. Claude Code, Codex, Goose, and gptme all used the same approach historically.

Does this work with Mastra's TypeScript inference?

Yes. The tool schemas come from the MCP server's tool listing, so the model sees fully-typed tool definitions just like any other Mastra-managed tool.

What happens when Engram ships Streamable HTTP?

The config simplifies to `servers.engram.url = new URL(...)` with `requestInit.headers` for auth. The README has the forward-compatible variant ready.

Ship durable memory in Mastra today

Free tier: 10K memories and 50K retrievals per month. No credit card. Same Engram backend powers all 41 integrations, so memories you write from one client are immediately queryable from the rest.