Skip to content

fix(hermes): keep cwd, transport sse and extra keys in Hermes MCP config - #3807

Merged
Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-t3-p2-hermes-mcp-shape
Nov 18, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 7 commits into
mainfrom
danielmeppiel-t3-p2-hermes-mcp-shape

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Hermes MCP servers now keep what the manifest declares. Until now APM rebuilt every Hermes entry through an allowlist (command/args/env or url/headers), so:

  • stdio cwd was dropped,
  • SSE remotes had no transport: sse and Hermes connected over Streamable HTTP, and
  • documented per-server keys such as timeout, connect_timeout and auth never reached config.yaml.

What changes:

  • Shape owner (adapters/client/_remote_shapes.py): the hermes row now uses type_key="transport" with {streamable-http: omitted, sse: "sse"}, is marked verified, and lists the 0.36 url-only shape as retired.
  • Hermes adapter (adapters/client/hermes.py): renders its native shape through the shared formatter. It keeps the modeled keys (command/args/env/cwd for stdio, url/headers/transport for remotes) and every extra key that passed the passthrough denylist owner (models/dependency/mcp.py), so serverUrl/httpUrl/enabled are still stripped. It drops the Copilot-only keys and stamps enabled last.
  • Upgrade heal: Hermes now opts into native content comparison and reports the 0.36 allowlist render as a legacy render (legacy_managed_renders). The ownership owner then rewrites APM-owned entries on the next apm install / update / install --frozen. A same-name entry the user wrote is preserved and reported as a conflict. Unrelated top-level config.yaml keys are untouched.
  • Frozen heal keeps ownership (install/mcp/ownership.py, found by Copilot review): apm install --frozen heals a fingerprinted registry entry but never writes the lockfile, so the next install saw a fingerprint mismatch and dropped the claim on every harness (later updates conflicted, removing the declaration left the entry behind). The owner now swaps the entry's remote shape keys back to a retired render; only when that reproduces the recorded fingerprint exactly, and the shape keys equal the current render, does it stay managed, and it is rewritten once so the lock records the current receipt. Any other edit stays a conflict.
  • Panel folds (lean panel, fix(hermes): keep cwd, transport sse and extra keys in Hermes MCP config #3807 (comment)): a stale receipt is refreshed through retain_native_receipt(replace=True) instead of forcing a rewrite, so repeated --frozen runs write nothing; _shape_delta is the single shape-change definition; a behavioral test asserts every runtime with retired shapes resolves compares_native_connections True (inherited opt-outs included); a hand-written same-name Hermes entry equal to the 0.36 render stays foreign; the frozen-heal unit matrix covers Copilot and Hermes.
  • Guard: mutation_writes.mcp_remote_shape_table now fails when a row lists retired shapes but its adapter sets compares_native_connections = False, since those writes could never heal. Registry decision text updated, mutation test added.

Vendor evidence (verified 2026-11-17):

Credit: implemented with parth (@Parth-Vasave), who reported and volunteered on #3749 (co-author trailer on the commits).

Issue and approved scope

Issue: Fixes #3749

Human scope-approval comment: #3749 (comment)

Does this PR complete the issue, or what remains? It completes it: project and user scope (including HERMES_HOME outside HOME) persist cwd, documented extra keys and transport: sse; unrelated keys are preserved; reinstall is idempotent; uninstall removes only APM entries; earlier APM writes heal.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Validation (macOS, .venv, -p no:xdist, lifecycle uses APM_BINARY_PATH=.venv/bin/apm, temp HOME, no network):

Command Result
pytest tests/unit/install/test_mcp_ownership.py tests/unit/adapters 344 passed (on current main 82f8047)
pytest tests/unit/test_mcp_integrator_remove_stale.py tests/unit/test_mcp_client_factory.py tests/unit/test_transitive_mcp.py tests/integration/test_mcp_install_flow.py tests/integration/test_hermes_target.py tests/integration/test_architecture_mcp_native_comparison.py tests/unit/scripts/test_architecture_runner.py tests/unit/adapters 654 passed
pytest tests/integration/test_architecture_owner_rule_mutations.py 657 passed
pytest tests/integration/test_hermes_mcp_fidelity_lifecycle.py tests/integration/test_mcp_remote_transport_harness_lifecycle.py tests/integration/test_mcp_retired_shape_heal_lifecycle.py 45 passed, 2 xfailed (the then-pending #3781 marker, since removed on main)
Red run, same unit tests on the unfixed source 8 failed (cwd, sse transport, extras, heal, golden hermes-sse)
Red run, Hermes lifecycle + heal [project-v0.36.0-install], [user-v0.35.1-install] + transport [user-sse] on the unfixed source 5 failed (KeyError: 'cwd', no transport: sse, no heal)
After merging main c775a7f: pytest tests/unit/adapters/test_hermes_client_adapter.py tests/unit/adapters/test_mcp_remote_transport_shapes.py tests/unit/install/test_mcp_ownership.py tests/unit/scripts/test_architecture_runner.py 209 passed
After merging main, APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_hermes_mcp_fidelity_lifecycle.py tests/integration/test_mcp_remote_transport_harness_lifecycle.py tests/integration/test_mcp_retired_shape_heal_lifecycle.py tests/integration/test_architecture_owner_rule_mutations.py 723 passed
Frozen-heal fold: pytest tests/unit/install/test_mcp_retired_shape_heal.py -k frozen_heal on the unfixed owner 1 failed (frozen-healed), 2 passed
Frozen-heal fold: test_mcp_retired_shape_heal_lifecycle.py -k frozen_heal_keeps on the unfixed owner 2 failed (claims empty after frozen + install)
After the fold: APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm pytest tests/integration/test_hermes_mcp_fidelity_lifecycle.py tests/integration/test_mcp_remote_transport_harness_lifecycle.py tests/integration/test_mcp_retired_shape_heal_lifecycle.py tests/integration/test_architecture_mcp_native_comparison.py tests/integration/test_mcp_install_flow.py tests/integration/test_hermes_target.py tests/integration/test_mcp_credential_scope_lifecycle.py tests/unit/test_mcp_integrator_remove_stale.py tests/unit/install 3650 passed, 1 skipped
Panel fold: second --frozen run on the previous owner (e4bcf2c) failed (.vscode/mcp.json rewritten, mtime changed)
At head 141ffc6 after the folds: the same targeted set plus tests/integration/test_mcp_only_lockfile_lifecycle.py tests/unit/adapters 3944 passed, 1 skipped
uvx [email protected] check / format --check on the CI paths passed
pylint --disable=all --enable=R0801 ... (CI paths) 10.00/10
bash scripts/lint-auth-signals.sh, bash scripts/lint-architecture-boundaries.sh passed
YAML-dump, str(relative_to), 2100-line guards passed

New tests:

  • tests/unit/adapters/test_hermes_client_adapter.py: goldens for stdio cwd plus extras, SSE transport: sse plus auth with denylisted aliases stripped, Streamable HTTP with no transport key, registry SSE remote, unrelated keys and foreign servers preserved and idempotent, and v0.36 heal (fingerprint and no-fingerprint) vs a foreign edit (CONFLICT).
  • tests/integration/test_hermes_mcp_fidelity_lifecycle.py (L4, RT3's oracle plus a package apm uninstall -g case).
  • Tests that set HERMES_HOME use tmp_path roots and carry windows_compat (a POSIX literal is relative on Windows and the user-root owner rejects it).
  • Hermes restored in the fix(mcp): render remote transports per harness and heal retired shapes #3789 transport matrix and in the _assert_healed upgrade assertions.

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour. No requirement pins harness MCP keys; the apm-spec-waiver: line is in the fix commit message.

Hermes rebuilt every server entry through a lossy allowlist, so stdio cwd,
the `transport: sse` discriminator and documented passthrough keys
(timeout, connect_timeout, auth, ...) never reached config.yaml.

- Switch the `hermes` row of the remote shape owner to
  type_key=transport ({streamable-http: omitted, sse: "sse"}), verified,
  with the 0.36 url-only shape retired.
- Hermes renders its native shape (modeled keys plus non-denylisted
  `extra` passthrough) and opts into native comparison, so ownership
  recognizes the 0.36 allowlist render and heals APM-owned entries on the
  next install; foreign entries stay preserved.
- Shape-table guard: a row with retired shapes must be bound by an adapter
  that keeps native comparison on.
- Tests: unit goldens, ownership heal/conflict, guard mutation, L4 Hermes
  lifecycle (HERMES_HOME outside HOME), and Hermes restored in the P1
  transport and heal lifecycle matrices.

Fixes #3749

apm-spec-waiver: Hermes MCP native shape follows vendor docs; no OpenAPM requirement pins harness MCP keys (T3 brief F29)

Co-authored-by: Parth-Vasave <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…ermes MCP

Co-authored-by: Parth-Vasave <[email protected]>
Co-authored-by: Copilot App <[email protected]>

Copilot AI 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.

🟡 Changes recommended

Frozen SSE healing leaves a stale content hash, causing subsequent installs to drop Hermes’ ownership claim and leading to update conflicts and incomplete uninstall cleanup.

1 open issue
What changed in this PR

This PR addresses #3749 by preserving Hermes MCP configuration fields and extending the shared transport-shape and ownership mechanisms introduced in #3789.

Changes:

  • Preserve stdio cwd, allowed extra keys, and transport: sse in Hermes configuration.
  • Enable native comparison and migration of earlier APM-written entries.
  • Add lifecycle coverage, an architecture guard, and updated usage documentation.
File Description
tests/​unit/​install/​test_mcp_ownership.py Include Hermes among native-comparison adapters.
tests/​unit/​adapters/​test_mcp_remote_transport_shapes.py Update the Hermes SSE expected shape.
tests/​unit/​adapters/​test_hermes_client_adapter.py Test field preservation, migration, and conflict protection.
tests/​integration/​test_mcp_retired_shape_heal_lifecycle.py Restore Hermes migration assertions.
tests/​integration/​test_mcp_remote_transport_harness_lifecycle.py Include Hermes in transport lifecycle coverage.
tests/​integration/​test_hermes_mcp_fidelity_lifecycle.py Add configuration preservation and uninstall scenarios.
tests/​integration/​test_architecture_owner_rule_mutations.py Test rejection of disabled comparison for retired shapes.
src/​apm_cli/​adapters/​client/​hermes.py Preserve native fields and recognize legacy renders.
src/​apm_cli/​adapters/​client/​_remote_shapes.py Define Hermes SSE transport and retire the URL-only shape.
scripts/​architecture_linter/​checks/​mutation_mcp_remote_transport.py Guard native comparison for adapters with retired shapes.
packages/​apm-guide/​.apm/​skills/​apm-usage/​dependencies.md Document Hermes transport and passthrough fields.
docs/​src/​content/​docs/​integrations/​hermes.md Explain preserved fields and migration behavior.
docs/​src/​content/​docs/​consumer/​install-mcp-servers.md Update Hermes transport and ownership guidance.
CHANGELOG.md Add the Hermes configuration fix entry.
.apm/​architecture/​owners/​hooks-integrations.json Extend the shape owner's native-comparison contract.

Review effort: Balanced

…dows-safe

Replace the CHANGELOG placeholder with (#3807). The HERMES_HOME override
unit test used a POSIX literal, which is relative on Windows and now
rejected by the user-root owner; it uses a tmp_path root instead. The
Hermes tests that set HERMES_HOME join the windows_compat family.

Co-authored-by: Parth-Vasave <[email protected]>
Co-authored-by: Copilot App <[email protected]>
`apm install --frozen` heals an APM-owned registry entry from a retired
remote shape but never writes apm.lock.yaml, so its fingerprint still
describes the retired shape. The next install saw a fingerprint mismatch,
classified the healed entry as foreign and dropped the claim on every
harness, so later updates conflicted and removing the declaration left
the entry behind.

The ownership owner now swaps the entry's remote shape keys back to a
retired render's values; when that reproduces the recorded fingerprint
exactly (and the shape keys equal the current render) the entry stays
managed and is rewritten once so the lock records its current receipt.
Any other edit changes the fingerprint and stays a conflict.

apm-spec-waiver: ownership fingerprint bookkeeping only; no OpenAPM requirement covers harness MCP receipts

Co-authored-by: Parth-Vasave <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…ntry

Panel folds on the frozen-heal ownership fix:

- A receipt that predates a --frozen heal no longer forces UPDATE_MANAGED.
  compare_native_mcp_connection reports it through stale_receipts and the
  entry stays MATCHING_MANAGED; the registry path refreshes the receipt via
  retain_native_receipt(replace=True). Repeated --frozen runs write nothing
  and env-derived values are not churned.
- _shape_delta is the one definition of a shape change, shared by the
  retired-shape heal and the stale-receipt check.
- Behavioral guard: every runtime whose shape row retires earlier shapes
  resolves compares_native_connections True (covers inherited opt-outs).
- Hermes cells: the frozen-heal unit matrix runs for Copilot and Hermes,
  and a hand-written same-name Hermes entry equal to the 0.36 render stays
  foreign and unclaimed.

apm-spec-waiver: ownership fingerprint bookkeeping only; no OpenAPM requirement covers harness MCP receipts

Co-authored-by: Parth-Vasave <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_now

Hermes MCP entries now keep cwd, transport sse and extra passthrough keys in config.yaml. Entries written by earlier APM releases are healed in place without dropping ownership, including under install --frozen.

panel-mode=lean; personas=python-architect,test-coverage-expert,apm-ceo

cc Sergio Sisternes (@sergio-sisternes-epam) -- a fresh advisory pass is ready for your review.

This PR fixes a real fidelity gap in #3749 for a harness we already support: APM was writing lossy Hermes configs. The fix sits in the right place. Hermes moves onto the shared remote-shape owner instead of keeping a private key allowlist, and its opt-out from native comparison is removed, so ownership checks now read what is actually on disk. The change stays inside the approved scope (cwd, sse transport, non-denylisted extras, healing earlier writes, no changes to other harness rows), and the docs and CHANGELOG are updated in the same PR.

Both panelists agreed on all their findings. python-architect raised three: a stale receipt that kept rewriting files, duplicated shape-delta logic, and a guard that inherited attributes could slip past. test-coverage-expert raised two: no proof that a user's same-name Hermes entry is left alone, and frozen-heal negative cases that only ran against Copilot. All five were recommended-tier and all five are folded at 141ffc6 with test evidence. The most important is the stale-receipt fold: a new lifecycle check asserts that a second --frozen run leaves native bytes and mtimes unchanged on every harness. It failed before the fold (VS Code mcp.json was rewritten) and passes now. The other test-backed folds:

  • A hand-written Hermes entry identical to the exact 0.36 render is asserted unchanged and unclaimed.
  • The frozen-heal matrix now runs over both copilot and hermes (healed, edited-after-heal, user-reshaped).
  • A behavioral guard resolves compares_native_connections on the client object, so inherited values or properties can no longer slip past it.

The earlier high-severity Copilot reviewer finding (frozen heal dropped ownership on every harness) was fixed with red-before-fix evidence. That fix closes a frozen-install ownership hole for every harness, not just Hermes.

Aligned with: Portable by manifest (the same apm.yml declaration now yields a complete Hermes config); Secure by default (only APM-owned entries heal or are removed, same-name user entries are never taken over, denylisted httpUrl/serverUrl still stripped); Governed by policy (the guard fails when a row retires shapes but its adapter does not compare native content); Multi-harness (Hermes leaves the unverified set with vendor-cited transport semantics; the frozen-heal fix applies to every harness at project and user scope); Pragmatic as npm (no migration command, earlier writes heal on the next install, repeated --frozen runs leave files untouched).

Panel summary

Persona B R N Takeaway
Python Architect 0 3 0 Heal placed in the ownership owner, fingerprint un-heal is sound; stale-receipt rewrite and duplicated shape-delta flagged (both folded).
Test Coverage Expert 0 2 0 Every scoped Hermes promise has a real-binary lifecycle trap that fails on revert; foreign/edited same-name Hermes cells added.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Recommendation

All panel and Copilot reviewer findings are folded at 141ffc6, each with a test that fails when the fix is reverted, and nothing remains open. Next step: confirm CI is green on 141ffc6 and get a review from the CODEOWNERS-requested reviewer, Sergio Sisternes (@sergio-sisternes-epam), then ship in 0.36.1. Keep watching the frozen-install idempotency assertion (unchanged native bytes and mtimes on every harness); any future retired-shape heal depends on it.


Full per-persona findings

Python Architect

  • [recommended] A stale receipt used UPDATE_MANAGED to refresh, so every later --frozen install rewrote the same entry at src/apm_cli/install/mcp/ownership.py
    Refreshing the lock receipt and writing the native file are different decisions; --frozen never writes the lock, so the rewrite repeated and could churn env-derived values.
    Folded at 141ffc6: compare reports stale_receipts; the entry stays MATCHING_MANAGED and the registry caller refreshes via retain_native_receipt(replace=True). Lifecycle asserts a second --frozen run writes nothing.
  • [recommended] _in_retired_shape and _healed_since_receipt each computed the shape-key delta
    One definition should decide which differences are APM's shape change.
    Folded: _shape_delta shared by both.
  • [recommended] The AST guard reads only the adapter's own class body, so an inherited compares_native_connections = False gets past it at scripts/architecture_linter/checks/mutation_mcp_remote_transport.py
    Folded: test_every_runtime_with_retired_shapes_compares_native_content checks the resolved attribute for every runtime with retired shapes.

Test Coverage Expert

  • [recommended] No lifecycle test proved a user-authored same-name Hermes MCP entry is preserved rather than taken over
    Folded: test_foreign_entry_in_a_retired_shape_is_never_taken_over plants heal-foreign = {url, enabled: true} (the exact 0.36 Hermes render) and asserts it unchanged and unclaimed.
  • [recommended] Frozen-heal negative cases ran only against Copilot
    Folded: test_frozen_heal_keeps_the_retired_receipt_verifiable is parametrized over copilot and hermes.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.

@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Drive-to-merge pass: ready to merge

Head 141ffc6f81 is landing-ready for 0.36.1: every Copilot and panel finding is folded, CI is green, and the canonical-owner gate verified exact-head functional evidence for the 3 touched owners (MCP ownership, remote-shape table, MCP install routing). Panel advisory: #3807 (comment)

Folded in this run

  • (copilot) Keep ownership of fingerprinted registry entries after a --frozen heal (shared ownership owner) -- resolved in e4bcf2c.
  • (panel) Refresh a stale frozen-heal receipt via retain_native_receipt(replace=True) instead of forcing a rewrite; repeated --frozen writes nothing -- resolved in 141ffc6.
  • (panel) _shape_delta is the single shape-change definition -- resolved in 141ffc6.
  • (panel) Behavioral guard: runtimes with retired shapes resolve compares_native_connections True -- resolved in 141ffc6.
  • (panel) A hand-written same-name Hermes entry equal to the 0.36 render stays foreign and unclaimed -- resolved in 141ffc6.
  • (panel) Frozen-heal unit matrix covers Copilot and Hermes -- resolved in 141ffc6.

Copilot signals reviewed

  • src/apm_cli/adapters/client/_remote_shapes.py:235 -- LEGIT: --frozen heal kept the stale lock fingerprint, so the next install dropped the claim (reproduced on every harness) (resolved in e4bcf2c).

Regression-trap evidence (mutation-break gate)

  • test_mcp_retired_shape_heal_lifecycle.py::test_frozen_heal_keeps_ownership_of_fingerprinted_registry_entries -- removed _healed_since_receipt; claims were empty after --frozen + install; guard restored.
  • Same test, second --frozen no-write assertion -- reverted to the forced rewrite; .vscode/mcp.json was rewritten; fold restored.
  • test_mcp_retired_shape_heal.py::test_frozen_heal_keeps_the_retired_receipt_verifiable -- removed the stale-receipt check; frozen-healed failed; guard restored.
  • test_hermes_mcp_fidelity_lifecycle.py -- on the unfixed Hermes adapter: KeyError: 'cwd', no transport: sse, no heal.

Lint contract

ruff check and ruff format --check (pinned 0.15.12) on the CI paths, pylint R0801, lint-auth-signals.sh and lint-architecture-boundaries.sh all silent.

CI

gh pr checks 3807 at 141ffc6: 23 pass, 3 skipping, 0 fail. The Windows Compatibility Gate ran the Hermes fidelity lifecycle and the Copilot/Hermes frozen-heal cells (1052 passed). 0 unresolved review threads (after 0 CI fix iterations).


Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors.

Resolve tests/unit/adapters/test_hermes_client_adapter.py by keeping
#3815's tmp_path-based, windows_compat HERMES_HOME override test; the
#3749 Hermes tests keep their tmp_path fixture and windows_compat marks.

Co-authored-by: Parth-Vasave <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 754a6ab into main Nov 18, 2026
26 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-t3-p2-hermes-mcp-shape branch November 18, 2026 03:13
@Parth-Vasave

Copy link
Copy Markdown
Contributor

Thanks for picking this up and for the co-author credit!

I verified the fix on main at 70554b6:

  • Re-ran the repro from [BUG] Hermes MCP adapter drops cwd, extra passthrough keys and the SSE transport when writing config.yaml #3749 against the commit before the merge and against main. Before, config.yaml only had command/args/url. Now cwd, timeout, connect_timeout, auth: oauth and transport: sse all come through. Unrelated top-level keys (model, etc.) are kept, and reinstalling leaves the file byte-identical.
  • The adapter, remote-shape and heal unit tests all pass, and so do test_hermes_mcp_fidelity_lifecycle.py and test_mcp_retired_shape_heal_lifecycle.py run against a source-built apm.

I haven't checked this against a live Hermes agent, so that part isn't covered. LGTM.

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.

[BUG] Hermes MCP adapter drops cwd, extra passthrough keys and the SSE transport when writing config.yaml

3 participants