Skip to main content

khwan-mcp

Durable memory that survives the session. An MCP server that plugs Khwan — a pure AI-memory layer — into Claude Code, Claude Desktop, or any MCP client.

Khwan never runs a model. The client is the model. Its job is to persist and distil what matters into a brain you can recall in a later session or seed a subagent with — a compact, bounded set of facts instead of a replayed transcript. One account can hold many isolated cores (brains), and — on paid plans — an isolated sub-brain per end-user.

How it saves tokens (and where it doesn't)

Be honest about the mechanism — an MCP adds to a host's context, it cannot replace the transcript the host already sends. So:

  • Within one hot session, it does not save tokens. Claude Code caches its growing history (cache reads ≈ 0.1×), so re-injecting memory every turn only adds. Don't do that here.
  • Across sessions and subagents, it does. A cache dies in minutes; a session ends. Khwan persists distilled facts so the next run recalls them cheaply — no cold-replay of an old transcript, and facts that already scrolled out of context are retrievable again.

The token-smart pattern: seed once, remember durable facts (below), rather than running the full loop on every turn of a caching host. The full prepare → record loop still shines in a custom agent on a non-caching host, where replacing history with distilled memory bounds per-turn cost directly.

Install

pip install khwan-mcp          # or: uvx khwan-mcp

Connect to Claude Code

claude mcp add khwan \
  -e KHWAN_API_KEY=kwk_live_xxx \
  -e KHWAN_CORE=default \
  -- khwan-mcp

Recommended pattern (token-smart)

On a caching host like Claude Code, prefer seed + remember over the per-turn loop:

  1. Seed at the start of a session or subagent:

    "Call khwan_recall(query="<the task>") and use the returned seed_text as context."

  2. Remember durable facts as they emerge:

    "That's a standing decision — call khwan_remember(fact="…")."

Reinforce it in your project's CLAUDE.md, e.g.:

- At the start of a task, call `khwan_recall` to seed relevant memory.
- When a durable decision/preference/fact emerges, call `khwan_remember`.
- Don't call prepare/record every turn — it adds tokens without saving them here.

Seeding a subagent is where the win is clearest — hand it a bounded brief instead of the whole transcript:

"Recall deploy memory with khwan_recall(query="deploy runbook"), then spawn a subagent whose brief is that seed_text plus the task."

Connect to Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "khwan": {
      "command": "khwan-mcp",
      "env": {
        "KHWAN_API_KEY": "kwk_live_xxx",
        "KHWAN_CORE": "default"
      }
    }
  }
}

Configuration (environment)

Var Required Purpose
KHWAN_API_KEY yes Your key from the Khwan dashboard (kwk_live_…).
KHWAN_CORE no Select an isolated core/brain (default: the account's default core).
KHWAN_USER no Isolated sub-brain per end-user (paid); sets X-Khwan-User.
KHWAN_BASE_URL no Override the API base — e.g. http://127.0.0.1:8010 for a local engine.

Tools

Tool When
khwan_recall(query, limit=8) seed a session/subagent — compact relevant facts + seed_text.
khwan_remember(fact) persist a durable fact/preference for future sessions.
khwan_prepare(input) full loop, before answering — memory context + a turn_token.
khwan_record(turn_token, answer) full loop, after answering — persists the turn so Khwan learns.
khwan_memory(limit=20) inspect what the brain currently remembers.
khwan_cores() list the isolated cores on the account.

khwan_recall / khwan_remember are the token-smart pair for a caching host; khwan_prepare / khwan_record are the full loop for custom agents (pass the exact turn_token from prepare back into record).

Always-on memory (Claude Code hooks)

The tools above are called when Claude decides to. For deterministic memory — no reliance on the model — use the hook preset in examples/claude-code-hooks/: a UserPromptSubmit hook injects memory on every prompt and a Stop hook records every answer.

⚠️ On a caching host this is the thorough option, not the cheap one — it adds per-turn tokens. Prefer it when recall reliability matters more than token cost (or on a non-caching client); otherwise use khwan_recall at session start.

License

Proprietary — © Khwan Labs.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

khwan_mcp-0.2.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

khwan_mcp-0.2.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file khwan_mcp-0.2.1.tar.gz.

File metadata

  • Download URL: khwan_mcp-0.2.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for khwan_mcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a9b2ca4be3c7a5986c311e1f0aed31f29a4ba66c37d194c5d3047a6650753c62
MD5 348f021b8d02398c6a17fe3483eb3a02
BLAKE2b-256 713d6fd70b1932a8ba8ef2e5e422527cc2900792ff54a770203f23668442f67b

See more details on using hashes here.

File details

Details for the file khwan_mcp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: khwan_mcp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for khwan_mcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6012ca6c58aaabb39752a57fa41cd377c1ab263eb8e044457382e1dc43b8444d
MD5 26679bf01023c5f270dd47ff5428c4c7
BLAKE2b-256 0ad4a70499c9a591aa1f7eeaabd08ded85f54cac513432ad234f085619bc5427

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.2

2 files

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page