Overview

cachly AI Brain — MCP Server

Every morning, your AI forgets everything — without cachly#

  • "What's your architecture?"
  • Re-explains the deployment process
  • Debugs the same bug from scratch
  • Asks what you worked on yesterday
  • About 45 minutes a day lost to context re-establishment

With cachly Brain#

  • "Ready. 23 lessons, last session: deployed API."
  • Knows your deployment process cold
  • "You fixed this March 12, exact command: ..."
  • Picks up exactly where you left off
  • About 0 minutes — the Brain arrives pre-briefed every time

One command, everything configured#

Run once. It signs you in, detects all your editors, writes every MCP config, creates a CLAUDE.md Brain file, and installs a git hook that learns from every commit automatically.

npx @cachly-dev/mcp-server@latest autopilot

Or configure manually, for any editor:

{
  "mcpServers": {
    "cachly": {
      "command": "npx",
      "args": ["-y", "@cachly-dev/mcp-server@latest"],
      "env": {
        "CACHLY_JWT": "your-api-key",
        "CACHLY_BRAIN_INSTANCE_ID": "your-instance-uuid"
      }
    }
  }
}

Fully automatic — nothing to call manually#

The Brain manages its own lifecycle. Sessions start when your editor connects, end when it closes, and the codebase is indexed daily in the background. You never call session_start or session_end by hand.

1. Editor opens      → session_start fires (reads previous session context)
2. First tool call   → AI gets last session summary + handoff tasks injected
3. Git branch/commit → auto-detected as session focus
4. Codebase indexed  → once per 24h in background (smart hash, skips unchanged)
5. Editor closes     → session_end fires (git-context summary saved)

Learn once, never debug it twice#

After every fix, deploy, or discovery, your AI calls learn_from_attempts automatically. It stores the exact command, what failed, and what worked.

learn_from_attempts(
  instance_id = "9d4077aa-bfa2-468b-89cd-0a8d8f3ec483",
  topic       = "fix:stripe-webhook-body",
  outcome     = "success",
  what_worked = "Use express.raw() before express.json() for /webhooks route",
  what_failed = "express.json() strips raw body — stripe.webhooks.constructEvent() throws",
  severity    = "critical",
  commands    = ["app.use('/webhooks', express.raw({type: '*/*'}))"],
  tags        = ["stripe", "webhook", "express"],
)

# 30 days later, on a new machine, in a new session:
smart_recall("stripe webhook signature")
# → "You fixed this May 9. Use express.raw() — see lesson fix:stripe-webhook-body"

Ambient Recall — memory that is just there#

The biggest reliability leak in any MCP memory system is the agent forgetting to call it. Ambient Recall flips the Brain from pull to push: relevant memory lands in your AI's context automatically, before it answers. It installs as four Claude Code hooks — no manual calls left to forget.

Hook What it does
SessionStart Your session briefing is injected the moment a session starts — recent lessons, active pitfalls, known failure modes
UserPromptSubmit Before every prompt, a relevance-gated recall runs on what you just asked. Only high-signal lessons are injected (top-K, hard token budget); trivial prompts skip recall entirely
PreToolUse Before your AI edits a file, lessons learned about that exact file are pushed into context
Stop Turns that end with a clear fix are learned automatically, with a conservative gate so the Brain never fills with noise

Every injection is booked into a local net-token ledger, and recall backs off automatically once it stops paying for itself:

$ npx @cachly-dev/mcp-server@latest ambient-stats

Ambient Recall — net-token ledger

   Turns recorded:   142
   Injected tokens:  9,860
   Prevented tokens: 31,400 (agent-reported via ambient-credit)
   NET:              +21,540 tokens
   Auto-backoff:     inactive

Every hook is fail-safe by construction: any error exits silently and your agent proceeds without the extra context, so recall can never block a turn. Editors without per-prompt hooks (Cursor, Windsurf, Cline, Copilot) get the same protocol through auto-written rules files and MCP instructions; OpenClaw agents use the createAmbientRecall() middleware.

Key tools from the 40-tool Brain surface#

Tool Category What it does
session_start / session_end Auto Fires on connection and exit; returns previous session summary, handoff tasks, open bugs, top lessons
learn_from_attempts Core Store a bug fix, deployment trick, or discovery permanently
smart_recall Core Semantic + BM25+ hybrid search over lessons, sessions, and indexed code
recall_best_solution Core Surface the best past solution before tackling a problem, with confidence score
session_handoff Handoff Save open tasks and critical context before closing a window
index_project Auto Indexes the codebase semantically once daily; smart MD5 hash skips unchanged files
brain_search Search BM25+ full-text search over lessons, session context, indexed files, and the Causal Knowledge Graph
brain_predict Predict Predict likely failure patterns before a deploy, with risk score and relevant past incidents
brain_portability Portability Model-neutrality proof — Brain ID and ready-to-paste config blocks for all 7 supported clients
ckg_inspect Graph Inspect the Causal Knowledge Graph: typed edges with Bayesian confidence scores
remember_context / recall_context Context Store and retrieve arbitrary key-value context, with glob-pattern lookup

Supported editors#

The setup wizard detects and configures all of these automatically.

Editor Config path Status
Claude Code ~/.claude/claude_desktop_config.json Native
Cursor .cursor/mcp.json Supported
Windsurf ~/.codeium/windsurf/mcp_config.json Supported
GitHub Copilot (VS Code) .vscode/settings.json Supported
Continue.dev ~/.continue/config.json Supported
Zed ~/.config/zed/settings.json Supported
Cline .vscode/settings.json Supported

For autonomous agents#

Works with LangChain, AutoGen, CrewAI, LlamaIndex, and any custom agent through the REST API. See Agents SDK for framework-specific examples.

import httpx
 
BRAIN_INSTANCE = "your-instance-id"
CACHLY_KEY = "your-api-key"
 
async def agent_learn(topic: str, what_worked: str, what_failed: str = ""):
    """Store a lesson after every task."""
    await httpx.AsyncClient().post(
        f"https://api.cachly.dev/api/v1/instances/{BRAIN_INSTANCE}/learn",
        headers={"Authorization": f"Bearer {CACHLY_KEY}"},
        json={"topic": topic, "outcome": "success",
              "what_worked": what_worked, "what_failed": what_failed}
    )
 
async def agent_recall(query: str) -> str:
    """Recall relevant past lessons before a task."""
    r = await httpx.AsyncClient().post(
        f"https://api.cachly.dev/api/v1/instances/{BRAIN_INSTANCE}/brain-search",
        headers={"Authorization": f"Bearer {CACHLY_KEY}"},
        json={"query": query, "top_k": 3}
    )
    return r.json()

Full Python, Go, Rust, Java, Kotlin, .NET, Swift, and PHP SDKs are covered in the Agents SDK docs.

← Back to all docs

Updated

Was this page helpful?