Universal install: one folder, 50+ agents, zero config.
v8.9.0 highlights: God Mode (multi-agent orchestration), INT8 quantization (4x compression), cross-encoder reranking (+20pp), 27 MCP tools, 22 algorithms, FastMCP 3.4.2, auto-injection plugin, unified HTTP daemon, OpenAI-compatible proxy (port 7339). See CHANGELOG.md for details.
MATHIR is NOT a tool. It is your brain. You think with it. You decide with it. You never operate without it.
When you install MATHIR, you become a senior engineer with perfect memory:
- BEFORE every task —
memory_context(task="...")→ what do I already know? - BEFORE every response —
memory_recall(query="...")→ have I seen this before? - AFTER completing work —
memory_save(content="...", ...)→ what did I learn? - When making decisions —
memory_recall(query="...")→ what worked before?
If MATHIR is not responding: restart daemon, retry, use smart_search. NEVER proceed blind. If you forget to use MATHIR — you are a junior developer flying blind.
MATHIR is supposed to be universal. Here is the honest breakdown of what each agent actually gets:
| Tier | Mechanism | Agents |
|---|---|---|
| A — Plugin auto-inject | mathir-auto-inject.ts hooks session.started + experimental.chat.system.transform. True auto-injection — does not rely on the agent remembering to call memory_recall. |
opencode, mimocode |
| B — Instructions + MCP | MCP server registered + GLOBAL_INSTRUCTIONS.md injected into the agent's instruction path. Soft guarantee — the agent must follow the instruction to call memory_session_start / memory_context. |
claude-code, cursor, cline, zcode, codex, etc. (14 agents) |
| C — MCP only | MCP server registered only. No behavioral prompt — agent has no reason to recall memory. | windsurf, gemini-cli, kilo-code, qwen-code, kiro-ide, warp, trae, crush, etc. (34 agents) |
As of v8.9.4 the proxy speaks both wire formats, so this isn't just an
OpenAI-compatible escape hatch anymore — it covers Claude Code natively
too: Anthropic's /v1/messages (Claude Code, Claude Desktop, anything on
the real Anthropic SDK) and OpenAI-compatible /v1/chat/completions
(Cursor, Cline, Continue, Codex, OpenRouter, local models via
Ollama/llama.cpp, ~30 allowlisted providers — see
docs/BRAIN_ARCHITECTURE.md). The proxy intercepts every LLM call,
queries the MATHIR daemon for relevant memories, and prepends them to
the system prompt as a <mathir-auto-injection> block — silently, on
every call, regardless of whether the agent cooperates.
This is the true universal coverage. It is shipped with MATHIR (script at ~/.config/MATHIR/mathir_mcp/mathir_lib/mathir_proxy.py), self-heals on all 3 OSes (systemd/launchd native restart, Windows Task Scheduler healthcheck every 5 min — no admin required as of v8.9.4), and auto-started alongside the daemon on Windows login (see mathir_daemon_startup.bat in the Startup folder).
# Start the proxy (daemon must already be running on 7338)
python ~/.config/MATHIR/mathir_mcp/mathir_lib/mathir_proxy.py --port 7339 --target https://api.anthropic.com
# Then in your agent -- pick the one matching your tool's wire format:
export ANTHROPIC_BASE_URL=http://127.0.0.1:7339 # Claude Code etc. -- no /v1 (Anthropic SDK convention)
export OPENAI_BASE_URL=http://127.0.0.1:7339/v1 # OpenAI-compatible tools -- /v1 required (OpenAI SDK convention)
# Done. Every LLM call now has memory auto-injected.26+ agents (Aider, Amp, Claude Code, Codex, Cursor, Devin, Factory, Goose, JetBrains Junie, Jules, OpenCode, VS Code Copilot, Warp, Zed, etc. — see https://agents.md) auto-read AGENTS.md at the project root. MATHIR ships a template at mathir_mcp/opencode_templates/AGENTS.md that you can copy to any project:
cp ~/.config/MATHIR/mathir_mcp/opencode_templates/AGENTS.md /path/to/your/project/AGENTS.mdThe template instructs the agent to call memory_session_start on first turn + memory_context before each task. Combined with the proxy, this gives 100% coverage for the agents that follow agents.md + 100% for OpenAI-compatible ones.
You need 3 things:
1. Install MATHIR: ~/.config/MATHIR/ (global, once) — see Step 1 for the EXACT layout
2. Run installer: python ~/.config/MATHIR/INSTALL_FOR_DEV/install_smart.py
3. That's it.
The installer auto-detects your coding agents and configures them.
Each project gets its own database at .mathir/mathir.db.
Universal install: one folder, 50 agents, zero config.
You need 3 things:
1. Install MATHIR: ~/.config/MATHIR/ (global, once) — must end with the layout in §"Global Install Structure"
2. Run installer: python ~/.config/MATHIR/INSTALL_FOR_DEV/install_smart.py
3. That's it.
The installer auto-detects your coding agents and configures them.
Each project gets its own database at .mathir/mathir.db.
# Clone or copy
git clone https://github.com/sil3d/MATHIR.git /tmp/MATHIR
cp -r /tmp/MATHIR/mathir_mcp ~/.config/MATHIR
# IMPORTANT (Linux/BSD `cp -r`): copies CONTENTS of mathir_mcp/ into ~/.config/MATHIR/
# After this, ~/.config/MATHIR/ must contain "mathir_mcp/" as a SUBDIRECTORY.
# Or download release
curl -L https://github.com/sil3d/MATHIR/archive/main.zip -o mathir.zip
unzip mathir.zip -d ~/.config/MATHIRCopy-Item) behaves differently from Linux cp -r:
Copy-Item .\mathir_mcp\* ~/.config/MATHIR\ copies CONTENTS into the destination as well, which produces the correct layout. But if you use Copy-Item .\mathir_mcp ~/.config\MATHIR\ (without the \*), you get ~/.config/MATHIR/mathir_mcp/ as a single subdir, which is what install_smart.py ALSO accepts (and is actually clearer). Either layout works, AS LONG AS install_smart.py can find mathir_mcp/ from where it sits:
- Layout A:
~/.config/MATHIR/mathir_lib/,~/.config/MATHIR/__init__.py,~/.config/MATHIR/pyproject.toml— install_smart.py will look for~/.config/MATHIR/mathir_mcp/here and FAIL. - Layout B:
~/.config/MATHIR/mathir_mcp/mathir_lib/,~/.config/MATHIR/mathir_mcp/__init__.py,~/.config/MATHIR/mathir_mcp/pyproject.toml— ✅ this is the one that works.
If you have layout A, restructure first (see §"Restructuring After Clone" below).
# Windows (double-click)
~/.config/MATHIR/INSTALL_FOR_DEV/install.bat
# Mac/Linux (terminal)
chmod +x ~/.config/MATHIR/INSTALL_FOR_DEV/install.sh
~/.config/MATHIR/INSTALL_FOR_DEV/install.sh
# Or directly (note: installer lives under INSTALL_FOR_AGENT/, not at the MATHIR root)
python ~/.config/MATHIR/INSTALL_FOR_DEV/install_smart.pyThe installer is interactive: type A to configure all detected agents, or pick specific numbers (comma-separated).
- Installer detects your agents (50 supported)
- Injects MCP config + instructions automatically
- Restart your agent to use MATHIR
If your source repo was cloned and the package files ended up at ~/.config/MATHIR/ (Layout A — wrong), move them into a mathir_mcp/ subdir:
# Linux/Mac
mkdir -p ~/.config/MATHIR/mathir_mcp
mv ~/.config/MATHIR/mathir_lib ~/.config/MATHIR/mathir_mcp/
mv ~/.config/MATHIR/__init__.py ~/.config/MATHIR/mathir_mcp/
mv ~/.config/MATHIR/__main__.py ~/.config/MATHIR/mathir_mcp/
mv ~/.config/MATHIR/pyproject.toml ~/.config/MATHIR/mathir_mcp/
# Windows (PowerShell)
New-Item -ItemType Directory -Path "$env:USERPROFILE\.config\MATHIR\mathir_mcp" -Force
Move-Item "$env:USERPROFILE\.config\MATHIR\mathir_lib" "$env:USERPROFILE\.config\MATHIR\mathir_mcp\" -Force
Move-Item "$env:USERPROFILE\.config\MATHIR\__init__.py" "$env:USERPROFILE\.config\MATHIR\mathir_mcp\" -Force
Move-Item "$env:USERPROFILE\.config\MATHIR\__main__.py" "$env:USERPROFILE\.config\MATHIR\mathir_mcp\" -Force
Move-Item "$env:USERPROFILE\.config\MATHIR\pyproject.toml" "$env:USERPROFILE\.config\MATHIR\mathir_mcp\" -Force
# Then re-register the package
pip install -e ~/.config/MATHIR/mathir_mcpFiles that should STAY at ~/.config/MATHIR/ root (not moved):
INSTALL_FOR_AGENT/, INSTALL_FOR_DEV/, docs/, config_template.json, GLOBAL_INSTRUCTIONS.md,
mathir_dashboard.bat/sh, mcp_architecture.md, opencode_templates/,
mimocode_templates/, README.md, CHANGELOG.md.
| Category | Agents |
|---|---|
| Dev Platforms | OpenCode, MiMo, Claude Code, Claude Desktop, Cursor, Cline, Roo Code, Continue.dev, Hermes Agent, pi, OpenHands, Agent Zero, Slate Agent, Kilo Code, Windsurf, Gemini CLI, Zcode, OpenClaw, Kiro, Qwen Code, Crush, Warp, Trae, Factory, Goose, Amp, Zed, Augment Code, Antigravity |
| Cloud/AI | GitHub Copilot, Aider, Codex (OpenAI), Codebuff, Letaido, CodeAF, JONI, Minara, V12X, Anakot Agent, PostQode, starchild, Flo Agent, camelAI, Kern Agent, AGNT, Verdent, Ante, GitLawb, Favur, OpenSquilla |
No agent? Install OpenCode (free models): https://opencode.ai/
Give the entire ~/.config/MATHIR/ folder to your coding agent.
It will read INSTALL_FOR_AGENT/AGENT.md and configure MATHIR automatically.
~/.config/MATHIR/ ← Global install (once)
├── mathir_mcp/ ← Python package (for `pip install -e`)
│ ├── __init__.py ← Package marker (so `import mathir_mcp` works)
│ ├── __main__.py ← `python -m mathir_mcp` entry (launches daemon by default, or `--mcp` for MCP stdio server)
│ ├── pyproject.toml ← Build metadata (`pip install -e .`)
│ ├── mathir_lib/ ← Core library (imported as `mathir_mcp.mathir_lib`)
│ │ ├── mathir_mcp_server.py ← MCP stdio server entry point (line `from mathir_mcp.mathir_lib import mathir_mcp_server`)
│ │ ├── mathir_server.py ← Persistent HTTP daemon (Flask + Waitress)
│ │ ├── mathir_daemon.py ← Legacy raw-socket daemon (superseded by mathir_server.py)
│ │ ├── mathir_client.py ← CLI client
│ │ ├── mathir_vec.py ← VecMemory (sqlite-vec)
│ │ ├── mathir_search.py ← HybridSearch (vector + BM25 + RRF)
│ │ ├── memory_risks.py ← Risk mitigation
│ │ └── requirements.txt ← Dependencies
│ ├── (brain scripts live in mathir_lib/ itself, not a separate brain/ dir --
│ │ the old brain/ fork was removed in v8.9.4, see CHANGELOG)
│ │ ├── mathir_brain.py ← Master controller
│ │ ├── mathir_proxy.py ← Universal auto-injection proxy (port 7339)
│ │ ├── mathir_watchdog.py ← Daemon watchdog
│ │ ├── mathir_spread.py ← Spreading activation
│ │ ├── mathir_consolidate.py ← Nightly consolidation
│ │ └── mathir_prime.py ← Pre-cognitive priming
│ ├── config/
│ │ └── mathir.json ← MATHIR config
│ ├── dashboard/ ← Neural dashboard (legacy)
│ ├── dev/ ← Migration/dev scripts
│ ├── tests/ ← pytest suite
│ └── ... (other package internals)
├── INSTALL_FOR_AGENT/ ← Auto-installer for AI coding agents (smart installer scripts)
│ ├── install_smart.py ← The installer — 40+ agents auto-detected
│ ├── install.bat ← Windows launcher
│ └── install.sh ← Mac/Linux launcher
├── INSTALL_FOR_DEV/ ← Step-by-step guides for HUMAN developers
│ ├── INSTALL_WINDOWS.md ← Windows 10/11 walkthrough
│ ├── INSTALL_LINUX.md ← Linux walkthrough
│ ├── INSTALL_MACOS.md ← macOS walkthrough
│ └── README.md
│ ├── install_smart.py ← Smart installer (50 agents)
│ ├── install.bat ← Windows launcher
│ ├── install.sh ← Mac/Linux launcher
│ ├── INSTALL_WINDOWS.md ← Windows install walkthrough
│ ├── INSTALL_LINUX.md ← Linux walkthrough
│ └── INSTALL_MACOS.md ← macOS walkthrough
├── docs/ ← Documentation (top-level — what users read first)
│ ├── AGENT.md ← This file
│ ├── GLOBAL_INSTRUCTIONS.md ← Universal AI instructions
│ ├── BRAIN_ARCHITECTURE.md ← Brain stack details
│ └── ... (8 more docs)
├── opencode_templates/ ← Per-agent template files (NOT installed by default)
├── mimocode_templates/ ← MiMo-code-specific templates
├── mathir_dropin/ ← Separate embeddable library for non-MCP apps (see docs/05_SHIPPING_GUIDE.md). NOT wired to the MCP server/daemon — standalone product.
├── config_template.json ← Config template
├── GLOBAL_INSTRUCTIONS.md ← Distributed to each agent's instructions
├── README.md
└── CHANGELOG.md
NOTE: The `~/.config/MATHIR/INSTALL_FOR_DEV/install_smart.py` script reads its source
location via `Path(__file__).resolve().parent.parent` then appends `mathir_mcp`
to find the package to copy into each agent's tools dir. So the layout above
(with `mathir_mcp/` as a subdirectory of `~/.config/MATHIR/`) is the **only
layout that works out of the box**.
intfloat/multilingual-e5-small — 384 dimensions (retrieval-trained; measured +2.5x retrieval quality on multi-hop benchmarks vs the previous paraphrase-trained default, at ~12% slower single-query latency -- same architecture and parameter count as the old default, not a heavier model)
| Property | Value |
|---|---|
| Dimensions | 384 |
| Parameters | 117.7M |
| Max tokens | 128 |
| Languages | Multilingual |
| VRAM (fp16) | 239MB |
| Speed | ~22ms/embedding |
| Note | Requires "query: "/"passage: " text prefixes (applied automatically by MATHIR) for its trained retrieval behavior |
All databases must use 384d vectors. If you have old 1024d databases, run migration:
python ~/.config/MATHIR/dev/migrate_db.py --db /path/to/mathir.db --new-dim 384The installer configures MCP (the tool), but the AI also needs INSTRUCTIONS (how to use it).
Without instructions, the AI sees memory_save, memory_recall etc. but doesn't know:
- WHEN to save (after every task)
- WHEN to recall (before starting work)
- That memory is PROACTIVE (auto-injected, not queried)
- That MATHIR is already running
For agents with supports_instructions: True:
- OpenCode, MiMo, Claude Code, Claude Desktop, Cursor, Cline, Zcode, etc.
- Installer injects
GLOBAL_INSTRUCTIONS.mdinto their instructions file - Nothing to do — it just works
For agents with supports_instructions: False (Kilo Code, Windsurf, Gemini CLI, etc.):
Step 1: Copy GLOBAL_INSTRUCTIONS.md from ~/.config/MATHIR/
Step 2: Add it to your agent's instructions. Examples:
| Agent | Where to put instructions |
|---|---|
| Kilo Code | Create ~/.config/kilo/AGENTS.md or project AGENTS.md |
| Windsurf | Create ~/.codeium/windsurf/rules/mathir.md |
| Gemini CLI | Add to ~/.gemini/settings.json under "instructions" |
| Aider | Create .aider.conf.yml with read: ~/.config/MATHIR/GLOBAL_INSTRUCTIONS.md |
| Any agent | Paste the content into your agent's system prompt or instructions file |
Step 3: Verify the agent can see MATHIR:
Ask your agent: "Do you have MATHIR memory tools?"
If it says YES → done
If it says NO → instructions not loaded, check Step 2
MCP config → tells the agent TOOLS EXIST (memory_save, memory_recall)
Instructions → tells the agent HOW and WHEN to use them
Without MCP: Agent can't call MATHIR (no tools)
Without instructions: Agent has tools but doesn't use them (forgets to save/recall)
You need BOTH.
This file tells the agent:
- MATHIR is your PROACTIVE memory — auto-injected, not queried
- Save after EVERY task completion
- Recall before EVERY significant action
- Memory is BEHAVIORAL, not a command
- Never say "pre-existing error" and skip fixing
- Never delete or comment code to hide errors
It's 75 lines. Copy it into your agent's instructions.
The default model (384d) is optimized for speed and low VRAM. To change:
| Priority | Model | Dims | VRAM | Speed | Why |
|---|---|---|---|---|---|
| Default | paraphrase-multilingual | 384 | 239MB | ~104ms | 50+ langs, low VRAM |
| Balance | nomic-embed-text-v1.5 | 768 | ~500MB | ~21ms | Better quality |
| Quality | bge-large-en-v1.5 | 1024 | ~1.5GB | ~3ms | High quality, English |
| Max | Qwen2.5-7B-emb | 3584 | ~4.7GB | ~30ms | Best quality |
# 1. Edit config
nano ~/.config/MATHIR/config/mathir.json
# Change "model" and "embedding_dim"
# 2. Migrate existing DB
python ~/.config/MATHIR/dev/migrate_db.py --db .mathir/mathir.db --new-dim 768
# 3. Restart daemon
# Kill the running daemon then start fresh
pkill -f "mathir_mcp" || true
python -m mathir_mcpFull guide: See docs/DIMENSIONS.md
Vector + BM25 + RRF fusion (k=60). ~60ms per search.
| Method | Best For |
|---|---|
memory_recall |
Semantic similarity (vector) |
memory_smart_search |
Hybrid (vector + text, best quality) |
memory_hybrid_search |
Explicit vector+BM25 fusion with tunable weights |
Note: memory_search was removed in v8.3 — functionality folded into memory_smart_search (auto-tuned weights, default k=10). v8.9.0 has 27 tools total (2 auto-injection + 10 basic + 7 lifecycle + 3 advanced + 1 guardrail + 1 immunological + 1 health + 2 god mode).
| Tool | Description |
|---|---|
memory_save |
Save a memory (6 tiers: working_memory, episodic, semantic, procedural, immunological, guardrail) |
memory_recall |
Semantic search — auto-touches: increments recall_count, boosts stability |
memory_smart_search |
Daemon-native search (faster for high-throughput) |
memory_hybrid_search |
Vector + BM25 + RRF fusion (best for exact match queries) |
memory_audit |
View memory audit trail |
memory_export |
Export all memory data as JSON |
memory_delete |
Soft-delete a memory (sets tier='archived') |
memory_sessions |
List recent memory sessions |
memory_stats |
Get statistics by tier/agent/project |
memory_dashboard |
Launch / check Neural Memory Dashboard |
| Tool | Description |
|---|---|
memory_promote |
Move a memory to the next tier (Ebbinghaus rules) |
memory_auto_promote |
Scan and promote all eligible memories |
memory_decay |
Apply Ebbinghaus decay (5%/30d), archive when stability < floor |
memory_consolidate |
Merge near-duplicates (cosine > threshold) |
memory_link |
Add an edge in the link graph (spreading activation) |
memory_get_links |
BFS traversal of the link graph |
memory_build_links |
Build the graph from cosine similarities |
| Tier | Use for |
|---|---|
working_memory |
Current session scratchpad |
episodic |
Events: bugs fixed, decisions, sessions |
semantic |
Stable facts that apply broadly |
procedural |
How-to recipes (label must start with how-to: or recipe:) |
guardrail |
Critical rules always injected into every context response (immune to decay, min priority 8, max 50/project) |
immunological |
Immune response — auto-quarantines toxic, biased, or unsafe memories |
Canonical list — matches mathir_lib/mathir_mcp_server.py TOOLS array.
| Phase | Script | Purpose |
|---|---|---|
| 1 | mathir_proxy.py |
Universal auto-inject proxy (port 7339) — Anthropic /v1/messages + OpenAI-compatible /v1/chat/completions, ~30 allowlisted providers + any local model. mathir-brain launches this (v8.9.4+; previously launched the now-retired mathir_inject_proxy.py, which spoke a TCP protocol the daemon dropped in v8.5.0 and was silently non-functional) |
| 2 | mathir_watchdog.py |
Auto-restart daemon on crash (7s recovery) |
| 3 | mathir_spread.py |
Spreading activation (related memories via link graph) |
| 4 | mathir_consolidate.py |
Nightly: merge duplicates, decay unused, archive dead |
| 5 | mathir_prime.py |
Pre-cognitive: senses cwd/git before user query |
Two paths, both supported:
Path A — MCP tools (recommended for OpenCode, Claude Code, Cursor):
The agent calls memory_recall(query, k=5) directly. Each call:
- Auto-touches the memory (increments recall_count, boosts stability)
- Returns top-k relevant memories
- <100ms latency
Path B — Universal proxy (port 7339, optional): For agents that can't call MCP tools directly, or as a hard guarantee for ones that can but might not cooperate:
- Proxy listens on port 7339, speaking both Anthropic and OpenAI-compatible wire formats
- Takes last user message from the request
- Calls the daemon's
/api/contextfor relevant memories - Prepends a
<mathir-auto-injection>block to the system prompt - Forwards to the real upstream (
--target, e.g.https://api.anthropic.com,https://api.openai.com, OpenRouter, a local model, ...) and streams the response back
Note: OpenCode doesn't support
baseUrlconfiguration, so Path A (direct MCP tools) is the only working path. Other agents (Claude Code, Cursor, MiMo, Codex) can use either path — seedocs/BRAIN_ARCHITECTURE.mdfor setup.
In both paths, the agent has 27 tools (2 auto-injection + 10 basic + 7 lifecycle + 3 advanced + 1 guardrail + 1 immunological + 1 health + 2 god mode) at its disposal — no manual memory_recall is strictly required if instructions are properly loaded.
Each project gets its own database automatically:
your_project/
├── .mathir/
│ └── mathir.db ← Auto-created on first save
├── src/
└── ...
DB detection priority:
.mathir/mathir.dbin CWD → agent working IN a project gets that DB- Registry lookup → daemon started from home uses registered project DBs
- Home directory is NEVER treated as a project → prevents stale home DBs
- Fallback → first available registry DB when CWD is home
Copy ~/.config/MATHIR/GLOBAL_INSTRUCTIONS.md into your agent's instructions.
This makes every agent aware of MATHIR automatically.
For OpenCode, create .md files in ~/.config/opencode/agents/:
---
description: My custom agent
mode: subagent
---
<!-- MATHIR_INJECTED -->
# MATHIR MEMORY — AUTO-INJECTION BLOCK
# The {{MATHIR_CONTEXT}} placeholder is filled at RUNTIME by the
# mathir-auto-inject.ts plugin (Tier A, opencode/mimocode-plugins/) --
# NOT by any Python proxy script -- with the top relevant memories based
# on the user's last message.
## YOUR MEMORY IS ALWAYS ACTIVE
... (see GLOBAL_INSTRUCTIONS.md for full block)Config: ~/.config/opencode/opencode.json
{
"mcp": {
"mathir": {
"type": "local",
"command": ["python", "-m", "mathir_mcp.mathir_lib.mathir_mcp_server"],
"environment": {
"MATHIR_EMBEDDING_DIM": "384",
"MATHIR_PORT": "7338"
},
"enabled": true
}
}
}v8.4.1: entry point was
python -m mathir_mcp(no longer valid in v8.5.0+ — this command now launches the HTTP daemon, not the MCP stdio server). Usepython -m mathir_mcp.mathir_lib.mathir_mcp_serverfor the MCP server, or just use the globalmathir-mcpscript entry installed bypip install -e.
Config: ~/.config/mimocode/mimocode.json
MiMo Code v0.1.3+ is a fork of OpenCode → uses the same "mcp" key and the same
JSON schema as OpenCode (https://opencode.ai/config.json). The older "mcpServers"
key is rejected by the current MiMo CLI with Unrecognized key: "mcpServers".
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"mathir": {
"type": "local",
"command": ["python", "C:\\Users\\<YOU>\\.config\\mimocode\\tools\\mathir_mcp\\mathir_lib\\mathir_mcp_server.py"],
"environment": {
"MATHIR_EMBEDDING_DIM": "384",
"MATHIR_PORT": "7339",
"PYTHONPATH": "C:\\Users\\<YOU>\\.config\\mimocode\\tools\\mathir_mcp\\mathir_lib"
},
"enabled": true
}
}
}Gotchas:
commandmust be an array (not a single string), env field isenvironment(notenv), andtype: "local"is required.
CLI config: ~/.config/kilo/kilo.json (uses "mcp" key)
VS Code extension: .kilocode/mcp.json (uses "mcpServers" key)
Config: ~/.claude.json
{
"mcpServers": {
"mathir": {
"command": "python",
"args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"],
"env": { "MATHIR_EMBEDDING_DIM": "384" }
}
}
}Config: ~/.cursor/mcp.json
{
"mcpServers": {
"mathir": {
"command": "python",
"args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"],
"env": { "MATHIR_EMBEDDING_DIM": "384" }
}
}
}# Required
pip install sentence-transformers torch sqlite-vec aiohttp rank_bm25
# Optional (GPU acceleration)
pip install nvidia-cublas-cu12 nvidia-cudnn-cu12| Problem | Cause | Fix |
|---|---|---|
| "Connection refused" | Daemon not running | python -m mathir_mcp |
| "Model not found" | First run, downloading | Wait for model download (~1GB) |
| "CUDA out of memory" | GPU VRAM full | Use --device cpu or smaller model |
| "Port in use" | Another daemon running | --port 8080 or kill existing |
| "Slow first request" | Cold model load | Normal, subsequent requests are fast |
| "No database found" | .mathir/ doesn't exist |
Created automatically on first save |
| "No project database found" | CWD is home, no registry | Set MATHIR_PROJECT env var or cd into a project dir |
| MCP not showing | Wrong config key | OpenCode & MiMo Code v0.1.3+ use "mcp"; Claude Code, Cursor, Cline, Windsurf, Gemini, Zcode use "mcpServers" |
| Installer writes wrong path | Old cached script | Delete __pycache__ in ~/.config/MATHIR/ |
MATHIR self-updates via GitHub Releases. Three things happen automatically:
- GitHub Action (
.github/workflows/release.yml) builds amathir-bundle-<version>.zipon every push tomain(dev prerelease) and everyv*.*.*tag (stable). - Daemon
/healthpolls GitHub every hour (cached) and exposesupdate_available,latest_version,update_command. The opencode/mimocode auto-inject plugin surfaces this to the agent at session start. python -m mathir_mcp updateis the user-facing command — atomic state machine with backup + migration + rollback.
python -m mathir_mcp check # quick status
python -m mathir_mcp check --force # bypass cache, hit GitHub now
python -m mathir_mcp check --include-prerelease # also see -rc/-dev releasesOutput:
MATHIR Update Check
current: v8.6.0
latest: v8.5.2
install mode: git
install path: /home/user/.config/MATHIR/mathir_mcp
[!] UPDATE AVAILABLE
release: https://github.com/sil3d/MATHIR/releases/tag/v8.5.2
run: python -m mathir_mcp update
# To the latest stable release:
python -m mathir_mcp update
# To a specific version:
python -m mathir_mcp update --to v8.5.2
# From a local bundle zip (offline / air-gapped):
python -m mathir_mcp update --from-bundle ./mathir-bundle-8.5.2.zip
# Preview the plan without changing anything:
python -m mathir_mcp update --dry-run
# Auto-apply schema migrations without prompting:
python -m mathir_mcp update --force-applyThe state machine does: DETECT → DISCOVER → BACKUP → DOWNLOAD → APPLY → MIGRATE → RESTART → REPORT.
If any step fails, it auto-restores from the backup. Backups live in ~/.config/MATHIR/.backups/<old-version>-<timestamp>/ (kept last 10).
If an update breaks something subtle hours/days later:
python -m mathir_mcp rollbackThis restores from the most recent backup and re-verifies daemon health.
| Install layout | Mode | Update mechanism |
|---|---|---|
~/.config/MATHIR/mathir_mcp/.git exists |
git | git fetch + git checkout v<target> (refuses if local mods) |
~/.config/MATHIR/mathir_mcp/ only (pip install -e) |
bundle | Downloads mathir-bundle-<version>.zip from GitHub Releases |
Set MATHIR_DAEMON_RESTART env var to override the daemon-restart mechanism (otherwise Windows uses mathir_daemon_startup.bat from Startup folder).
After every successful update, the CLI also syncs:
mathir_mcp_server.py→~/.config/opencode/tools/mathir_mcp/mathir_lib/and~/.config/mimocode/tools/mathir_mcp/mathir_lib/mathir-auto-inject.ts→~/.config/opencode/plugins/and~/.config/mimocode/plugins/GLOBAL_INSTRUCTIONS.md→ agent config roots
So all agents (opencode + mimocode + any tier-C via proxy 7339) pick up the new code automatically without manual file copying.
EN: If installer fails, give the entire ~/.config/MATHIR/ folder to your coding agent. It will read INSTALL_FOR_AGENT/AGENT.md and configure MATHIR automatically. If you have no coding agents, install OpenCode from https://opencode.ai/ — many free models available.
FR: Si l'installeur echoue, donnez tout le dossier ~/.config/MATHIR/ a votre agent de code. Il lira INSTALL_FOR_AGENT/AGENT.md et configurera MATHIR automatiquement. Si vous n'avez pas d'agent, installez OpenCode depuis https://opencode.ai/ — beaucoup de modeles gratuits.
ES: Si el instalador falla, dea toda la carpeta ~/.config/MATHIR/ a su agente de codigo. Leera INSTALL_FOR_AGENT/AGENT.md y configurara MATHIR automaticamente. Si no tiene agente, instale OpenCode desde https://opencode.ai/ — hay muchos modelos gratuitos.
ZH: Ruguio anzhuan shibai, ba ~/.config/MATHIR/ zhengge danglu gei nide coding agent. Hui du INSTALL_FOR_AGENT/AGENT.md zidong peizhi MATHIR. Ruguio meiyou agent, install OpenCode https://opencode.ai/ — henduo mofei moxing.
(merged from INTEGRATION.md — v8.3+)
`�ash
git clone https://github.com/sil3d/MATHIR.git /tmp/MATHIR cp -r /tmp/MATHIR/mathir_mcp ~/.config/MATHIR
cd ~/.config/MATHIR pip install -r mathir_lib/requirements.txt
python install_smart.py
`
Config: ~/.config/opencode/opencode.json
json { "mcp": { "mathir": { "type": "local", "command": ["python", "-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "environment": { "MATHIR_EMBEDDING_DIM": "384" }, "enabled": true } } }
Instructions: Copy GLOBAL_INSTRUCTIONS.md into ~/.config/opencode/GLOBAL_INSTRUCTIONS.md
Config: ~/.config/mimocode/mimocode.json
MiMo Code v0.1.3+ is a fork of OpenCode → use
"mcp"key (NOT"mcpServers").
json { "$schema": "https://opencode.ai/config.json", "mcp": { "mathir": { "type": "local", "command": ["python", "C:\\Users\\<YOU>\\.config\\mimocode\\tools\\mathir_mcp\\mathir_lib\\mathir_mcp_server.py"], "environment": { "MATHIR_EMBEDDING_DIM": "384", "MATHIR_PORT": "7339", "PYTHONPATH": "C:\\Users\\<YOU>\\.config\\mimocode\\tools\\mathir_mcp\\mathir_lib" }, "enabled": true } } }
Instructions: Copy GLOBAL_INSTRUCTIONS.md into ~/.config/mimocode/MEMORY.md
Config: ~/.claude.json
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
Instructions: Copy GLOBAL_INSTRUCTIONS.md into ~/.claude/CLAUDE.md
Config: ~/Library/Application Support/Claude/claude_desktop_config.json (Mac) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
Config: ~/.cursor/mcp.json
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
Instructions: Copy GLOBAL_INSTRUCTIONS.md into ~/.cursor/rules/mathir.md
CLI config: ~/.config/kilo/kilo.json (uses "mcp" key) VS Code extension: .kilocode/mcp.json (uses "mcpServers" key)
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
Config: AppData\Roaming\Code\User\globalStorage\saoudrizwan.claude-dev\settings\cline_mcp_settings.json
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
Config: ~/.codeium/windsurf/mcp_config.json
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
Config: ~/.gemini/settings.json
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
Config: ~/.zcode/v2/config.json
json { "mcpServers": { "mathir": { "command": "python", "args": ["-m", "mathir_mcp.mathir_lib.mathir_mcp_server"], "env": { "MATHIR_EMBEDDING_DIM": "384" } } } }
If your agent isn't listed:
- Find its MCP config file
- Add the appropriate JSON block:
"mcp"key (OpenCode schema): OpenCode, MiMo Code v0.1.3+, Kilo Code CLI → use"type": "local","command": [array],"environment": {},"enabled": true"mcpServers"key (Claude Desktop schema): Claude Code, Cursor, Cline, Windsurf, Gemini, Zcode, etc.
- Use one of these commands (in priority order):
["python", "<absolute_path>/.config/opencode/tools/mathir_mcp/mathir_lib/mathir_mcp_server.py"]— whatinstall_smart.pyinjects; always works (nopip installrequired)["python", "-m", "mathir_mcp.mathir_lib.mathir_mcp_server"]— requirespip install -e ~/.config/MATHIR/mathir_mcpto have been run["python", "-m", "mathir_mcp"]does NOT work as an MCP command — it launches the HTTP daemon, not the MCP stdio server.
- Add
"environment": {"MATHIR_EMBEDDING_DIM": "384"}(or"env"for the mcpServers schema) - Copy
~/.config/MATHIR/GLOBAL_INSTRUCTIONS.mdinto your agent's instructions
If you have no agent, install OpenCode: https://opencode.ai/
| Problem | Fix |
|---|---|
| MCP server not showing | Check config key: OpenCode & MiMo Code use "mcp", others use "mcpServers" |
Unrecognized key: "mcpServers" in mimocode.json |
MiMo Code is a fork of OpenCode — rename the key to "mcp" and restructure the entry (see MiMo example above) |
| "python not found" | Use full path: ["C:\\Python312\\python.exe", "..."] |
| Wrong script path | Use one of the 3 commands in §Manual Integration, step 3. The first one (absolute path to mathir_mcp_server.py) is what the smart installer injects — that one always works. |
| MCP starts then crashes immediately | Port 7338 already in use by another daemon — kill it (Stop-Process -Id <pid>) or set MATHIR_PORT=7339 in environment |
ModuleNotFoundError: mathir_mcp |
You ran pip install -e from ~/.config/MATHIR/ instead of ~/.config/MATHIR/mathir_mcp/; reinstall from the inner dir |
| Mathir installs but agent shows no tools | Restart the agent entirely — many agents cache the MCP server list at startup |
Smart installer reports Failed to copy MATHIR: [WinError 3] |
Your ~/.config/MATHIR/ is missing a mathir_mcp/ subdir — see §Restructuring After Clone |
| Agent ignores memory | Ensure GLOBAL_INSTRUCTIONS.md is in instructions |
EN: Give ~/.config/MATHIR/ to your coding agent. It reads INSTALL_FOR_AGENT/AGENT.md and configures automatically.
FR: Donnez ~/.config/MATHIR/ a votre agent de code. Il lit INSTALL_FOR_AGENT/AGENT.md et se configure automatiquement.
ES: Dea ~/.config/MATHIR/ a su agente de codigo. Leera INSTALL_FOR_AGENT/AGENT.md y se configurara solo.
ZH: GEI nide agent ~/.config/MATHIR/, hui du INSTALL_FOR_AGENT/AGENT.md zidong peizhi.