A community-driven registry for the Claude Code ecosystem. Not affiliated with Anthropic.
Are you the author? Sign in to claim
A production-ready MCP server that builds a world model for codebases, preventing hallucinations, repeated mistakes, and
Enforcement, provenance, and harness-neutral memory for AI coding agents. A temporal knowledge graph that validates code changes against learned constraints at the edit boundary, re-injects relevant context after compaction, tracks contradictions with confidence-weighted resolution, and runs across Claude Code, Cursor, and pi.
Status: v0.7.5 -- 26 MCP tools, 18 CLI subcommands, 304 tests. Adds a Codex CLI adapter (
install-codexwires world-model-mcp into~/.codex/config.tomlwith PreToolUse / PostCompact / PostToolUse / SessionStart hooks). v0.7.4 added an AGENTS.md constraint reader, a self-hosted Claude Managed Agents deployment guide, and a reproducible contradiction-resolution benchmark (93.5% overall). v0.7.3 added a guided demo, opt-in telemetry, and a pi-package adapter. v0.7.0 introduced PostCompact auto-injection, thedeferenforcement tier, confidence-weighted contradiction resolution, and a compaction audit log. v0.7.2 added streamable HTTP transport for remote / MCP-tunnel deployment. Contributions welcome.
mcp-name: io.github.SaravananJaichandar/world-model-mcp
If world-model-mcp helped you, star the repo or open an issue with what worked or didn't. I read every one and the feedback shapes what ships next.
World Model MCP creates a temporal knowledge graph of your codebase that learns from every coding session to:
Think of it as a long-term memory layer that runs alongside Claude Code, Cursor, or any MCP-aware coding agent.
install-codex CLI subcommand appends a [mcp_servers.world_model] block plus PreToolUse, PostToolUse, PostCompact, and SessionStart hooks to ~/.codex/config.toml. The bundled snippet was verified against openai/codex@main at v0.138.0-alpha (server name uses underscore to dodge the tool-name hyphen-strip in codex-rs/codex-mcp/src/mcp/mod.rs; hook output sticks to camelCase with deny_unknown_fields compliance). Schema regression tests in tests/test_v075_features.py lock the contract down. See adapters/codex/README.md.hook_helper and inject_helper -- both helpers now accept either Claude Code's payload shape (event, project_dir) or Codex's (hook_event_name, cwd), so the same Python code drives all four adapters (Claude Code, Cursor, pi, Codex).url field for HTTP MCP servers landed June 3, hook JSON event-name casing remains undocumented). Targeting June 25 for that adapter after the API stabilizes. Detailed reasoning in the v0.7.5 RELEASE_NOTES entry..agents/skills/ constraint reader -- world-model-mcp now reads declarative project conventions from AGENTS.md, CLAUDE.md, GEMINI.md, and .agents/skills/*.md files and mixes them into PreToolUse enforcement alongside the SQLite-backed constraints. Supports structured fence blocks (```constraint and YAML frontmatter) and heuristic imperative-sentence extraction for prose-style AGENTS.md files. New MCP tool: get_agents_md_constraints. (anthropics/claude-code#6235 has 4,000+ thumbs-up for AGENTS.md as the cross-agent format.)docs/deployment/managed-agents-self-hosted.md, with a Modal quickstart you can deploy in under five minutes.benchmarks/contradictions/dataset.jsonl, runner at benchmarks/contradictions/run.py, results at benchmarks/contradictions/RESULTS.md. Headline: 93.5% overall accuracy, 100% on keep_higher_confidence and keep_most_sources, with documented honest weaknesses on tie-handling and small confidence gaps. Re-run with python benchmarks/contradictions/run.py. CI workflow guards regressions.world-model demo -- one command to see every primitive working. Initializes the knowledge graph, seeds reproducible demo data via scripts/demo_seed.py, then exercises each primitive (PreToolUse enforcement, contradiction detection, PostCompact injection, audit log) with real outputs. New users can see the value without writing any code.world-model setup, inspectable with world-model telemetry --status, disabled with world-model telemetry --disable. No file paths, no code, no identifiers tied to a person. See Privacy and Security for the exact payload.adapters/pi/ package. world-model-mcp now plugs into earendil-works/pi via pi's extension API (tool_call -> PreToolUse, context -> auto-injection, session_compact -> audit log). Install with world-model install-pi.defer enforcement tier -- PreToolUse now classifies recurring warning-level violations as defer, which pauses headless agents (with graceful fallback to ask on older clients) instead of either hard-denying or silently passing through.resolve_contradiction tool picks a winner using keep_higher_confidence, keep_most_recent, keep_most_sources, or auto. The loser is marked superseded.audit-compactions CLI or export to JSONL.adapters/cursor/. Same Python helpers, different manifest format.WORLD_MODEL_TRANSPORT=http so the same 25 MCP tools work behind an MCP tunnel for Claude Managed Agents with self-hosted sandboxes. See docs/deployment/mcp-tunnel.md.Download the latest .mcpb from Releases and drag it into Claude Desktop. Auto-installs hooks, MCP server config, and dependencies.
# 1. Install the package
pip install world-model-mcp
# 2. Setup in your project (auto-seeds the knowledge graph from existing code)
cd /path/to/your/project
python -m world_model_server.cli setup
# 3. Restart Claude Code
# Done! The world model is pre-populated and active
You can also re-seed or seed manually at any time:
# Seed from existing codebase
world-model seed
# Re-seed with force (re-processes already seeded files)
world-model seed --force
For Claude Managed Agents with self-hosted sandboxes, or any deployment where the MCP server lives behind a firewall and the agent reaches it from Anthropic-side infrastructure, run world-model-mcp in HTTP mode.
pip install 'world-model-mcp[http]'
export WORLD_MODEL_TRANSPORT=http
export WORLD_MODEL_HTTP_PORT=8765
python -m world_model_server.server
Or use the bundled image:
docker compose up -d # Dockerfile.http + persistent volume
curl http://127.0.0.1:8765/healthz # {"status":"ok","version":"0.7.2"}
Full walkthrough including Anthropic MCP tunnels setup: docs/deployment/mcp-tunnel.md.
Stdio remains the default transport for Claude Code, Cursor, and .mcpb
installs. Nothing changes for those flows.
To see every primitive working with real outputs from a real SQLite database before committing to a full install:
pip install world-model-mcp
cd /tmp/wm-test && mkdir -p wm-test && cd wm-test
world-model demo
The demo initializes a knowledge graph, seeds reproducible data, and exercises PreToolUse enforcement, contradiction detection, the PostCompact injection bundle, and the compaction audit log -- with the actual JSON outputs. Re-runs are idempotent.
For users of earendil-works/pi:
pip install world-model-mcp # the Python helpers
world-model install-pi # writes adapters/world-model-pi/
pi install local:./adapters/world-model-pi
The pi adapter wires the same hook_helper and inject_helper you'd use from Claude Code into pi's tool_call, context, and session_compact events. See adapters/pi/README.md.
For users of OpenAI's Codex CLI:
pip install world-model-mcp # the Python helpers
python -m world_model_server.cli install-codex
# (appends [mcp_servers.world_model] + hook blocks to ~/.codex/config.toml)
# Restart codex; verify with: codex mcp list
--dry-run prints what would be appended without writing; --force re-appends even if the adapter marker is already present. The bundled snippet uses world_model (underscore) as the MCP server name to dodge Codex's silent hyphen-strip in its tool-name sanitizer. Hook output is camelCase with deny_unknown_fields compliance against Codex's strict Rust schema; the contract is locked down by tests in tests/test_v075_features.py. See adapters/codex/README.md.
your-project/
├── .mcp.json # MCP server configuration
├── .claude/
│ ├── settings.json # Hook configuration
│ ├── hooks/ # Compiled TypeScript hooks
│ └── world-model/ # SQLite databases (~155 KB)
Before:
// Claude invents an API that doesn't exist
const user = await User.findByEmail(email); // This method doesn't exist
After:
// Claude checks the world model first
const user = await User.findOne({ email }); // Verified to exist
Goal: Reduce non-existent API references by validating against the knowledge graph
Session 1: User corrects Claude
// Claude writes:
console.log('debug info');
// User corrects to:
logger.debug('debug info');
// World model learns: "Use logger.debug() not console.log()"
Session 2: Claude uses the learned pattern
// Claude automatically writes:
logger.debug('debug info'); // No correction needed
Goal: Learned patterns persist across sessions and prevent repeat violations
// Week 1: Bug fixed (null check added)
if (user && user.email) { ... }
// Week 2: Refactoring
// World model warns: "This line preserves a critical bug fix"
// Claude preserves the null check
// Result: Bug not re-introduced
Goal: Detect potential regressions before code execution
┌──────────────────────────────────────────────────────────┐
│ Claude Code + Hooks │
│ Captures: file edits, tool calls, user corrections │
└──────────────────────────────────────────────────────────┘
|
v
┌──────────────────────────────────────────────────────────┐
│ MCP Server (Python) │
│ - 22 MCP tools for querying/recording/predicting │
│ - LLM-powered entity extraction (Claude Haiku) │
│ - External linter integration (ESLint, Pylint, Ruff) │
└──────────────────────────────────────────────────────────┘
|
v
┌──────────────────────────────────────────────────────────┐
│ Knowledge Graph (SQLite + FTS5) │
│ - entities.db: APIs, functions, classes │
│ - facts.db: Temporal assertions with evidence │
│ - relationships.db: Entity dependency graph │
│ - constraints.db: Learned rules from corrections │
│ - sessions.db: Session history and outcomes │
│ - events.db: Activity log with reasoning chains │
└──────────────────────────────────────────────────────────┘
Temporal Facts: Every fact has validAt and invalidAt timestamps
Evidence Chains: Every assertion traces back to source
Constraint Learning: Pattern recognition from user corrections
Dual Validation: Combines two validation sources
Twenty-two MCP tools available to Claude Code:
query_factCheck if APIs/functions exist before using them
result = query_fact(
query="Does User.findByEmail exist?",
entity_type="function"
)
# Returns: {exists: bool, confidence: float, facts: [...]}
record_eventCapture development activity with reasoning chains
record_event(
event_type="file_edit",
file_path="src/api/auth.ts",
reasoning="Added JWT authentication middleware"
)
validate_changePre-execution validation against constraints and linters
result = validate_change(
file_path="src/api/auth.ts",
proposed_content="..."
)
# Returns: {safe: bool, violations: [...], suggestions: [...]}
get_constraintsRetrieve project-specific rules for a file
constraints = get_constraints(
file_path="src/**/*.ts",
constraint_types=["linting", "architecture"]
)
record_correctionLearn from user edits (HIGH PRIORITY)
record_correction(
claude_action={...},
user_correction={...},
reasoning="Use logger.debug instead of console.log"
)
get_related_bugsRegression risk assessment
result = get_related_bugs(
file_path="src/api/auth.ts",
change_description="refactoring authentication logic"
)
# Returns: {bugs: [...], risk_score: float, critical_regions: [...]}
seed_projectScan the codebase and populate the knowledge graph with entities and relationships
result = seed_project(
project_dir=".",
force=False
)
# Returns: {files_seeded: int, entities_created: int, relationships_created: int}
ingest_pr_reviewsPull GitHub PR review comments and convert team feedback into constraints
result = ingest_pr_reviews(
repo="owner/repo", # Auto-detected from git remote if omitted
count=10
)
# Returns: {prs_scanned: int, constraints_created: int, constraints_updated: int}
# Run tests
pytest
# With coverage
pytest --cov=world_model_server --cov-report=html
186 tests covering knowledge graph CRUD, FTS5 search, constraint management, bug tracking, auto-seeding, PR review ingestion, decision traces, outcome linkage, trajectory learning, prediction layer, memory health, contradiction detection, transcript pointers, project identity, and PreToolUse enforcement. See tests/ for details.
# Database location (default: ./.claude/world-model/)
export WORLD_MODEL_DB_PATH="/custom/path"
# Anthropic API key (optional - enables LLM extraction)
# IMPORTANT: Never commit this! Use .env file (see .env.example)
export ANTHROPIC_API_KEY="your-api-key-here"
# Model selection
export WORLD_MODEL_EXTRACTION_MODEL="claude-3-haiku-20240307" # Fast
export WORLD_MODEL_REASONING_MODEL="claude-3-5-sonnet-20241022" # Accurate
# Debug mode
export WORLD_MODEL_DEBUG=1
Note: Create a .env file in your project root (see .env.example) - it's automatically ignored by git.
Edit .claude/settings.json to customize which tools trigger world model hooks:
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write|Bash",
"hooks": [...]
}]
}
}
Currently Supported:
Coming Soon:
Extensible Architecture: Easy to add new language parsers (see CONTRIBUTING.md)
v0.7.3 added anonymous usage telemetry. It is:
world-model setup, with a clear y/N prompt.world-model telemetry --status shows the exact JSON payload that would be sent.world-model telemetry --disable, or globally with WORLD_MODEL_TELEMETRY_DISABLE=1.What we send (only if you opt in):
| Field | Example | Why |
|---|---|---|
event | setup_completed, demo_run, hook_fired | Which lifecycle step ran |
version | 0.7.3 | Which release you're on |
install_id | random UUID at ~/.world-model/install_id | Distinguish installs without identifying users |
ts | unix timestamp | When the event fired |
What we never send: file paths, file contents, rule names, hostnames, IP addresses, API keys, decision-trace text, fact text, or anything else that could identify a person or leak business logic. The full payload schema lives in world_model_server/telemetry.py.
Where it goes: opt-in events are posted to a dedicated private GitHub repo (SaravananJaichandar/world-model-telemetry) as plain issues. There is no third-party analytics service, no cookie, no fingerprint. The PAT embedded in the client is scoped to that one repo with Issues: write only.
ANTHROPIC_API_KEY).env files.env.example as template.env files only.gitignore automatically excludes sensitive filesdefer enforcement tier in PreToolUse: pause headless agents on recurring warning-level violations, with graceful fallback to askauto strategyworld-model demo guided tour for first-time usersadapters/pi/, install-pi CLI).agents/skills/ constraint reader (new MCP tool: get_agents_md_constraints)_meta headers, InputRequiredResult)/world-model slash command + TUI status widget (replaces standalone dashboard)Contributions are welcome. See CONTRIBUTING.md for:
Areas where help is needed:
Project Size:
Storage Efficiency:
MIT License - Free for commercial and personal use
Run Claude Code as an MCP server so any agent can delegate coding tasks to it
Browser automation using accessibility snapshots instead of screenshots
Secure MCP server for MySQL database interaction, queries, and schema management
English-first Korean equity intelligence MCP — DART filings, foreign-holder 5%-rule flows, activist filings, KRX news. F