cerebro
Cérebro 2.0
用于 OpenCode 的上下文优化服务器。通过 LLMLingua-2 压缩 LLM 提示词,注入任务协议,并提供 2nd Brain 知识图谱。
架构
┌─────────────────────────────────────────────────┐
│ OpenCode │
│ ┌──────────────┐ ┌──────────────────────────┐ │
│ │ Plugin │ │ MCP Client │ │
│ │ (hooks) │ │ (tools) │ │
│ └──────┬───────┘ └────────────┬─────────────┘ │
│ │ │ │
└─────────┼───────────────────────┼────────────────┘
│ │
┌─────▼─────┐ ┌──────▼──────┐
│ Compressor │ │ MCP Server │
│ LLMLingua-2│ │ + HTTP API │
└─────┬─────┘ └──────┬──────┘
│ │
┌─────▼───────────────────────▼──────┐
│ @cerebro/core │
│ compressor · task-injector · brain │
└────────────────────────────────────┘包
Package | 说明 |
| 压缩引擎、任务注入器、大脑引擎、指标 |
| MCP stdio 服务器 + HTTP API(供仪表盘使用) |
| OpenCode 插件(消息压缩 + 任务注入) |
| 基于 Vite + React + Tailwind 的仪表盘 UI |
Related MCP server: repocontext
快速开始
# 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配置
环境变量(在 opencode.json 的 environment 中设置):
变量 | 默认值 | 说明 |
|
| 压缩率(0.05–1.0,值越小压缩越多) |
|
| 2nd Brain 知识库的路径 |
|
| 仪表板的 HTTP API 端口 |
|
| 是否启用任务协议注入 |
|
| 以逗号分隔的受保护块模式 |
OpenCode 集成
在项目根目录的 opencode.json 中添加以下内容:
{
"$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 工具
compress_prompt
使用 LLMLingua-2 ONNX 压缩文本。
{ "text": "Your long prompt...", "rate": 0.4 }brain_resolve
查询 2nd Brain 中某个 screen 及其 wiki 链接依赖项。
{ "screen": "dashboard-vendas", "depth": 1 }brain_index
在知识图谱中索引或更新某个 screen。
{
"id": "dashboard-vendas",
"content": "---\ntitle: Dashboard Vendas\n---\n\n# Dashboard Vendas\n\nMetrics for the sales dashboard."
}brain_screens
列出所有已索引的 screen。无参数。
cerebro_metrics
获取压缩指标和 token 节省情况。无参数。
cerebro_config
获取或设置运行时配置。
{ "key": "compressionRate", "value": 0.3 }仪表板
仪表板运行在 4321 端口,提供以下功能:
指标:压缩统计、token 节省、最近事件
第二大脑:浏览已索引的 screen 及其 wiki 链接
配置:查看和编辑运行时配置
pnpm --filter @cerebro/dashboard dev
# Open http://localhost:4321插件钩子
OpenCode 插件提供三个钩子:
Hook | 说明 |
| 在发送给 LLM 之前压缩旧消息 |
| 在系统提示词中注入任务协议 + 自检 |
| 记录工具执行情况,供仪表板展示 |
开发
# Type check all packages
pnpm -r typecheck
# Run tests
pnpm test
# Watch mode
npx vitest
# Build dashboard
pnpm --filter @cerebro/dashboard buildpackages/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)使用 pnpm test 或 npxnpx vitest run 运行。
许可证
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Intelligent context infrastructure for AI teams: knowledge graph, sessions, tasks, documents.
Shared memory for coding agents. Stop re-explaining your codebase every session.
Shared memory and context across ChatGPT, Claude, Claude Code, Codex, Cursor and 20+ AI tools
Shared project context for AI agents and teams: docs, tasks, and messages that stay current.
Related MCP Servers
- AlicenseAqualityCmaintenanceProvides intelligent code context and analysis through semantic compression, AST parsing, and multi-language support. Offers 60-80% token reduction while enabling AI assistants to understand codebases through local analysis, OpenAI-enhanced insights, and GitHub repository integration.6229 npm3MIT
- AlicenseAqualityBmaintenanceNext-gen AST codebase map, token compression (70%~85% savings), and context packaging engine for AI coding agents & IDEs.43MIT
- AlicenseNot gradedqualityCmaintenanceEnables autonomous context window management, prompt caching, token optimization, and real-time observability for AI coding agents across multiple IDEs, reducing token costs and improving performance.Apache 2.0
- AlicenseBqualityBmaintenanceEnables AI coding agents and local LLMs to store and recall project memory, compact verbose logs, look up code symbols, create and rewind workspace snapshots, detect risky commands and loops, pack context optimally, and draft tokens through MCP tools.102Apache 2.0