cerebro
Enables context optimization for LLM-powered coding assistants by compressing prompts, injecting task protocols, and providing a 2nd Brain knowledge graph with tools for prompt compression, knowledge retrieval, metrics, and runtime configuration.
README
Cérebro 2.0
Context optimization server for OpenCode. Compresses LLM prompts via LLMLingua-2, injects task protocols, and provides a 2nd Brain knowledge graph.
Architecture
┌─────────────────────────────────────────────────┐
│ OpenCode │
│ ┌──────────────┐ ┌──────────────────────────┐ │
│ │ Plugin │ │ MCP Client │ │
│ │ (hooks) │ │ (tools) │ │
│ └──────┬───────┘ └────────────┬─────────────┘ │
│ │ │ │
└─────────┼───────────────────────┼────────────────┘
│ │
┌─────▼─────┐ ┌──────▼──────┐
│ Compressor │ │ MCP Server │
│ LLMLingua-2│ │ + HTTP API │
└─────┬─────┘ └──────┬──────┘
│ │
┌─────▼───────────────────────▼──────┐
│ @cerebro/core │
│ compressor · task-injector · brain │
└────────────────────────────────────┘
Packages
| Package | Description |
|---|---|
@cerebro/core |
Compression engine, task injector, brain engine, metrics |
@cerebro/mcp-server |
MCP stdio server + HTTP API for dashboard |
@cerebro/plugin |
OpenCode plugin (message compression + task injection) |
@cerebro/dashboard |
Vite + React + Tailwind dashboard UI |
Quick Start
# Install dependencies
pnpm install
# Approve native builds (onnxruntime-node)
pnpm approve-builds
# Run tests
pnpm test
# Build all packages
pnpm -r build
# Start MCP server (stdio for OpenCode)
node packages/mcp-server/dist/index.js
# Start dashboard dev server
pnpm --filter @cerebro/dashboard dev
Configuration
Environment variables (set in opencode.json under environment):
| Variable | Default | Description |
|---|---|---|
COMPRESSION_RATE |
0.4 |
Compression rate (0.05–1.0, lower = more compression) |
BRAIN_PATH |
.context-brain |
Path to 2nd Brain knowledge base |
DASHBOARD_PORT |
4321 |
HTTP API port for dashboard |
ENABLE_TASK_INJECTION |
true |
Enable task protocol injection |
PROTECTED_PATTERNS |
code,json,errors,system |
Comma-separated protected block patterns |
OpenCode Integration
Add to opencode.json in your project root:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"cerebro": {
"type": "local",
"command": ["node", "caminho/para/cerebro/packages/mcp-server/dist/index.js"],
"environment": {
"COMPRESSION_RATE": "0.4",
"BRAIN_PATH": ".context-brain",
"DASHBOARD_PORT": "4321",
"ENABLE_TASK_INJECTION": "true"
},
"enabled": true
}
}
}
MCP Tools
compress_prompt
Compress text using LLMLingua-2 ONNX.
{ "text": "Your long prompt...", "rate": 0.4 }
brain_resolve
Query the 2nd Brain for a screen and its wiki-linked dependencies.
{ "screen": "dashboard-vendas", "depth": 1 }
brain_index
Index or update a screen in the knowledge graph.
{
"id": "dashboard-vendas",
"content": "---\ntitle: Dashboard Vendas\n---\n\n# Dashboard Vendas\n\nMetrics for the sales dashboard."
}
brain_screens
List all indexed screens. No parameters.
cerebro_metrics
Get compression metrics and token savings. No parameters.
cerebro_config
Get or set runtime configuration.
{ "key": "compressionRate", "value": 0.3 }
Dashboard
The dashboard runs on port 4321 and provides:
- Métricas: Compression stats, token savings, recent events
- 2º Cérebro: Browse indexed screens and their wiki-links
- Config: View and edit runtime configuration
pnpm --filter @cerebro/dashboard dev
# Open http://localhost:4321
Plugin Hooks
The OpenCode plugin provides three hooks:
| Hook | Description |
|---|---|
experimental.chat.messages.transform |
Compresses old messages before sending to LLM |
experimental.chat.system.transform |
Injects task protocol + self-check into system prompt |
tool.execute.after |
Logs tool execution for dashboard visibility |
Development
# Type check all packages
pnpm -r typecheck
# Run tests
pnpm test
# Watch mode
npx vitest
# Build dashboard
pnpm --filter @cerebro/dashboard build
Testing
66 tests across 6 suites:
packages/core/src/ task-injector.test.ts (18) · metrics.test.ts (5)
packages/mcp-server/src/ errors.test.ts (9) · rate-limiter.test.ts (7) · e2e.test.ts (10)
packages/plugin/src/ plugin.test.ts (8)
Run with: pnpm test or npx vitest run
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.