Cortex Intelligent
# mcp-cortex-intelligent — Cortex Intelligent
<p align="center">
<img src="assets/logo.svg" alt="mcp-cortex-intelligent logo" width="120"/>
</p>
[](https://www.npmjs.com/package/mcp-cortex-intelligent)
[](LICENSE)
[](https://nodejs.org)
Make ordinary LLMs smarter — offline, no API keys, no external services.
MCP server that augments an ordinary LLM with context, procedures, memory, exemplars, verification, and an internal decision engine. Standard MCP (stdio), compatible with OpenCode, Claude Desktop, Cursor, VS Code, and any MCP client.
## Architecture
```mermaid
flowchart TB
Client["MCP Client (OpenCode)"] -->|stdio| Server["Cortex MCP Server (offline)"]
Server --> Provisioner["Provisioner<br/>agent and skill, marker-block"]
Server --> ModelGuard["Model Guard<br/>resolver, guardrails, decision"]
Server --> CogAug["Cognitive Augmentor<br/>exemplar, self-critique, compliance, verifier"]
Server --> KB["Knowledge Base<br/>hybrid search plus memory"]
Server --> Decision["Internal Decision Engine<br/>heuristics"]
Server --> SQLite[("SQLite + FTS5")]
Server --> Verifier["Verification Runner<br/>allowlist, sandbox"]
```
## Features
- **Auto-Provision Agent & Skill** — idempotent marker-block append, never overwrites user content, backup before write.
- **Model Awareness + Guardrails** — detects model tier (weak/medium/strong), injects anti-blunder procedures.
- **Offline Cognitive Augmentor** — exemplar retrieval, structured self-critique, compliance scoring, verification runner.
- **Internal Decision Engine** — fast deterministic decisions (tier/risk/route/compliance) via heuristics. No LLM.
- **Plan & Task Management** — AI Agent → SKILL.md → AGENTS.md → PLAN.md ↔ CORTEX_EXECUTE ↔ TASK.md ↔ CORTEX_VERIFY → DONE. Persistent task tracking.
- **Knowledge Base + Memory** — hybrid search (BM25 + vector + RRF), long-term memory with decay.
## Installation
### Requirements
- Node.js >= 22.12 (for node:sqlite)
- npm
### From source
```bash
git clone https://github.com/adyoi/mcp-cortex-intelligent.git
cd mcp-cortex-intelligent
npm install
npm run build
npm start
```
### From npm (after publish)
```bash
npx mcp-cortex-intelligent
```
## Configuration
Copy `.env.example` to `.env` and edit. Environment variables always win over the file.
| Variable | Default | Purpose |
|---|---|---|
| CORTEX_DB_DIR | .cortex-data | SQLite store location |
| CORTEX_MODEL | (auto) | Override model |
| CORTEX_TIER_OVERRIDE | (auto) | Override tier |
| CORTEX_VERIFY_ALLOWLIST | npm test,npm run lint,npm run typecheck | Verification commands |
| CORTEX_VERIFY_TIMEOUT_MS | 300000 | Verification timeout |
| CORTEX_SELF_CRITIQUE_THRESHOLD | 0.8 | Revision threshold |
| CORTEX_SELF_CRITIQUE_MAX_ITERS | 3 | Max self-critique iterations |
| CORTEX_PROVISION_BACKUP | 1 | Backup before write |
| CORTEX_GUARDRAILS_STRICT | 1 | Enforce guardrails |
| EMBEDDING_PROVIDER | local | local / transformers |
| EMBEDDING_MODEL | Xenova/all-MiniLM-L6-v2 | Embedding model |
| SEARCH_MODE | hybrid | hybrid / vector / keyword |
| KB_MEMORY_HALF_LIFE_DAYS | 14 | Memory decay half-life |
### OpenCode registration
Add to `~/.config/opencode/opencode.json`:
```json
{
"mcp": {
"cortex": {
"type": "local",
"command": ["node", "~/mcp-cortex-intelligent/dist/index.js"],
"cwd": "~/mcp-cortex-intelligent",
"environment": { "CORTEX_DB_DIR": "~/mcp-cortex-intelligent/.cortex-data" }
}
}
}
```
## Tools (62)
| Group | Count | Tools |
|---|---|---|
| System | 3 | system_stats, lsp_diagnostics, cognitive_status |
| Provisioning | 4 | bootstrap_session, provision_agent_skill, list_agents_skills, update_procedure_block |
| Model | 5 | detect_model, get_model_profile, set_model, get_guardrails, model_decision |
| Knowledge | 11 | knowledge_ingest_text, knowledge_ingest_file, knowledge_ingest_dir, knowledge_search, knowledge_retrieve, knowledge_list_documents, knowledge_document_stats, knowledge_delete_document, knowledge_sync_session, knowledge_reindex, knowledge_backup |
| Memory | 9 | memory_remember, memory_recall, memory_context, memory_list, memory_get, memory_update, memory_forget, memory_consolidate, memory_stats |
| Cognitive | 3 | self_critique, score_compliance, run_verification |
| Decision | 2 | decision_classify, decision_health |
| Procedure | 5 | get_procedure, list_procedures, ingest_procedure, retrieve_exemplars, ingest_exemplar |
| Plan & Task | 17 | init_plan, read_plan, update_plan_section, init_task, init_agents, init_audit, task_create, task_list, task_get, task_start, task_done, task_block, task_delete, task_update, task_sync_md, task_summary, task_from_plan |
| Web | 3 | webfetch, webfetch_validate, browser_fetch |
## Workflow
### Bootstrap Session
1. Call `bootstrap_session(project_root)`.
2. Detect model → `model_decision` → set session state.
3. Provision agent & skill (append if exists).
4. Inject guardrails via `get_guardrails(task="session_start")`.
### Task Execution
1. `get_guardrails(task_type)` → checklist.
2. `retrieve_exemplars(task)` → best examples.
3. Plan → Read → Edit → Verify → Review.
4. `run_verification()` → real feedback.
5. `score_compliance(plan)` + `self_critique(artifact)`.
### Plan & Task Loop
```mermaid
flowchart LR
A[AI Agent] --> B[SKILL.md]
B --> C[AGENTS.md]
C --> D[memory_context]
D --> E[PLAN.md]
E --> F[get_guardrails]
F --> G[CORTEX_EXECUTE]
G <--> H[TASK.md]
H <--> I[CORTEX_VERIFY]
I -- pass --> J[DONE]
I -- fail --> G
```
### Steps
1. `init_plan` + `init_task`.
2. Agent reads PLAN.md → picks next task.
3. `task_list(status="todo")` → choose.
4. `task_start(id)` → doing.
5. Execute with guardrails + verification.
6. `task_done(id)` after verification passes.
7. `task_sync_md()` → write TASK.md.
## Security
- Secrets are never stored (no-secret rule).
- Verification runner uses allowlist, locked cwd, timeout, minimal env.
- Provisioning restricted to `.opencode/` under project root.
- Backup before overwrite; idempotent writes.
- 100% offline, no network calls.
## Development
```bash
npm install
npm run typecheck
npm run lint
npm run build
npm test
npm start
```
## Documentation
Full documentation: https://adyoi.github.io/mcp-cortex-intelligent/
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).
## License
MIT
TDQS
Scored across 62 tools
Several clusters of tools have unclear boundaries: knowledge_search vs knowledge_retrieve vs retrieve_exemplars, memory_recall vs memory_context vs memory_list, and webfetch vs browser_fetch all overlap in purpose. The four init_* tools (init_plan, init_task, init_agents, init_audit) and decision_classify vs model_decision are near-duplicates that an agent could easily misselect.
There are strong consistent namespaces (knowledge_*, memory_*, task_*), but the surface also mixes bare verb_noun names (get_model_profile, set_model, ingest_procedure, score_compliance, run_verification) with un-prefixed concepts like webfetch, self_critique, and cognitive_status. It is readable but not a single predictable convention.
At 62 tools this far exceeds a well-scoped surface for a knowledge/memory/task assistant, and many tools are redundant or niche (four init_* variants, two fetch tools, three decision/health tools). The count indicates scope creep rather than a tight, purposeful set.
The domain surface is broad and mostly covers the lifecycle: knowledge ingest/search/list/delete/reindex/backup, full memory CRUD plus consolidation, and a fairly complete task lifecycle with plan and procedure support. Minor gaps remain, such as no document edit/update operation and procedures lacking delete/update beyond block versioning, with backup restore only available offline.