Skip to content

Raise HTTP 403 with insufficient_scope instead of tool/prompt not found on scope failure#65

Merged
yeison-liscano merged 3 commits intomainfrom
copilot/understanding-mcp-auth-package
Mar 18, 2026
Merged

Raise HTTP 403 with insufficient_scope instead of tool/prompt not found on scope failure#65
yeison-liscano merged 3 commits intomainfrom
copilot/understanding-mcp-auth-package

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

When an authenticated request lacks the required OAuth scopes, the server was returning a JSON-RPC RESOURCE_NOT_FOUND error ("Tool X not found"). This prevents MCP clients from distinguishing a missing resource from an authorization failure and blocks the OAuth 2.1 step-up flow.

Changes

  • InsufficientScopeError — new exception (not a ServerError subclass) carrying required_scopes; propagates through the transport layer rather than being swallowed as a JSON-RPC error
  • server.pycall_tool / get_prompt now raise InsufficientScopeError instead of ToolNotFoundError/PromptNotFoundError when the resource exists but scope check fails
  • _transport_http.py — catches InsufficientScopeError in _process_messages and sends HTTP 403 Forbidden with {"error":"insufficient_scope"}; AuthErrorMiddleware then adds the WWW-Authenticate header
  • _stdio_transport.py — catches InsufficientScopeError and falls back to a JSON-RPC RESOURCE_NOT_FOUND error with required scopes in the description (STDIO doesn't use OAuth per the MCP spec)
  • middleware.pyAuthErrorMiddleware now sets error="insufficient_scope" in WWW-Authenticate on 403 responses (was null previously), satisfying RFC 6750

Before / After

# Before: authenticated user, missing scope → 200 with JSON-RPC error
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32002, "message": "Tool private_tool not found"}}

# After: 403 Forbidden
{"error": "insufficient_scope"}
# WWW-Authenticate: ******"insufficient_scope", resource_metadata="..."

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.astral.sh
    • Triggering command: /home/REDACTED/.local/bin/uv uv sync (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…cope is insufficient

Co-authored-by: yeison-liscano <104051061+yeison-liscano@users.noreply.github.com>
Copilot AI changed the title [WIP] Add documentation on how mcp_auth package works Raise HTTP 403 with insufficient_scope instead of tool/prompt not found on scope failure Mar 17, 2026
Copilot AI requested a review from yeison-liscano March 17, 2026 15:53
@yeison-liscano yeison-liscano marked this pull request as ready for review March 18, 2026 03:34
@yeison-liscano yeison-liscano merged commit 35023cd into main Mar 18, 2026
4 checks passed
@yeison-liscano yeison-liscano deleted the copilot/understanding-mcp-auth-package branch March 18, 2026 03:34
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.

2 participants