Skip to main content
Glama

opus-advisor-mcp

一个 MCP 服务器,允许 Claude Code 在任务中途咨询 Opus 作为战略顾问。在 Sonnet 或 Haiku 上运行会话,并按需将复杂决策升级给 Opus——使用您现有的 Claude Code 订阅。

灵感来自 Anthropic 的顾问策略。

工作原理

┌─────────────────────────────────────────────┐
│  Claude Code (Sonnet)                       │
│                                             │
│  "I need to decide on the DB schema..."     │
│        │                                    │
│        ▼                                    │
│  calls consult_opus MCP tool                │
│        │                                    │
└────────┼────────────────────────────────────┘
         │
         ▼
┌─────────────────────────────────────────────┐
│  opus-advisor MCP server                    │
│                                             │
│  1. Reads prior consultation history        │
│  2. Reads requested files from disk         │
│  3. Pipes prompt to: claude -p --model opus │
│  4. Logs advice to advisor-log.md           │
│  5. Returns advice to Sonnet                │
└─────────────────────────────────────────────┘

无需 API 密钥。该服务器通过调用 claude CLI 来运行,该 CLI 使用您现有的身份验证。

Related MCP server: codex-bridge

安装

npm install -g opus-advisor-mcp

或者克隆并在本地构建:

git clone https://github.com/Divinci-AI/opus-advisor-mcp.git
cd opus-advisor-mcp
npm install
npm run build

配置

添加到您项目的 .mcp.json 或 ~/.claude/.mcp.json 中:

{
  "mcpServers": {
    "opus-advisor": {
      "command": "opus-advisor",
      "timeout": 180000
    }
  }
}

如果是在本地安装(而非全局安装):

{
  "mcpServers": {
    "opus-advisor": {
      "command": "node",
      "args": ["/path/to/opus-advisor-mcp/dist/index.js"],
      "timeout": 180000
    }
  }
}

添加配置后重启 Claude Code。

工具

consult_opus

咨询 Opus 以获取战略建议。

参数

类型

默认值

描述

question

string

必填

您需要咨询的问题或难题

context

string

可选

额外的上下文、约束或背景

files

string[]

可选

作为代码上下文包含的文件路径(相对于项目根目录)

effort

"low"

"medium"

"high"

"medium"

Opus 的推理努力程度

include_history

boolean

true

包含之前的咨询历史以保持连贯性

示例:

{
  "question": "Is this database migration safe under concurrent writes?",
  "files": ["src/db/migration-042.ts", "src/db/schema.ts"],
  "effort": "high"
}

read_advisor_log

读取之前调用的咨询日志。

参数

类型

描述

last_n

number

要返回的最近咨询次数(省略则返回全部)

read_advisor_meta

读取结构化元数据(延迟、令牌计数、努力程度)。

参数

类型

描述

last_n

number

要返回的最近条目数(省略则返回全部)

clear_advisor_log

清除咨询日志和元数据以重新开始。

功能

  • 无需 API 密钥 — 通过 claude CLI 使用您现有的 Claude Code 订阅

  • 按项目记录日志 — 咨询历史存储在每个项目的 ~/.opus-advisor/<project>-<hash>/ 中

  • 代码感知上下文 — 直接传递文件路径;服务器会读取并将其作为标记的代码块注入

  • 咨询连贯性 — 之前的建议会作为上下文反馈,以便 Opus 可以在之前的决策基础上进行构建

  • 令牌感知历史 — 历史记录受条目数 (5) 和令牌预算 (~6K 令牌) 的双重限制

  • 元数据跟踪 — 在 advisor-meta.jsonl 中跟踪延迟、令牌估算和努力程度

  • 信号保护 — 被终止进程的部分输出会被丢弃,不会作为建议返回

  • 路径遍历防护 — 文件读取经过验证,确保在项目根目录内

安全性

  • 路径遍历保护:files 参数验证所有解析后的路径是否保留在项目根目录内。像 ../../etc/passwd 或项目外的绝对路径将被拒绝。

  • 二进制文件过滤:常见的二进制扩展名(图像、可执行文件、存档等)会自动跳过。

  • 无 Shell 执行:服务器使用带有数组参数的 spawn 并通过 stdin 管道传输提示词。不会发生 Shell 插值。

  • 仅限本地:MCP 服务器通过 stdio 在本地运行。不会打开任何网络端口。

  • 咨询日志:以纯文本形式存储在 ~/.opus-advisor/ 中。这些文件可能包含您咨询中的代码片段和问题。如果这些文件包含敏感代码,请勿提交或共享它们。

环境变量

变量

描述

ADVISOR_LOG_DIR

覆盖日志目录(默认:~/.opus-advisor/<project>-<hash>/)

与 Anthropic 顾问工具的比较

Anthropic 的 advisor_20260301 是一项服务器端 API 功能,顾问可以在单个 API 请求中查看完整的对话记录。此 MCP 服务器采用不同的方法:

Anthropic 顾问工具

opus-advisor-mcp

上下文共享

完整记录(服务器端)

问题 + 文件 + 历史记录(客户端)

身份验证

需要 API 密钥

使用现有的 Claude Code 订阅

集成

API 级别 (tools 数组)

MCP 工具(目前可在 Claude Code 中使用)

持久性

无

Markdown 日志 + JSONL 元数据

成本

按 Opus 费率的令牌计费

包含在订阅中

要求

许可证

MIT

Available Tools

4 tools
clear_advisor_logClear Advisor LogA
Destructive

Clear the consultation log and metadata to start fresh for this project.

Inputs: no named parameters.

consult_opusConsult Opus AdvisorA
Read-only

Consult Claude Opus 4.7 for strategic advice. Opus runs via the Claude Code CLI with your existing subscription — no API key needed. The advisor maintains a per-project consultation log for continuity across calls. History is capped by both entry count (5) and token budget (~6K tokens) to prevent context bloat. Use this for architecture decisions, complex debugging, code review, or any problem that benefits from deeper reasoning.

Inputs: question (required), context, effort, files, +1 more.

read_advisor_logRead Advisor LogA
Read-only

Read the consultation log from prior Opus advisor calls for this project. Useful for reviewing past advice or getting context on decisions already made.

Inputs: last_n.

read_advisor_metaRead Advisor MetadataA
Read-only

Read structured metadata (latency, token counts, effort levels) from all consultations. Useful for understanding cost and performance patterns.

Inputs: last_n.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.3/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool has a uniquely defined purpose: clearing the log, consulting Opus, reading the log, and reading metadata. No two tools overlap in functionality, so an agent can easily distinguish them.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern using snake_case (e.g., consult_opus, read_advisor_log). The naming convention is uniform across the entire set.

    Tool Count5/5

    Four tools is a well-scoped count for an advisor MCP server. Each tool addresses a distinct need (consultation, log management, metadata access) without unnecessary extras.

    Completeness4/5

    The tool set covers the core operations: consultation, log reading/clearing, and metadata inspection. A minor gap is the lack of a configuration tool to adjust Opus parameters, but the current surface is sufficient for most workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers