Skip to content

fix(mcp): import Hermes and OpenCode remote servers as Streamable HTTP - #8824

Merged
allenxu09 merged 3 commits into
farion1231:mainfrom
L4XB:fix/mcp-import-remote-transport
Nov 29, 2026
Merged

allenxu09 merged 3 commits into
farion1231:mainfrom
L4XB:fix/mcp-import-remote-transport

Conversation

@L4XB

@L4XB L4XB commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary / 概述

Hermes connects to a url MCP server over Streamable HTTP and uses SSE only when the entry sets transport: sse. OpenCode connects to remote servers over Streamable HTTP. CC Switch imported every such server as sse, so enabling an imported server for Claude Code or another app wrote type: sse for an endpoint that speaks Streamable HTTP. Writing a server back to Hermes also dropped transport: sse.

  • convert_from_hermes_format: a url entry becomes http, or sse when it sets transport: sse.
  • Writing to Hermes keeps a transport: sse that the existing entry already has while the server stays sse, and drops it when the server is http. It never adds one: rows that earlier importers stored as sse came from plain url entries, which Hermes keeps reaching over Streamable HTTP.
  • convert_from_opencode_format: remote becomes http.

This matches the newer importers: Pi, Agy, Mcode and Kimi already map a URL server without a transport to http. Servers imported before this change keep the type they were stored with.

Related Issue / 关联 Issue

Fixes #8823

Testing

