Skip to content

fix(mcp): keep the sign-in when a tool call is refused for scope - #7451

Merged
reachjalil merged 1 commit into
devfrom
fix/mcp-scope-refusal-keeps-sign-in
Nov 16, 2026
Merged

reachjalil merged 1 commit into
devfrom
fix/mcp-scope-refusal-keeps-sign-in

Conversation

@reachjalil

Copy link
Copy Markdown
Member

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_scope was 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 403 insufficient_scope no longer clears saved tokens. A 401 invalid_token and 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?

  • The new test joins the Den API test:api:security list, 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.

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>
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-den Ready Ready Preview Nov 16, 2026 11:00pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
openwork-app Skipped Skipped Nov 16, 2026 11:00pm UTC
openwork-landing Skipped Skipped v0 Nov 16, 2026 11:00pm UTC

Request Review

@vercel
vercel Bot temporarily deployed to Preview – openwork-app November 16, 2026 22:59 Inactive
@vercel
vercel Bot temporarily deployed to Preview – openwork-landing November 16, 2026 22:59 Inactive
@reachjalil
reachjalil merged commit af32cd7 into dev Nov 16, 2026
19 checks passed

This branch was successfully deployed

1 active and 2 inactive deployments
Preview – openwork-den — 6a8f6b38 Deployed Nov 16, 2026 by vercel[bot]
Preview – openwork-app — 6a8f6b38 Deployed Nov 16, 2026 by vercel[bot]
Preview – openwork-landing — 6a8f6b38 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant