Skip to main content
Glama

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

说明

@cerebro/core

压缩引擎、任务注入器、大脑引擎、指标

@cerebro/mcp-server

MCP stdio 服务器 + HTTP API(供仪表盘使用)

@cerebro/plugin

OpenCode 插件(消息压缩 + 任务注入)

@cerebro/dashboard

基于 Vite + React + Tailwind 的仪表盘 UI

Related MCP server: ContextStream MCP Server

快速开始

# 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.jsonenvironment 中设置):

变量

默认值

说明

COMPRESSION_RATE

0.4

压缩率(0.05–1.0,值越小压缩越多)

BRAIN_PATH

.context-brain

2nd Brain 知识库的路径

DASHBOARD_PORT

4321

仪表板的 HTTP API 端口

ENABLE_TASK_INJECTION

true

是否启用任务协议注入

PROTECTED_PATTERNS

code,json,errors,system

以逗号分隔的受保护块模式

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

说明

experimental.chat.messages.transform

在发送给 LLM 之前压缩旧消息

experimental.chat.system.transform

在系统提示词中注入任务协议 + 自检

tool.execute.after

记录工具执行情况,供仪表板展示

开发

# Type check all packages
pnpm -r typecheck

# Run tests
pnpm test

# Watch mode
npx vitest

# Build dashboard
pnpm --filter @cerebro/dashboard build
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)

使用 pnpm testnpxnpx vitest run 运行。

许可证

MIT

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Provides 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.
    6
    12
    3
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Provides persistent memory and a codebase knowledge graph for AI coding assistants, enabling shared context across multiple tools like Claude, Cursor, and ChatGPT, with significant token reduction.
    5
    32
    MIT

View all related MCP servers

Related MCP Connectors

  • The project brain for AI coding agents — memory, decisions, sprints, knowledge base via MCP.

  • Persistent memory and knowledge graphs for AI agents. Hybrid search, context checkpoints, and more.

  • Universal memory for AI agents and tools. Save, organize and search context anywhere.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Wendell-A/cerebro2.0-lowvram'

If you have feedback or need assistance with the MCP directory API, please join our Discord server