Skip to content

[REQ-128][CODE] 编排 MCP OAuth prerequisite 与 package connection binding #703

Closed

Description

@jinjunnn

Covers

alpha-work#49 AC4/AC5:把 signed MCP OAuth prerequisite 接到现有 engine OAuth
protocol/token authority;main 拥有 package attempt/binding,renderer 不持有 token。

Solution baseline

REQ-128 accepted baseline
§2.6–§2.7。

Boundary

  • main 验 {catalogId, prerequisiteId, envelopeDigest} 并创建 opaque
    PackageConnectionAttemptV1。
  • engine packages/opencode/src/mcp/** 继续拥有 discovery/DCR/PKCE/state/callback/
    token store;main 只通过现有 authenticated local sidecar typed route发起/查询。
  • renderer 只运输 attempt ID、打开受控 browser、显示状态。
  • 现有 0600 + flock token store 是本票接受边界;不切 safeStorage/engine generation。

Development plan

  1. 定义 attempt/service identity/connection binding 状态与 reason codes。
  2. 接 signed prerequisite → main attempt → typed engine authenticate/status/cancel route。
  3. required OAuth ready 前 installer 调用数为零;optional 未连接可安装但 runtime unavailable。
  4. OAuth 已 consent 后本地安装失败:保留可复用 connection,诚实展示;撤销为独立动作。
  5. 并发/stale attempt、callback mixup 与 token-server binding fail closed。

Acceptance and named gates

  • package-mcp-oauth.wiring.test.ts 覆盖 discovery、PKCE、state、callback、cancel、
    stale/concurrent attempt、service/envelope binding。
  • 生产 test 证明 main 调 authenticated engine route,renderer 不能构造自由 OAuth 请求。
  • install failure retains connection;package uninstall 不自动 revoke shared connection。

Dependencies

Blocked by alpha-code#694。

Out of scope

新 OAuth stack、Alpha account OAuth、token storage migration、provider-specific handler。

Exit condition

Merged PR + security review + named production wiring tests + canonical docs impact handled。

Activity

  1. self-assigned this
    on Jul 30, 2026
  2. added
    type:featureNew user or system capability
    prio:P1High-value near-term delivery
    area:securitySecurity or access control
    cross-repoRequires coordinated work in multiple repositories
    on Jul 30, 2026
  3. added a commit that references this issue on Jul 30, 2026
  4. jinjunnn commented on Aug 1, 2026

    @jinjunnn
    OwnerAuthor

    ⚠️ 2026-07-31 重写:原方案的三条前提被实读证伪,owner 裁决改为自建授权流程

    本票原定「main 只经引擎现有 typed route 编排 OAuth」。勘破证明该路走不通,且不可修。

    被证伪的三条(实读 @ 59211fe8)

    1. 引擎要求「服务已装好」才肯开始授权。 packages/opencode/src/mcp/index.ts:800-804
      requireMcpConfig(name) —— 不在 config 里直接 404。⇒ 票面「required OAuth ready 前
      installer 调用数为零」顺序上不可能。
    2. POST /mcp/:name/auth(authStart)单独用是死路。 waitForCallback 全仓唯一调用点是
      index.ts:898,在 authenticate 内部;startAuth 只 ensureRunning 服务器、不注册 pending。
      ⇒ main 自己开浏览器后回调打到 127.0.0.1:19876,oauth-callback.ts:86-91 判
      !pendingAuths.has(state) → 400 CSRF,finishAuth 永远拿不到 code。
    3. finishAuth 有隐藏副作用:把该 MCP 连上并 enabled:true(index.ts:941
      createAndStore(mcpName, {...mcpConfig, enabled:true}))。「拿到令牌」与「激活服务」不可分离。

    附带事实:走 authenticate 意味着引擎自己开系统浏览器(browser.ts:14,不是 renderer 开)
    且 HTTP 请求挂最多 5 分钟(oauth-callback.ts:24 CALLBACK_TIMEOUT_MS)。
    另外票面 AC「renderer 不能构造自由 OAuth 请求」今天就已经是假的:
    preload/types.ts:70-74 把 {url,username,password} 暴露给 renderer,
    renderer/extensions/use-extensions.ts:155-159 已在自建 Basic 头调 /mcp/:name/connect。

    为什么不能改引擎

    .github/workflows/alpha-ci.yml:44 的 UPSTREAM_PATHS 含 packages/opencode;
    :167 的守卫是 git diff --diff-filter=DMR。新增文件不红,但任何新 route 都必须修改
    groups/mcp.ts + handlers/mcp.ts(M)⇒ 结构性禁止
    。
    :119-166 的 exclude 白名单里没有任何 MCP 条目 —— MCP 协议客户端从未被正式收编。

    owner 裁决(2026-07-31)

    自建一套授权流程,不用引擎的。本票移出 Phase 2,另行排期。

    这是一次真正的主权收敛:alpha 今天只拥有 MCP 的管理面
    (alpha-mcp-secrets.ts / ext-mcp-policy.ts / mcp-default-deny.ts / ext-mcp-activation.ts),
    协议面(连接、OAuth 握手、令牌存储)仍在引擎。本票把协议面的授权部分收回 main。

    重写后的方向(待方案基线,不是可直接开工的计划)

    • main 自持 discovery / DCR / PKCE / state / callback / token store,不复用
      ~/.local/share/opencode/mcp-auth.json
      ;
    • callback 走 alpha 已有的 deep link 通道(shared/route-manifest.ts:568 形态),
      不占 127.0.0.1:19876(该端口 oauth-callback.ts:116-119 被占时静默不启动,是 fail-open);
    • 浏览器由 main 打开,renderer 只运输 attemptId;
    • 顺序恢复为「先授权、后安装」,required 前置在 admission 之前满足;
    • 需要独立的方案基线与安全审计(新 OAuth stack 属高风险面)。

    开工前必须先做

    写方案基线并过跨模型对抗审计。不得在没有基线的情况下直接实现 OAuth stack。

    相关

    • 顺带发现(已另票):mcp-auth.json 不在「清除数据」清单里。
    • alpha-code#704(Alpha Connection)不受影响,仍在 Phase 2 —— 那是 alpha 自己的机制。
  5. added a commit that references this issue on Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:securitySecurity or access controlcross-repoRequires coordinated work in multiple repositoriesprio:P1High-value near-term deliverytype:featureNew user or system capability

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions