Skip to content

feat(mcp): support remote dual-era negotiation - #2670

Merged
Astro-Han merged 19 commits into
apache:mainfrom
me2seeks:feat/1650-mcp-remote-dual-era-v2
Aug 19, 2026
Merged

feat(mcp): support remote dual-era negotiation#2670
Astro-Han merged 19 commits into
apache:mainfrom
me2seeks:feat/1650-mcp-remote-dual-era-v2

Conversation

@me2seeks

@me2seeks me2seeks commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add a versioned remote MCP protocol preference while preserving omitted v1 config as legacy and writing new remote entries as explicit auto.
  • Negotiate legacy or 2026-07-28 Streamable HTTP sessions, keep SSE fallback limited to typed pre-identity 404/405 failures, and expose the negotiated protocol in Desktop status.
  • Route initial discovery, manual refresh, legacy notifications, and modern subscriptions through the existing generation-owned discovery transaction and immutable Tool snapshot.
  • Apply bounded SEP-2243 Tool partitioning and call-time integer checks without creating a second callable registry or bypassing Runtime execution boundaries.

Refs #1650

Depends on #2663. This is a cross-fork follow-up, so it remains a draft against main; until #2663 lands, the PR 2-only diff is:

me2seeks/maka-agent@fix/1650-mcp-discovery-transaction...feat/1650-mcp-remote-dual-era-v2

Verification

I did not run a live public MCP endpoint or an Electron click-through smoke test.

Review focus

replaceToolSnapshot() remains the only callable publication transaction. Protocol status, subscription diagnostics, and renderer state are projections; they do not own Tool bindings or a separate revision. Every refresh signal advances the same connection-generation epoch, and publication is fenced before and after synchronous listeners.

Modern stdio and config v3 remain the next RFC slice rather than being enabled here.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

Visual evidence

The real Desktop Storybook surfaces cover both requested states. SSE fixes the protocol preference to Legacy; the installed-server inspector projects the protocol actually negotiated by the MCP manager.

Remote add/edit — SSE forces Legacy Installed server — negotiated protocol
Remote MCP editor with SSE-forced Legacy protocol preference Installed MCP server details with negotiated protocol

AI use

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Maka authored the existing dual-era MCP implementation, tests, verification, documentation, and visual evidence. OpenAI Codex authored the latest direct-map import ambiguity review remediation and its regression test.

Final squash trailers:

Generated-by: Maka
Generated-by: Codex

@me2seeks
me2seeks force-pushed the feat/1650-mcp-remote-dual-era-v2 branch 3 times, most recently from 91b3d4e to 8be1e7d Compare August 18, 2026 15:37
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

What this PR solves

This PR adds remote MCP dual-era protocol negotiation for legacy and 2026-07-28 Streamable HTTP sessions.

It preserves legacy omitted protocol settings and writes new remote entries with explicit auto preference. It limits SSE fallback to typed pre-identity 404/405 failures.

It also:

  • Exposes negotiated protocol status in Desktop.
  • Unifies discovery, refresh, notification, and subscription handling around one generation-owned immutable Tool snapshot.
  • Adds bounded SEP-2243 header validation, tool partitioning, warning formatting, and unsafe-integer validation.
  • Preserves Runtime execution boundaries and avoids a separate callable registry.
  • Migrates MCP configuration from version 1 to version 2.
  • Adds extensive coverage for negotiation, fallback, subscriptions, discovery races, configuration migration, validation, and schema isolation.

Source of truth and solution size

The PR extends existing MCP configuration, discovery, Runtime, and Desktop paths. It does not create a parallel callable or discovery authority.

The immutable Tool snapshot remains the single callable authority. Discovery uses generation-fenced refresh ownership. Desktop uses shared draft conversion helpers.

The solution is coherent with the stated requirements. The added protocol states, fallback branches, subscription lifecycle, and validation logic are necessary for dual-era interoperability and SEP-2243 enforcement.

Some test fixtures are large because they cover transport failures, cancellation, acknowledgements, reconnects, and race conditions. No clear deletion or simplification is identified without reducing regression coverage. The shared MCP_CONFIG_VERSION constant removes repeated version literals.

Validation and concrete risks

The PR reports passing MCP, Storage, Runtime, Desktop, Desktop typecheck, build, typecheck, lint, formatting, and CI checks. These results are not independently verified here.

No live public MCP endpoint or Electron click-through smoke test was run.

