Repository navigation
fix(mcp): keep the sign-in when a tool call is refused for scope - #7451
Merged
Merged
Conversation
A provider can refuse one tool call with 403 and an `insufficient_scope` challenge: the token is valid, but it lacks a scope that request needs. The client library treated that like a rejected token. The MCP SDK first tried to re-authorize or refresh, and then the saved sign-in was cleared and the member was asked to reconnect. Reconnecting requests the scopes the connection is configured with, so the next call was refused the same way and the sign-in was cleared again. On a shared connection that signed out everyone who used it. Outside a sign-in, the transport now reports the refusal instead of re-authorizing, so the call is sent once and nothing is refreshed, and an `insufficient_scope` 403 no longer clears the saved sign-in. A 401 `invalid_token`, and a 403 that challenges the token without naming a scope, still clear it. During a sign-in the SDK may still ask for wider scopes, as before. Den reports the refusal as what it is. The diagnostic carries the scope list the provider named, taken from the SDK's error and kept only when it is a short list of valid scope tokens. The message names it as provider-supplied text, and the action tells the member that an organization admin has to add the scope under Requested OAuth scopes and that signing in again without that change requests the same scopes. A tool call refused for scope is no longer reported as a failed sign-in, so no reconnect prompt is attached to it. The new test runs the real client against a stand-in provider, without a database, and is added to the security list so it runs on every PR. Signed-off-by: Jalil <reachjalil@gmail.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this about?
OAuth connections to provider MCP servers. When a provider refuses one tool call because the sign-in lacks a permission, OpenWork now keeps the sign-in and names the missing permission.
What problem does it solve?
People were signed out of a working connection and asked to reconnect, repeatedly. Reconnecting requests the same permissions, so it could not help. On a shared connection, one refused call signed out everyone.
What was the situation before?
A tool call answered with 403
insufficient_scopewas treated like a rejected token: the saved sign-in was cleared and the chat showed a reconnect prompt. After reconnecting, the same call failed the same way.How is this implemented?
packages/enterprise-mcp-client: outside a sign-in the transport reports the refusal (onInsufficientScope: "throw"), so the call is sent once with no refresh, and a 403insufficient_scopeno longer clears saved tokens. A 401invalid_tokenand a 403 that challenges the token itself still do.external-mcp-diagnostics.ts: the error names the scopes the provider asked for (only a short list of valid scope tokens, labelled as provider text) and says an organization admin must add them under Requested OAuth scopes.external-capabilities.ts: a tool call refused for scope is not reported as a failed sign-in, so no reconnect prompt is attached.What else changed?
test:api:securitylist, so it runs on every PR.Release note
A connection no longer asks you to sign in again when the provider refuses a request for a missing permission; the error names the permission an admin needs to add.
Evidence
ee/apps/den-api/test/api/external-mcp-scope-refusal.api.test.ts— before: a tool call refused for scope clears the saved sign-in; after: the sign-in is kept, the call is sent once, and the error names the scope. No E2E; no screen changed.