End to end with a temporary integration test (not part of this PR). It sets up Hermes with notion: {url: https://mcp.notion.com/mcp} and legacy: {url: https://legacy.example.com/sse, transport: sse} and OpenCode with a remote server linear, imports both, enables the three servers for Claude Code, then edits legacy:

main this PR
notion (Hermes, plain url) in ~/.claude.json "type":"sse" "type":"http"
linear (OpenCode remote) in ~/.claude.json "type":"sse" "type":"http"
legacy (Hermes, transport: sse) in ~/.claude.json "type":"sse" "type":"sse"
legacy in Hermes config.yaml after the edit transport dropped transport: sse kept
  • Updated the Hermes and OpenCode import tests that expected sse for a plain URL server. New tests: test_convert_hermes_sse_transport_to_unified, test_merge_keeps_hermes_sse_transport_while_server_is_sse, test_merge_drops_sse_transport_when_server_is_http, and test_merge_does_not_add_transport_to_rows_stored_as_sse for the upgrade path (an existing entry without transport plus a stored sse row).
  • Upgrade path end to end: with Hermes notion: {url: https://mcp.notion.com/mcp, enabled: true, timeout: 30} and a stored sse row for it, an edit in CC Switch writes notion back without transport.
  • cargo test: 4240 passed; cargo test --lib mcp::: 66 passed.
  • cargo fmt --check passes. cargo clippy --lib reports nothing in the changed files (Rust 1.99.1; its 5 warnings are in proxy/forwarder.rs, gemini_mcp.rs and the two auto-sync services).

Checklist / 检查清单

  • cargo clippy passes (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)
  • Rust-only change: no frontend code or user-facing text changed, so pnpm typecheck, pnpm format:check and the i18n files are not affected.

Hermes connects to a `url` server over Streamable HTTP and uses SSE only
when the entry sets `transport: sse`, and OpenCode connects to `remote`
servers over Streamable HTTP. Both importers stored every such server as
`sse`, so enabling an imported server for Claude Code or another app
wrote `type: sse` for an endpoint that speaks Streamable HTTP.

Import them as `http`, keep `sse` for Hermes entries that set
`transport: sse`, and write `transport: sse` back to Hermes for SSE
servers so that choice survives a sync.

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the fix and the upstream references. The import side matches what Hermes and OpenCode actually do. One problem on the Hermes write side:

[P1] Rows stored as sse by the old importer now get transport: sse written into Hermes, which breaks servers that used to work

Before this change every Hermes url entry (and every OpenCode remote entry) was imported as type: sse, and convert_to_hermes_format wrote those rows back as a plain url. Hermes therefore kept connecting over Streamable HTTP, falling back to SSE on its own when needed. These rows are not migrated, and importing again does not fix them: for an id that already exists, import_from_hermes only sets apps.hermes and keeps the stored spec (hermes.rs#L309-L314).

After upgrading, the next time such a row is projected to Hermes (editing or toggling the server, or re-syncing MCP, all through sync_single_server_to_hermes), the new branch at hermes.rs#L98-L100 adds transport: sse, and merge_hermes_spec carries it into the existing entry. In Hermes, transport == "sse" takes the SSE path directly, and when SSE fails it does not retry Streamable HTTP (_run_http). An entry like notion: {url: https://mcp.notion.com/mcp} that was imported before this change and worked in Hermes would stop connecting.

I checked this on a merge with current main: merge_hermes_spec({"url": ..., "enabled": true, "timeout": 30}, convert_to_hermes_format({"type": "sse", "url": ...})) returns an entry with "transport": "sse".

The write side needs to handle rows stored as sse by the earlier importers before it starts emitting transport: sse, with a test that covers this upgrade path (an existing Hermes entry without transport plus a stored sse row).

Everything else passes on the merge with main (cargo fmt --check, cargo clippy -- -D warnings, cargo test). Once this is addressed it is good to merge, and I'm happy to re-review quickly.

Rows that earlier importers stored as `sse` came from plain Hermes `url`
entries, which Hermes reaches over Streamable HTTP and falls back from
to SSE on its own. Writing `transport: sse` for every SSE row would move
those servers to SSE only, with no fallback, on their next sync.

Write SSE rows without `transport` again, and keep a `transport: sse`
that the existing Hermes entry already has while the server stays SSE.
@L4XB

L4XB commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, you're right. A row stored as sse by the old importer can't be told apart from a real SSE row, so the write side must not add transport: sse. Fixed in 3fc3cb3:

  • convert_to_hermes_format writes SSE rows without transport again, as on main.
  • On merge-on-write, a transport: sse that the existing Hermes entry already has is kept while the server stays sse, and dropped when it is http (merge_into_existing_entry).

Tests: test_merge_does_not_add_transport_to_rows_stored_as_sse is your case (existing {url, enabled, timeout: 30} plus a stored sse row: no transport, timeout kept). test_merge_keeps_hermes_sse_transport_while_server_is_sse and test_merge_drops_sse_transport_when_server_is_http cover the other two.

End to end, with a temporary integration test that is not part of the PR: Hermes has notion: {url: https://mcp.notion.com/mcp, enabled: true, timeout: 30} and legacy: {url: https://legacy.example.com/sse, transport: sse}, CC Switch has both stored as sse with Hermes enabled, and both are then edited in CC Switch. With e3c4c20, notion got transport: sse. With 3fc3cb3 it is written without one, and legacy keeps transport: sse.

cargo test: 4240 passed. cargo fmt --check passes, and cargo clippy --lib reports nothing in hermes.rs.

@funkpopo funkpopo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the clean fix in 3fc3cb3d!

  • Importing Hermes url entries (unless explicitly marked transport: sse) and OpenCode remote entries as Streamable HTTP (http) matches upstream client behavior.
  • The write-side regression from the previous review is resolved: merge_into_existing_entry preserves an existing transport: sse while the server stays sse, never injects transport: sse onto legacy sse rows, and drops it when switched to http, backed by 4 dedicated unit tests.
  • Merges cleanly onto latest main (bd3d38801) with all CI checks green.

LGTM, ready to merge.

@allenxu09 allenxu09 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM。

核对确认了 Hermes 与 OpenCode 远程 MCP 导入及回写逻辑:

  1. 导入语义对齐:convert_from_hermes_format 对纯 url 条目导入为 http(仅 transport: sse 导入为 sse),convert_from_opencode_format 将 remote 导入为 http,符合双方默认 Streamable HTTP 行为。
  2. 存量 SSE 条目回写安全:merge_into_existing_entry 仅在现有 Hermes 条目本身带有 transport: sse 且配置仍为 sse 时保留该字段;对旧版导入成 sse 但 Hermes 原配置无 transport 的条目不会误写入 transport: sse,切回 http 时也会正确移除。
  3. 测试与 CI:新增及更新的单元测试覆盖各路径,跨平台后端 CI 全绿。

@allenxu09
allenxu09 merged commit a02c3a1 into farion1231:main Nov 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Backend (Rust/Tauri) mcp Related to MCP server management

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP servers imported from Hermes or OpenCode are saved as SSE, although both connect to them over Streamable HTTP

4 participants