Key risks include:

  • Protocol negotiation and SSE fallback can change remote connection behavior.
  • Configuration migration can affect existing MCP files and import validation.
  • Subscription cancellation, reconnect, and refresh fencing have concurrency-sensitive behavior.
  • SEP-2243 partitioning can exclude tools or reject header arguments.
  • Desktop now exposes new protocol settings and negotiated status.
  • New exported MCP types and functions expand the public package surface.

Material changes in user-visible behavior, public contracts, security boundaries, releases, licensing, or governance require independent human review under repository policy.

Complexity delta

The PR adds:

  • A configuration version and remote protocol preference.
  • Negotiated protocol status.
  • Legacy, automatic, and exact modern negotiation branches.
  • SSE fallback rules.
  • Subscription and refresh lifecycle state.
  • SEP-2243 validation and partitioning APIs.
  • Desktop protocol settings and status presentation.
  • Extensive transport and concurrency test fixtures.

The PR removes or consolidates:

  • Hard-coded configuration version values.
  • Separate Desktop draft conversion logic.
  • Multiple discovery publication paths.
  • Shared output-validator caching that could mix schemas.
  • Implicit callable authority outside the immutable Tool snapshot.

Total maintenance complexity increases because the PR adds protocol eras, lifecycle states, and validation rules. The increase is justified by the compatibility, safety, and consistency requirements. The current evidence supports this conclusion, subject to review of the final diff and test results.

Review-relevant risks

The current diff has apparent effects on user-visible Desktop behavior, MCP configuration migration, public MCP types and functions, remote transport behavior, and SEP-2243 security validation.

Material changes in these areas require independent human review under repository policy.

The person performing the merge must review the final diff. A maintainer makes the final determination.

Walkthrough

MCP configuration version 2 adds remote protocol preferences and migration rules. Runtime management adds protocol negotiation, SSE fallback, subscriptions, refresh coordination, and header validation. Desktop editing, localization, fixtures, and tests now use the shared configuration model.

Changes

MCP dual-era protocol support

