Repository navigation
feat(mecated): streamline direct MCP OAuth onboarding - #1689
Conversation
samuv
left a comment
There was a problem hiding this comment.
I found four issues:
-
[P1] Valid unmarked file keys are adopted. In
internal/adapter/mcpcredential/custody.go:543-545,readOrCreateFileKeyreturns any valid existing key before checkingallowPendingArtifact. 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. -
[P2] The key artifact is created before the pending marker. In
internal/adapter/mcpcredential/custody.go:175-185, a crash afteropenNewwrites the file/keyring entry but beforepublishMarkerleaves an unmarked artifact. A subsequent attempt cannot perform the documented pending-marker recovery (the file path currently only appears recoverable because of finding 1). -
[P2] Marker publication uses a fixed
.newfilename. Ininternal/adapter/mcpcredential/custody.go:343-348, a process crash before the deferred unlink leaves.mcp-credential-backend.json.newbehind. Every later publication then fails itsO_EXCLopen withEEXIST, so a valid pending marker cannot progress toreadywithout manual cleanup. -
[P2] Empty query components are accepted by the query-free URL checks. In
internal/adapter/mcp/direct_discovery.go:96-110, bothexactDirectResource("https://mcp.example/mcp?")andexactDirectURL("https://mcp.example/metadata?")succeed because onlyRawQueryis checked, whileurl.URL.ForceQueryis 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.
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]>
f6bb310 to
80cad2c
Compare
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
left a comment
There was a problem hiding this comment.
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]>
ec49515 to
15075e5
Compare
Summary
Implements direct streaming-HTTP MCP OAuth onboarding without changing ToolHive broker behavior.
mecated mcp add,login,status, andremovelifecycle commands with a shared selected-profile/config-resolution path.Acceptance / verification
mecated mcp add <URL>instead of hand-written settings.yaml #1613.task lint✅task docs✅task api:check✅go run ./cmd/mecademo✅Baseline gate exceptions
task testis blocked by a pre-existing intermittent test synchronization race ininternal/adapter/osfs/managed_temp_scenario_unix_test.go(TestADR_0281_ForegroundLeaseOverlayAndMetadataPrivacy), unrelated to this change.task ac-trace-strictis 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.