Skip to content

feat(mecated): streamline direct MCP OAuth onboarding - #1689

Merged
jhrozek merged 24 commits into
mainfrom
impl/direct-mcp-onboarding
Sep 18, 2026
Merged

jhrozek merged 24 commits into
mainfrom
impl/direct-mcp-onboarding

Conversation

@jhrozek

@jhrozek jhrozek commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements direct streaming-HTTP MCP OAuth onboarding without changing ToolHive broker behavior.

  • Adds mecated mcp add, login, status, and remove lifecycle commands with a shared selected-profile/config-resolution path.
  • Generates validated operator configuration, secure credential storage setup, sourced key-file guidance, and attended login progress/error reporting.
  • Adds direct OAuth metadata discovery and DCR-aware registration/removal behavior.
  • Separates native and legacy credential domains; native custody uses initialization markers and fails closed for ambiguous or unmarked artifacts.
  • Makes custody setup and attended file confirmation cancellation-aware.
  • Updates MCP OAuth documentation, architecture, acceptance evidence, and ADR 0345.

Acceptance / verification

Baseline gate exceptions

task test is blocked by a pre-existing intermittent test synchronization race in internal/adapter/osfs/managed_temp_scenario_unix_test.go (TestADR_0281_ForegroundLeaseOverlayAndMetadataPrivacy), unrelated to this change.

task ac-trace-strict is blocked by pre-existing non-MCP acceptance proof gaps: operator-defined-provider AC4.4 and a proposed/unimplemented TypeScript SDK WKT plan. The direct-MCP onboarding plan is fully traced.

@samuv samuv 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.

I found four issues:

  1. [P1] Valid unmarked file keys are adopted. In internal/adapter/mcpcredential/custody.go:543-545, readOrCreateFileKey returns any valid existing key before checking allowPendingArtifact. This violates the central fail-closed guarantee that unmarked artifacts are never adopted. The existing regression test misses this because its fixture includes a newline, making the base64 non-canonical.

  2. [P2] The key artifact is created before the pending marker. In internal/adapter/mcpcredential/custody.go:175-185, a crash after openNew writes the file/keyring entry but before publishMarker leaves an unmarked artifact. A subsequent attempt cannot perform the documented pending-marker recovery (the file path currently only appears recoverable because of finding 1).

  3. [P2] Marker publication uses a fixed .new filename. In internal/adapter/mcpcredential/custody.go:343-348, a process crash before the deferred unlink leaves .mcp-credential-backend.json.new behind. Every later publication then fails its O_EXCL open with EEXIST, so a valid pending marker cannot progress to ready without manual cleanup.

  4. [P2] Empty query components are accepted by the query-free URL checks. In internal/adapter/mcp/direct_discovery.go:96-110, both exactDirectResource("https://mcp.example/mcp?") and exactDirectURL("https://mcp.example/metadata?") succeed because only RawQuery is checked, while url.URL.ForceQuery is ignored. This contradicts the query-free bootstrap contract and the requirement to reject query-bearing resource/metadata URLs before authority expansion.

Focused package tests pass. Dedicated temporary regression tests reproduced findings 1 and 4; those tests were not retained in the worktree.

jhrozek and others added 21 commits September 18, 2026 12:48
Probe a direct MCP resource without credentials, parse one atomic Bearer challenge, enforce exact same-origin protected-resource metadata, and qualify one issuer through bounded RFC 8414/OIDC discovery.

This is local spike evidence for Plan PR #1626, not a shippable implementation.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Add a root-pinned keyring/file wrapping-key seam, strict native MCP credential configuration, and loader support while preserving legacy key_env profiles.

The prototype hardens marker and key files with no-follow owner checks, atomic durable publication, and complete locator pinning. Linux production Secret Service detection remains a recorded spike gap.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Extend the local direct-DCR lifecycle with removing and removed states so grant deletion and profile removal can be retried without erasing pending or uncertain registration evidence.

The root-internal removal seam preserves shared key custody and makes no upstream revocation claim.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Add local add/list/remove command routing, narrow validated YAML mutation, hardened settings publication, redacted onboarding progress, issuer discovery, pinned credential selection, existing login delegation, and recoverable credential removal.

The commands are spike evidence only; settings-source shadow detection, the production Linux detector, RFC 9207 login binding, and live attended qualification remain documented gaps.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Nest keyring and file custody fields under local.key and handle an empty settings document as block-style YAML so generated profiles validate against the real schema.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Normalize both empty input and an existing empty mapping before appending block-style MCP nodes.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Prove the lifecycle command's empty mapping placeholder accepts native custody without emitting malformed flow-style YAML.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
mecated mcp add's default settings path and credential root/key path
used the stdlib os.UserConfigDir(), which resolves to ~/Library/Application
Support on macOS instead of mecatl's own XDG_CONFIG_HOME-or-~/.config
convention every other command (login, serve, ...) already follows.
add would silently read/write a different, empty settings file than the
one every other mecatl command uses, and never surface the new server
anywhere a user would actually look.

Switch to xdgconfig.UserConfigDir/UserStateDir, matching the acceptance
plan's own stated defaults: $XDG_STATE_HOME/mecatl/mcp-credentials for
ciphertext, $XDG_CONFIG_HOME/mecatl/mcp-credential-key for file custody.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
PrepareOAuthDCRLogin's reuse path only recognized "pending" and
"ready" lifecycle states explicitly; a valid "removed" tombstone (left
by a correct mecated mcp remove) fell through to the catch-all and was
classified OAuthDCRRecoveryCorrupt, blocking the exact re-add path
Scenario 6 / AC6.4 promises: a later add may replace a valid removed
tombstone with a fresh pending generation and perform a new upstream
registration.

Mirror the existing "no record at all" fresh-registration path, but
CAS-replace the current (removed) record instead of a create-only Put,
including the same concurrent-winner fallback for a racing add.

Verified live end-to-end (remove, then re-add with a genuinely new
DCR client registration) in addition to the new offline regression
test.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Add the production implementation in progress for URL-first direct MCP add, list, login, and remove: hardened issuer discovery, keyring/file-key custody, strict settings mutation, source provenance, and crash-recoverable DCR removal.

Full lint, docs, API compatibility, and offline demo gates pass. The full race suite remains blocked by unrelated macOS Unix-socket path and command-runner environment failures; the plan remains in-progress.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Address panel findings in direct MCP discovery, RFC 9207 callback binding, keyring custody, settings lifecycle commands, and crash-recoverable DCR removal.

Add focused offline command and acceptance coverage. Remaining live qualification and broader aggregate proof are tracked by the in-progress contract.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
TestMCPOAuthLoginTimeoutDiagnostics_Scenario1_CLIAndDiagnosticsRedaction
predates the onboarding work's progress lines (settings source/winner,
"preparing browser authorization", etc.), which legitimately print to
stdout. Narrow the assertion to what the test actually defends: the
diagnostic content itself (the redacted URL, the level marker) must
never appear on stdout, not that stdout is empty.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
runMCPAdd's internal runMCPLogin call never passed stderr through, so
any diagnostics logged during add's login/verification step were
silently discarded via runMCPLogin's own io.Discard default — the
exact same "no logs" gap #1624 fixed for mcp login directly, just not
propagated to the newer add command that wraps it.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
…choke point

mcp.Connect already redacts its returned error before this point, so logging
it here cannot leak a credential-bearing URL. Every login-connect failure
(transport, token restore, DCR, MCP handshake) passes through this one site,
so this is the one diagnostic line that actually helps diagnose a live
`mecated mcp login` failure without adding per-layer instrumentation.

Co-Authored-By: mecatl <[email protected]>
Add command-level offline acceptance proofs for discovery, credential custody, login output and recovery, non-presenting list behavior, and DCR removal retries.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Amend the direct MCP onboarding contract so existing key_env profiles retain their legacy namespace while native keyring/file profiles use a marker-bound native namespace without record migration.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Add pending-to-ready native custody recovery, cancellation-aware lifecycle commands, selected-profile loading, and legacy/native credential namespace isolation.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Bind pending recovery to created key material and require explicit recovery before native credential operations.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
Keep pending marker recovery and fail-closed custody checks readable under the lint complexity limit.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
unix.Stat_t.Dev is int32 on Darwin but uint64 on Linux; mcpSettingsDevice
hardcoded int32, which built fine on the author's Mac but failed to
compile on Linux CI, cascading into most of the PR's CI checks. Split
the normalizer into darwin/other variants matching this file's existing
sunpath_darwin.go/_other.go pattern.
Publish pending custody state before key material, use unique marker temporaries, and reject query-bearing discovery URLs.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
@jhrozek
jhrozek force-pushed the impl/direct-mcp-onboarding branch from f6bb310 to 80cad2c Compare September 18, 2026 11:18
jhrozek and others added 2 commits September 18, 2026 14:49
The native custody refactor removed its last caller; golangci-lint's
unused check was failing CI on it.

Co-Authored-By: mecatl <[email protected]>
Lead with the native custody workflow and retain a valid legacy manual-profile path.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>

@samuv samuv 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.

All four findings from the previous review are addressed, and the focused custody/discovery tests and current CI are green. Approving.

One non-blocking follow-up remains from the re-review: initial marker publication still has a crash window between Linkat(temp, marker) and Unlinkat(temp). A process death there leaves the marker inode with two hardlinks; verifyPrivateFD then rejects it because Nlink != 1, so the next Resolve reports MCP credential backend marker is invalid instead of recovering the valid pending state. Please retain this as a follow-up and add regression coverage for that exact boundary.

Clean the verified temporary hard link after an initial marker publish is interrupted.

Ref: #1613

Co-Authored-By: mecatl <[email protected]>
@jhrozek
jhrozek force-pushed the impl/direct-mcp-onboarding branch from ec49515 to 15075e5 Compare September 18, 2026 14:56
@jhrozek
jhrozek merged commit d2200ab into main Sep 18, 2026
36 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