Layer / File(s) Summary
Configuration versioning and protocol contracts
packages/core/src/mcp.ts, packages/storage/src/mcp-config-store.ts, apps/desktop/src/renderer/mcp-import.ts, apps/desktop/src/main/__tests__/*
Configuration version 2 supports legacy and modern remote protocol preferences. Version 1 and unversioned files migrate on read or mutation. Unsupported future versions remain protected.
Remote negotiation, fallback, and discovery
packages/mcp/src/index.ts, packages/mcp/src/__tests__/manager*.test.ts, packages/mcp/src/__tests__/modern-manager.test.ts
Remote connections negotiate protocol versions, apply constrained SSE fallback, manage modern subscriptions, coalesce refreshes, preserve snapshots, and clean up abortable connection state.
Header validation and tool isolation
packages/mcp/src/sep-2243.ts, packages/mcp/src/tool-output-validation.ts, packages/runtime/src/__tests__/mcp-tools.test.ts
SEP-2243 header schemas and arguments are validated. Invalid tools produce bounded diagnostics. Output validators are isolated per tool.
Desktop protocol editing and status presentation
apps/desktop/src/renderer/mcp-page-model.ts, apps/desktop/src/renderer/mcp-page.tsx, apps/desktop/src/renderer/locales/mcp-copy.ts, apps/desktop/src/renderer/mcp-catalog.ts
Draft conversion, serialization, transport rules, protocol selection, negotiated status, catalog defaults, and localized messages use the shared protocol model.
Architecture documentation alignment
docs/architecture/mcp-runtime-architecture-draft.zh-CN.md
The architecture draft describes the implemented remote dual-era runtime, configuration migration, lifecycle rules, security boundaries, and acceptance criteria.

Estimated code review effort: 5 (Critical) | ~120 minutes

Merge Risk: 🟡 Moderate · up to 2de99

This PR adds dual-era remote MCP negotiation, fallback, subscriptions, and related import and desktop behavior. The current head still has bounded correctness and diagnostics issues that can hide invalid configuration, reject a valid imported server, expose unsanitized server text in errors, and misstate verification status, so it should not merge until these are fixed or explicitly accepted.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Ai Use Disclosure ⚠️ Warning The authored PR description selects neither AI-use declaration, and all 21 introduced commits contain zero valid Generated-by trailers. Select exactly one declaration. If generative tooling made a substantive contribution, name the tool and scope. See “Human ownership and AI attribution” in CONTRIBUTING.md; add trailers if required and preserve them through squash or amend.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: remote MCP dual-era protocol negotiation.
Description check ✅ Passed The description includes the required summary, verification, AI-use declaration, checklist, behavior change, review focus, dependency, and remaining test limitations.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@me2seeks
me2seeks marked this pull request as ready for review August 18, 2026 15:42
@me2seeks

Copy link
Copy Markdown
Contributor Author

@Astro-Han This branch is now restacked on the reviewed #2663 discovery authority and current main. MCP, Storage, Runtime, Desktop, and Desktop typecheck all pass sequentially; the dual-era snapshot remains one immutable callable authority. I have moved it out of Draft while keeping the #2663 dependency explicit. Could you review the current head when convenient?

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Support dual-era remote MCP negotiation and unified discovery

✨ Enhancement 🐞 Bug fix 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds versioned remote MCP preferences with legacy compatibility and modern negotiation.
• Unifies all discovery signals behind generation-fenced immutable snapshots.
• Enforces SEP-2243 safety and displays negotiated protocols in Desktop.
Diagram

graph TD
  UI["Desktop MCP UI"] --> Store["Config Store"] --> Manager["Client Manager"] --> Transport["Remote Transport"] --> Server["MCP Server"] --> Discovery["Tool Discovery"] --> Snapshot["Tool Snapshot"] --> Runtime["Tool Runtime"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Separate legacy and modern managers
  • ➕ Isolates era-specific transport and subscription behavior
  • ➕ Reduces conditional logic within each implementation
  • ➖ Duplicates connection, refresh, diagnostics, and snapshot ownership
  • ➖ Creates greater risk of divergent callable registries and lifecycle semantics
2. Delegate refresh ownership to the SDK
  • ➕ Requires less custom subscription and coalescing code
  • ➕ Can follow SDK protocol evolution automatically
  • ➖ Introduces a second discovery authority beside the manager snapshot
  • ➖ Weakens generation fencing and publication guarantees during races

Recommendation: Keep the PR's shared manager and generation-owned discovery transaction. Although separate era implementations could simplify individual branches, preserving one refresh owner and one immutable callable snapshot provides stronger lifecycle consistency, avoids duplicate registries, and keeps all tool execution behind the established Runtime boundary.

Files changed (25) +3689 / -319

Enhancement (6) +509 / -75
mcp-copy.tsAdd localized protocol negotiation copy +20/-6

Add localized protocol negotiation copy

• Adds Chinese and English labels, guidance, status formatting, and import errors for legacy, automatic, and pinned modern protocol preferences.

apps/desktop/src/renderer/locales/mcp-copy.ts

mcp-import.tsImport and migrate versioned MCP configurations +24/-4

Import and migrate versioned MCP configurations

• Accepts version 1 and version 2 wrappers, projects legacy imports to version 2, and requires protocol fields to originate from an explicit version 2 configuration.

apps/desktop/src/renderer/mcp-import.ts

mcp-page-model.tsExtract MCP editor and protocol presentation model +128/-0

Extract MCP editor and protocol presentation model

• Centralizes draft conversion, config serialization, transport convergence, and negotiated-protocol presentation. New remote drafts default to auto while omitted existing preferences resolve to legacy.

apps/desktop/src/renderer/mcp-page-model.ts

mcp-page.tsxExpose remote protocol preferences in Desktop +49/-64

Expose remote protocol preferences in Desktop

• Adds the remote protocol selector and negotiated protocol status, adopts config version 2, and delegates editor transformations to the extracted page model.

apps/desktop/src/renderer/mcp-page.tsx

mcp.tsDefine MCP config v2 and protocol contracts +16/-1

Define MCP config v2 and protocol contracts

• Introduces remote protocol preferences and negotiated protocol status, increments the configuration version, and preserves omitted remote preferences as legacy.

packages/core/src/mcp.ts

sep-2243.tsImplement SEP-2243 tool header safeguards +272/-0

Implement SEP-2243 tool header safeguards

• Validates statically reachable header declarations, partitions malformed tools, emits bounded sanitized warnings, and rejects unsafe integer header arguments before transport execution.

packages/mcp/src/sep-2243.ts

Bug fix (1) +5 / -3
tool-output-validation.tsIsolate output validators per advertised tool +5/-3

Isolate output validators per advertised tool

• Compiles each tool output schema with a fresh validator so reused schema IDs cannot cross tool, server, or connection-generation boundaries.

packages/mcp/src/tool-output-validation.ts

Tests (14) +2388 / -51
mcp-import.test.tsTest version 2 MCP import compatibility +39/-3

Test version 2 MCP import compatibility

• Covers migration of version 1 and unwrapped imports, preservation of version 2 protocol preferences, and rejection of misplaced or unsupported protocol versions.

apps/desktop/src/main/tests/mcp-import.test.ts

mcp-ipc-main.test.tsUpdate MCP IPC tests for config version 2 +14/-11

Update MCP IPC tests for config version 2

• Moves IPC configuration fixtures to the shared version 2 constant while retaining commit, publication, cancellation, and rollback assertions.

apps/desktop/src/main/tests/mcp-ipc-main.test.ts

mcp-page-model.test.tsTest Desktop protocol preference modeling +130/-0

Test Desktop protocol preference modeling

• Verifies new remote entries use explicit auto negotiation, legacy entries retain legacy semantics, SSE converges to legacy, and connected status presents the negotiated revision.

apps/desktop/src/main/tests/mcp-page-model.test.ts

mcp-runtime-e2e.test.tsMove runtime MCP fixture to config version 2 +2/-1

Move runtime MCP fixture to config version 2

• Updates the generation-bound MCP runtime integration test to use the current configuration version.

apps/desktop/src/main/tests/mcp-runtime-e2e.test.ts

scenarios-modules.tsSeed MCP E2E scenarios with config version 2 +2/-1

Seed MCP E2E scenarios with config version 2

• Uses the shared MCP configuration version when creating Desktop E2E fixture data.

apps/desktop/src/main/e2e-fixture/scenarios-modules.ts

module-hubs.stories.tsxUpdate MCP stories for config version 2 +10/-9

Update MCP stories for config version 2

• Migrates Storybook MCP bridge fixtures and sample configurations to the shared current version.

apps/desktop/stories/module-hubs.stories.tsx

manager-fallback.test.tsTest bounded Streamable HTTP to SSE fallback +504/-0

Test bounded Streamable HTTP to SSE fallback

• Uses real HTTP and SSE fixtures to verify fallback occurs only for typed pre-identity 404/405 failures. It also covers pinning, cancellation, timeouts, protocol evidence, and aggregated failures.

packages/mcp/src/tests/manager-fallback.test.ts

manager-subscription.test.tsTest modern tool-list subscription lifecycle +515/-0

Test modern tool-list subscription lifecycle

• Covers acknowledged and degraded subscriptions, initial-discovery races, burst coalescing, independent diagnostics, remote closure, and non-blocking cancellation teardown.

packages/mcp/src/tests/manager-subscription.test.ts

manager.test.tsExpand manager negotiation and refresh race coverage +259/-21

Expand manager negotiation and refresh race coverage

• Adds legacy negotiation status and exact-pin tests plus extensive generation, publication, retry, refresh-budget, and initial-discovery race assertions. Existing fixtures move to config version 2 and gain additional failure and notification controls.

packages/mcp/src/tests/manager.test.ts

modern-manager.test.tsAdd modern Streamable HTTP integration coverage +382/-0

Add modern Streamable HTTP integration coverage

• Tests automatic and pinned 2026-07-28 sessions, capability-aware discovery, structured results, unsupported deferred input, and SEP-2243 wire behavior against a real modern server.

packages/mcp/src/tests/modern-manager.test.ts

sep-2243.test.tsTest bounded SEP-2243 validation +264/-0

Test bounded SEP-2243 validation

• Covers static header declaration validation, per-tool partitioning, bounded redacted warnings, and call-time safe-integer enforcement.

packages/mcp/src/tests/sep-2243.test.ts

tool-output-validation.test.tsTest isolation of colliding output schema IDs +32/-0

Test isolation of colliding output schema IDs

• Verifies tools advertising the same JSON Schema ID receive independent validators and cannot reuse another tool's compiled schema.

packages/mcp/src/tests/tool-output-validation.test.ts

mcp-tools.test.tsAssert MCP tools remain outside Plan mode +16/-0

Assert MCP tools remain outside Plan mode

• Verifies untrusted read-only annotations cannot lower MCP tools from network-send classification or expose them in Plan mode.

packages/runtime/src/tests/mcp-tools.test.ts

mcp-config-store.test.tsTest config v2 migration and preservation rules +219/-5

Test config v2 migration and preservation rules

• Covers legacy read projection, mutation-driven migration, protocol and transport validation, future-version overwrite protection, malformed-file recovery, and all supported preferences.

packages/storage/src/tests/mcp-config-store.test.ts

Documentation (1) +36 / -19
mcp-runtime-architecture-draft.zh-CN.mdDocument the remote dual-era MCP architecture +36/-19

Document the remote dual-era MCP architecture

• Documents version 2 configuration semantics, negotiation and fallback rules, modern subscriptions, unified discovery ownership, SEP-2243 validation, diagnostics, and runtime boundaries.

docs/architecture/mcp-runtime-architecture-draft.zh-CN.md

Other (3) +751 / -171
mcp-catalog.tsEnable auto negotiation for remote catalog entries +3/-3

Enable auto negotiation for remote catalog entries

• Marks bundled Notion, Vercel, and Supabase remote configurations with explicit automatic protocol negotiation.

apps/desktop/src/renderer/mcp-catalog.ts

index.tsImplement dual-era negotiation and unified discovery ownership +678/-162

Implement dual-era negotiation and unified discovery ownership

• Adds protocol-aware remote connection setup, narrow SSE fallback, modern subscriptions, diagnostics, cancellation-safe teardown, and negotiated status. Initial, manual, legacy, and modern refreshes now share a generation-fenced transaction that publishes one validated immutable tool snapshot, including SEP-2243 enforcement.

packages/mcp/src/index.ts

mcp-config-store.tsPersist versioned MCP protocol preferences safely +70/-6

Persist versioned MCP protocol preferences safely

• Adds version 1 read compatibility and version 2 protocol validation while restricting protocol fields to remote servers. Full replacement now refuses to overwrite parseable future-version wrappers but can repair malformed data.

packages/storage/src/mcp-config-store.ts

@qodo-code-review

qodo-code-review Bot commented Aug 18, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Refresh gate stays occupied ✓ Resolved 🐞 Bug ≡ Correctness
Description
Fix-now: startToolRefresh() starts refreshToolLoop() before publishing its state, so the
synchronous modern/no-tools path runs its cleanup while the gate is still unset and then installs an
already-settled refresh forever. Every later manual or notification refresh joins that stale promise
instead of advancing the generation-owned discovery transaction, violating the PR’s stated refresh
invariant.
Code

packages/mcp/src/index.ts[387]

+    state.promise = this.refreshToolLoop(serverId, entry, state);
Relevance

●●● Strong

Synchronous cleanup race is a concrete correctness bug; closely related MCP refresh invariants and
integration fixes were accepted.

PR-#1661
PR-#2989

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The gate is assigned only after the async loop is invoked, while cleanup clears it only if that
assignment is already visible. For modern servers lacking the tools capability, discovery selects
[] without awaiting, so cleanup runs synchronously and misses the gate; the matching-state fast
path then reuses the settled promise on every subsequent refresh.

packages/mcp/src/index.ts[369-389]
packages/mcp/src/index.ts[1017-1022]
packages/mcp/src/index.ts[1093-1099]
packages/mcp/src/index.ts[1291-1295]
packages/mcp/src/tests/modern-manager.test.ts[61-77]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`startToolRefresh()` can leave an already-settled refresh state permanently installed when modern discovery completes synchronously because the cleanup runs before `entry.refreshState` is assigned.

## Issue Context
The modern no-tools-capability path skips `listAllTools()` and therefore reaches `refreshToolLoop()`'s `finally` without an await. Consolidate ownership in the existing refresh gate; no new state or branch is needed.

## Fix Focus Areas
- packages/mcp/src/index.ts[378-389]
- packages/mcp/src/index.ts[1017-1022]
- packages/mcp/src/index.ts[1093-1099]
- packages/mcp/src/__tests__/modern-manager.test.ts[61-77]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: 🧠 Deep: This is a high-density cross-package protocol and state-management change with 119 edit sites, multiple negotiation/fallback paths, discovery generations, subscriptions, storage, UI projections, and new validation logic, making independent subtle defects plausibly easy to miss in one pass.

Grey Divider

Tip of the day
💡 Did you know, you can show, collapse, or hide each part of a finding: code, evidence, and all

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread packages/mcp/src/index.ts Outdated

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dual-era negotiation and single-snapshot publication design are strong: protocol evidence, fallback boundaries, generation fencing, and config migration all stay at their existing owners. I found two concrete P2 regressions in the shared notification-refresh path. First, legacy unsolicited tools/list_changed compatibility is now accidentally gated by the server capability declaration. Second, the three-pass storm budget is retained for the entire connection lifetime, so four ordinary tool-list changes permanently freeze the snapshot. Both can be fixed at @maka/mcp without adding another registry or refresh authority.

I did not carry forward the separate cross-process config TOCTOU concern as a finding: the production Desktop constructs one store instance and the repository does not currently define a multi-writer contract, so a file-locking layer would be disproportionate without that requirement.

AI-assisted review: Codex coordinated two independent reviewer passes and an OpenCode Go DeepSeek V4 Flash high-effort adversarial pass. I verified the exact head 8be1e7dca1cfe2635603229835bb93427d13a931, the pinned SDK handler registration, production callers, the refresh state machine, and current CI. No local tests were run in this review.

中文审查

双时代协商和单一工具快照发布的总体设计很好:协议证据、fallback 边界、generation fence 和配置迁移都留在已有责任层。本轮确认了两个 P2:legacy unsolicited tools/list_changed 被 SDK 的 capability 声明意外门控;三次刷新预算被保留到整个连接生命周期,第四次正常工具变化会永久冻结快照。两项都应在 @maka/mcp 修复,不需要新增 registry 或刷新权威。

另一个跨进程配置 TOCTOU 候选没有保留为 finding:生产 Desktop 只创建一个 store,仓库目前也没有定义多写入者契约;在缺乏真实需求时引入文件锁不符合奥卡姆剃刀。

本次为 AI 辅助审查:Codex 协调两轮独立 reviewer 审查及 OpenCode Go DeepSeek V4 Flash high 对抗性复核,并核验了精确 head、pin 的 SDK handler 注册、生产调用方、刷新状态机和当前 CI。本轮未运行本地测试。

Comment thread packages/mcp/src/index.ts
Comment thread packages/mcp/src/index.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d88d6b0c-b725-4cdd-807c-9255b7ba3818

📥 Commits

Reviewing files that changed from the base of the PR and between 62556ab and 2de993e.

📒 Files selected for processing (25)
  • apps/desktop/src/main/__tests__/mcp-import.test.ts
  • apps/desktop/src/main/__tests__/mcp-ipc-main.test.ts
  • apps/desktop/src/main/__tests__/mcp-page-model.test.ts
  • apps/desktop/src/main/__tests__/mcp-runtime-e2e.test.ts
  • apps/desktop/src/main/e2e-fixture/scenarios-modules.ts
  • apps/desktop/src/renderer/locales/mcp-copy.ts
  • apps/desktop/src/renderer/mcp-catalog.ts
  • apps/desktop/src/renderer/mcp-import.ts
  • apps/desktop/src/renderer/mcp-page-model.ts
  • apps/desktop/src/renderer/mcp-page.tsx
  • apps/desktop/stories/module-hubs.stories.tsx
  • docs/architecture/mcp-runtime-architecture-draft.zh-CN.md
  • packages/core/src/mcp.ts
  • packages/mcp/src/__tests__/manager-fallback.test.ts
  • packages/mcp/src/__tests__/manager-subscription.test.ts
  • packages/mcp/src/__tests__/manager.test.ts
  • packages/mcp/src/__tests__/modern-manager.test.ts
  • packages/mcp/src/__tests__/sep-2243.test.ts
  • packages/mcp/src/__tests__/tool-output-validation.test.ts
  • packages/mcp/src/index.ts
  • packages/mcp/src/sep-2243.ts
  • packages/mcp/src/tool-output-validation.ts
  • packages/runtime/src/__tests__/mcp-tools.test.ts
  • packages/storage/src/__tests__/mcp-config-store.test.ts
  • packages/storage/src/mcp-config-store.ts

Included review availability: Your plan includes up to 3 reviews per rolling hour; 0 remain after this review.

Comment thread apps/desktop/src/renderer/mcp-import.ts Outdated
Comment thread apps/desktop/src/renderer/mcp-page.tsx Outdated
Comment thread docs/architecture/mcp-runtime-architecture-draft.zh-CN.md Outdated
Comment thread packages/mcp/src/index.ts

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up review on exact head 2de993e83. The latest microtask gate correctly closes the synchronous initial-refresh race, and the dual-era negotiation still keeps protocol evidence, fallback, generation fencing, and snapshot publication at the existing MCP manager authority.

The two previously posted P2 findings remain reproducible on this head, so I am not duplicating their inline threads: capability-less legacy tools/list_changed is still dropped by the SDK-gated handler, and refreshPasses still accumulates for the entire connection until the fourth ordinary change permanently suppresses refresh. The first-principles fix remains one manager-owned notification path per negotiated era and a burst-scoped—not connection-scoped—refresh budget.

The new inline P3 is independent and non-blocking.

AI-assisted review disclosure: Codex performed the final review using three independent reviewer passes and OpenCode Go DeepSeek V4 Flash (high effort) as an adversarial advisory pass. I verified the two state-machine failures and the UI validation path against exact head 2de993e83; no local tests were run, and current CI is green.

中文评论

对精确 head 2de993e83 的跟进审查。最新的 microtask gate 已正确修复同步 initial refresh race;dual-era negotiation 也仍将协议证据、fallback、generation fence 和 snapshot 发布留在既有 MCP manager 权威中。

此前两个 P2 在此 head 上仍可复现,因此不重复行内线程:未声明 capability 的 legacy tools/list_changed 仍被 SDK 门控丢弃;refreshPasses 仍按整个连接累计,第四次正常变化会永久 suppress refresh。更符合第一性原理的修复仍是:每个协商时代只有一个 manager-owned notification path,并把刷新预算限制在一次 burst,而不是整个 connection。

新增行内 P3 独立且不阻塞。

AI 辅助审查说明:Codex 使用三轮独立 reviewer 审查,并以 OpenCode Go DeepSeek V4 Flash(high effort)进行对抗性辅助审查;我已在精确 head 2de993e83 上核对两个状态机故障与 UI validation 路径。本轮未运行本地测试,当前 CI 为绿色。

Comment thread apps/desktop/src/renderer/mcp-page.tsx Outdated

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dual-era negotiation now has a clean authority model: exact modern pins do not downgrade, fallback is limited to protocol-absence evidence, modern subscriptions validate honored filters, and refresh/snapshot/tool bindings are fenced by connection generation. The two earlier P2s—legacy list_changed gating and permanently accumulated refresh budget—are fixed with focused coverage.

No remaining P0-P2 findings on this exact head. The failing Windows recovery check points to an unrelated Runtime Host IPC fixture rather than the MCP diff; it should be rerun before merge.

AI-assisted review disclosure: two Codex reviewers independently reviewed exact head f3fa1d7, protocol/security/error paths, current CI, and all existing review threads.

中文说明

双时代协商现在保持清晰的权威边界:精确 modern pin 不会降级,fallback 只发生在有协议缺失证据时,modern subscription 会验证服务端实际接受的 filter,刷新、snapshot 和 tool binding 都受 connection generation 保护。上一轮两个 P2 已修复。当前没有剩余 P0-P2;无关的 Windows recovery 失败需在合并前重跑。

@Astro-Han

Copy link
Copy Markdown
Contributor

Could you please add screenshots of the Desktop UI/UX changes before this PR is merged?

At minimum, please show:

  1. The remote MCP add/edit UI with the new Protocol preference control, including the SSE-forced Legacy state.
  2. The installed server details showing the negotiated protocol.

One annotated composite image is fine. Thanks!

Posted by Codex on behalf of Astro-Han.

@me2seeks

Copy link
Copy Markdown
Contributor Author

Added both requested Desktop screenshots to the PR body: the remote editor with SSE-forced Legacy protocol preference, and installed-server details showing the negotiated protocol. These are captures of the real Storybook component surfaces. I also added the repository-template AI use section and final squash trailer.

@me2seeks
me2seeks force-pushed the feat/1650-mcp-remote-dual-era-v2 branch from f3fa1d7 to a4d96cc Compare August 19, 2026 11:02
@me2seeks

Copy link
Copy Markdown
Contributor Author

Rebased onto current main at d2d0121; the four discovery-ownership commits already merged through #2663 were dropped, while the dual-era transport/configuration delta and its review fixes were preserved. Local verification on the new head a4d96cc: full repository build and all workspace typechecks; MCP 115/115; Storage 815 passed / 16 skipped; Runtime 2940 passed / 6 skipped; affected Desktop MCP tests 15/15; full Biome format check and diff check. The simplification audit still finds one versioned config field, one negotiation owner, and no duplicate transport authority. The PR body already includes the requested Storybook screenshot and AI-use disclosure.

@me2seeks

Copy link
Copy Markdown
Contributor Author

The three red checks reduce to two known/non-MCP baseline failures, not the dual-era delta. Runtime Host failed only owned Host exits promptly after its first connection closes; the exact PR head passes that test in isolation locally, and the existing fix is #3221 / tracking issue #3190. The aggregate test check reflects that same failure. Installed CLI Windows failed before Host registration while PowerShell could not load Microsoft.PowerShell.Security/Get-Acl; this runner-sensitive Local IPC startup family is documented in #3237 and its diagnostics landed via #3238. MCP itself is 115/115 locally and CI’s MCP workspace passed. No unrelated source changes were added here.

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code review passes on exact head a4d96cc17: I found no remaining P0–P2 correctness issue. The rebase preserves one MCP-manager authority for negotiation, generation-fenced refresh, and callable snapshot publication; legacy and explicit modern protocol behavior remain correctly separated. All eight review threads are resolved, and both requested Storybook screenshots show the real Legacy and negotiated-protocol surfaces.

I am leaving this as COMMENT rather than APPROVE because the required checks are currently red. The Runtime Host failure matches the unrelated #3190 timing flake, the aggregate test follows it, and the Windows installed-CLI job fails before Host registration when the runner cannot load PowerShell Security/Get-Acl; nevertheless, this exact head must rerun green before merge.

The PR body declares Maka assistance, but its section contains literal \n escapes and none of the 18 substantive branch commits has the required Generated-by trailer. Please fix the Markdown and add Generated-by: Maka to the AI-authored commits, or explicitly identify any human-only exceptions. After provenance and CI are green, this head is otherwise ready for approval.

Reviewed with Codex as an AI-assisted code review. I verified the full rebased delta, negotiation/migration authority, fallback and refresh state machines, review threads, screenshots, CI logs, and commit provenance; no external model output was used.

中文说明

代码层面未发现剩余 P0–P2,8 个 thread 已解决,两张 Storybook 截图也确实覆盖 Legacy 与协商协议状态。但 required checks 仍有红灯,即使看起来是无关基线 flake,也需要在当前 head 重跑为绿。PR body 的 AI 段落含字面量 \n,18 个实质性 commits 都没有 Generated-by trailer;请补齐或明确纯人工例外。CI 与 provenance 修好后,代码本身可进入 APPROVE。

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One additional independent pass found a concrete import ambiguity, so my earlier statement that the code had no remaining P0–P2 needs this correction. The P2 is inline below; the rest of the prior review, including the CI, screenshots, and provenance gates, remains unchanged.

中文说明

独立交叉复核发现一个具体 import 歧义,因此更正上一条“无剩余 P0–P2”的结论:下面还有一个 P2。此前关于 CI、截图和 provenance 的其余结论不变。

Comment thread apps/desktop/src/renderer/mcp-import.ts Outdated
Route connect-time tool discovery through the refresh loop so buffered
list-changed notifications join the same snapshot fence as refresh
requests, keep the connect abort signal attached to discovery, and
publish the latest valid snapshot when manual refreshes coalesce while
skipping the stale intermediate result of a notification burst.

Generated-by: Maka
The editor draft still carried the pre-unification command/args pair while
the rest of the page and the validator had moved to the single commandLine
field, so serialization round-trips mixed the two shapes. Route the draft
through formatCommandLine/parseCommandLine like the rest of the editor.

Generated-by: Maka
@me2seeks
me2seeks force-pushed the feat/1650-mcp-remote-dual-era-v2 branch from a4d96cc to 083536d Compare August 19, 2026 12:16
@me2seeks

Copy link
Copy Markdown
Contributor Author

Review remediation is now on 083536d9e: direct-map imports whose server ID is literally mcpServers are structurally disambiguated, with the exact requested regression. Desktop full: 942/942. All existing commits now carry the Maka trailer; the latest Codex remediation is separately attributed. The two accepted Storybook screenshots remain in the body. Please re-review the current head.

@me2seeks me2seeks left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved the earlier review threads on the current head; submitting these pending replies so the review record is complete.

Comment thread apps/desktop/src/renderer/mcp-page.tsx Outdated
Comment thread docs/architecture/mcp-runtime-architecture-draft.zh-CN.md Outdated
Comment thread packages/mcp/src/index.ts
Comment thread apps/desktop/src/renderer/mcp-page.tsx Outdated

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 083536d9ee3b6c2e710b4852f045a0db12de2190.

The earlier direct-map ambiguity is fixed: a server literally named mcpServers is now recognized when its value is itself a command- or URL-based server definition, with a focused regression. The negotiation and migration authority remains coherent, all review threads are resolved, all checks are green, both requested UI screenshots are present, and all 19 commits carry the declared Maka/Codex provenance trailers. I found no remaining P0–P2 issues.

Non-blocking: the PR body still says the PR is a draft and waits for #2663, although both statements are now stale.

AI-assisted review disclosure: Codex reviewed the exact-head diff, remediation, tests, current CI and threads, screenshots, and provenance metadata. No external model was used. Astro-Han authorized this review campaign.

中文说明

原先 mcpServers 作为真实 server ID 时的解析歧义已修复,并补了针对性回归。当前线程全部解决、CI 全绿、两张 UI 截图有效、19 个提交的 Maka/Codex trailer 完整,没有剩余 P0–P2。PR 正文中“仍为 draft、等待 #2663”已过时,但不阻塞批准。

@Astro-Han
Astro-Han merged commit f189da8 into apache:main Aug 19, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants