MCP OAuth discovery requests have no per-request timeout

Open Beginner friendly
#30,412 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript
Domain
cli

Research direction

Start with the three unbounded fetch calls: fetchProtectedResourceMetadata and fetchAuthorizationServerMetadata in packages/core/src/mcp/oauth-utils.ts, and the WWW-Authenticate probe in packages/core/src/mcp/oauth-provider.ts. Compare them with the HEAD probe in packages/core/src/tools/mcp-client.ts, which already passes signal: AbortSignal.timeout(5000). Add a similar signal to each call and assert it in oauth-utils.test.ts, where fetch is mocked. Done when every discovery request has a bounded timeout and the tests check that the signal is passed.

Written by the indexing model from the issue text.

Description

status/need-triage
What happened?

The MCP OAuth discovery requests have no per-request deadline. OAuthUtils.fetchProtectedResourceMetadata and OAuthUtils.fetchAuthorizationServerMetadata call fetch(validatedUrl) with no signal:

and the WWW-Authenticate probe in MCPOAuthProvider does the same:

The only bound left is the global undici dispatcher from packages/core/src/utils/fetch.ts (60 s headers timeout, 5 min body timeout). Discovery runs these requests one after another: the protected resource metadata (path-based, then root-based), then up to five authorization server well-known endpoints in discoverAuthorizationServerMetadata. Every URL comes from the MCP server or its metadata. If that host accepts the connection and never answers, OAuth setup for that server waits up to 60 s per URL before moving on, so several minutes in the worst case, before it reports anything.

The HEAD probe in mcp-client.ts already uses signal: AbortSignal.timeout(5000) for the same kind of request (https://github.com/google-gemini/gemini-cli/blob/eecccfcd5aff25de5e78135ca20f7abe3f566955/packages/core/src/tools/mcp-client.ts#L2048-L2054), so the OAuth path looks like it was missed rather than intentionally unbounded.

What did you expect to happen?

Each discovery request fails fast (a few seconds, like the probe in mcp-client.ts) and discovery moves on to the next well-known URL or reports that OAuth discovery failed.

Client information

Found by reading main at eecccfcd5aff25de5e78135ca20f7abe3f566955. Not reproduced against a live server yet; it can be reproduced with an MCP server URL that answers 401 with a WWW-Authenticate: Bearer resource_metadata="..." header whose metadata URL points at a host that accepts the connection and never responds.

Login information

Not relevant (MCP server OAuth, not Gemini login).

Anything else we need to know?

Adding signal: AbortSignal.timeout(...) to the three calls above is the minimal fix, and the existing tests in oauth-utils.test.ts mock fetch, so the signal can be asserted there. I'm happy to send a PR for this once the issue is triaged.

Dominant language
TypeScript
Stars
109k
Forks
15k
Avg merge
1d 1h
Merged PRs (30d)
106

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from google-gemini/gemini-cli

All issues in google-gemini/gemini-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.