Skip to content

fix(mcp): make OAuth server connections non-blocking at startup#2281

Merged
bug-ops merged 1 commit intomainfrom
2276-mcp-oauth-startup
Mar 27, 2026
Merged

fix(mcp): make OAuth server connections non-blocking at startup#2281
bug-ops merged 1 commit intomainfrom
2276-mcp-oauth-startup

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 27, 2026

Summary

  • Extract OAuth Phase 2 from connect_all() into connect_oauth_deferred() in crates/zeph-mcp/src/manager.rs
  • connect_all() now only connects non-OAuth servers (fast, no blocking)
  • connect_oauth_deferred() runs as a background task spawned in src/runner.rs after TUI/channel is initialised
  • Auto-opens browser via open::that_in_background() before awaiting callback
  • CLI fallback: eprintln prints auth URL when no status_tx is present
  • OAuth tools are published via tools_watch_tx on success — picked up automatically by the agent loop
  • Adds open = "5" workspace dependency for cross-platform browser launch

Fixes

Fixes #2276

Test plan

  • Agent starts immediately without freezing when OAuth MCP server is configured
  • Auth URL appears in TUI status bar after startup completes
  • Browser auto-opens with the OAuth authorization URL
  • After completing OAuth flow in browser, MCP tools become available in the agent
  • CLI mode: auth URL printed to stderr, browser opens
  • Non-OAuth MCP servers are unaffected
  • cargo clippy --workspace --features full -- -D warnings — clean
  • cargo nextest run --config-file .github/nextest.toml --workspace --features full --lib --bins — 6821 passed

OAuth MCP servers blocked agent startup for up to 300 s because
connect_all() awaited the OAuth callback before the TUI was ready,
causing the auth URL to never be displayed.

- Extract OAuth Phase 2 from connect_all() into connect_oauth_deferred()
- connect_all() now only connects non-OAuth servers (fast path)
- connect_oauth_deferred() runs as a background task after TUI/channel
  is initialised, auto-opens the browser via open::that_in_background(),
  awaits the callback, and publishes tools via tools_watch_tx
- Add has_oauth_servers() predicate on McpManager
- Add open = "5" workspace dependency for cross-platform browser launch
- CLI fallback: eprintln prints the auth URL when no status_tx present

Fixes #2276
@github-actions github-actions bot added rust Rust code changes dependencies Dependency updates bug Something isn't working size/M Medium PR (51-200 lines) labels Mar 27, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 27, 2026 21:29
@bug-ops bug-ops merged commit 2b4a0f4 into main Mar 27, 2026
25 checks passed
@bug-ops bug-ops deleted the 2276-mcp-oauth-startup branch March 27, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Dependency updates rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(mcp): OAuth server blocks agent startup and auth URL invisible in TUI

1 participant