Skip to content

fix(mcp): force OAuth login for preregistered clients - #37840

Open
zapabob wants to merge 1 commit into
NousResearch:mainfrom
zapabob:codex/fix-mcp-preregistered-oauth-login
Open

fix(mcp): force OAuth login for preregistered clients#37840
zapabob wants to merge 1 commit into
NousResearch:mainfrom
zapabob:codex/fix-mcp-preregistered-oauth-login

Conversation

@zapabob

@zapabob zapabob commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add an explicit OAuth login path for pre-registered MCP clients so hermes mcp login does not depend on the server first returning HTTP 401.
  • Preserve the existing lazy 401-driven flow for servers without pre-registered client metadata.
  • Add regression coverage for Google Drive-style MCP servers that can list tools without an auth challenge.

Verification

  • uv run --extra dev python -m pytest tests/hermes_cli/test_mcp_config.py tests/tools/test_mcp_oauth_manager.py -o addopts='' -> 43 passed
  • uv run ruff check hermes_cli/mcp_config.py tools/mcp_oauth_manager.py tests/hermes_cli/test_mcp_config.py tests/tools/test_mcp_oauth_manager.py -> passed
  • git diff --check -> passed

Duplicate check

Searched NousResearch/hermes-agent PRs for force oauth login preregistered clients and mcp oauth preregistered clients; no duplicate PR was found.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have tool/mcp MCP client and OAuth comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists labels Jun 3, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #35965 — same fix (force OAuth login for preregistered MCP clients). Consolidating on the earlier open PR.

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

Thanks for isolating the anonymous-tools/list OAuth failure. The premise remains present on current main: _reauth_oauth_server still expects _probe_single_server() to initiate OAuth and only detects the missing-token condition afterward (hermes_cli/mcp_config.py:787-815).

Problems

  • The added helper unconditionally calls _stop_mcp_loop() (hermes_cli/mcp_config.py:255 in this PR). Current main documents that temporary probes must use _stop_mcp_loop_if_idle() so they do not terminate active MCP sessions or orphan their children (tools/mcp_tool.py:5592-5626).
  • Current main routes login and both reauth forms through _reauth_oauth_server (hermes_cli/mcp_config.py:759,865,899,915). The explicit-login step should be integrated there, retaining the current 315-second interactive timeout floor (hermes_cli/mcp_config.py:787-802).

Suggested changes

  • Port the logic into the shared reauth helper, use idle-only loop cleanup, and cover both login and reauth --all.

Automated hermes-sweeper review.

Comment thread hermes_cli/mcp_config.py
)
)
finally:
_stop_mcp_loop()

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.

Use _stop_mcp_loop_if_idle() here. Current tools/mcp_tool.py:5592-5626 documents that unconditional shutdown can terminate active registered MCP servers and orphan their subprocesses; this helper is a temporary CLI flow and must not tear down a live shared loop.

Comment thread hermes_cli/mcp_config.py
# list tools unauthenticated, so no SDK auth flow is triggered otherwise.
try:
if _has_preregistered_oauth_client(server_config):
_force_oauth_login(name, server_config)

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.

Current main funnels login and both reauth forms through _reauth_oauth_server. Port this shared explicit-login step there during salvage so reauth --all receives the same behavior and the existing 315-second browser-flow timeout is preserved.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
teknium1 added a commit that referenced this pull request Jul 27, 2026
…s; add new overflow shapes

Port from anomalyco/opencode#37848 (+ dev-branch twin #37840): expand
context-overflow patterns and guard against rate-limit messages that
mention tokens.

- 'Throttling error: Too many tokens, please wait before trying again.'
  (AWS Bedrock / proxy shape) classified as context_overflow and routed a
  healthy session into compression on every throttle. Added 'throttling'
  to _RATE_LIMIT_PATTERNS, which the message-only path checks BEFORE the
  overflow list.
- 'Input length N exceeds the maximum allowed input length of M tokens.'
  (Together/Fireworks shape) fell through to unknown — no compression
  recovery. Added 'maximum allowed input length' to overflow patterns.
- 'request_too_large' / 'Request exceeds the maximum size' (Anthropic 413
  type re-wrapped without a status code by aggregators/proxies) fell
  through to unknown. Added to _PAYLOAD_TOO_LARGE_PATTERNS.

All three shapes proven live on main before the fix; 265 classifier +
bedrock tests and 238 sibling rate-guard/compression tests pass.
randlee pushed a commit to randlee/hermes-agent that referenced this pull request Aug 11, 2026
…s; add new overflow shapes

Port from anomalyco/opencode#37848 (+ dev-branch twin NousResearch#37840): expand
context-overflow patterns and guard against rate-limit messages that
mention tokens.

- 'Throttling error: Too many tokens, please wait before trying again.'
  (AWS Bedrock / proxy shape) classified as context_overflow and routed a
  healthy session into compression on every throttle. Added 'throttling'
  to _RATE_LIMIT_PATTERNS, which the message-only path checks BEFORE the
  overflow list.
- 'Input length N exceeds the maximum allowed input length of M tokens.'
  (Together/Fireworks shape) fell through to unknown — no compression
  recovery. Added 'maximum allowed input length' to overflow patterns.
- 'request_too_large' / 'Request exceeds the maximum size' (Anthropic 413
  type re-wrapped without a status code by aggregators/proxies) fell
  through to unknown. Added to _PAYLOAD_TOO_LARGE_PATTERNS.

All three shapes proven live on main before the fix; 265 classifier +
bedrock tests and 238 sibling rate-guard/compression tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants