Skip to content

MCP OAuth scope from config is ignored for pre-registered remote servers #28895

Closed

Description

@hlsousa

Description

OpenCode appears to ignore oauth.scope for remote MCP servers that use a pre-registered OAuth client.

With a remote MCP config that includes both oauth.clientId and oauth.scope, running opencode mcp auth <name> generates an OAuth authorization URL that does not include a scope parameter.

At runtime, the client clearly reads oauth.clientId because it behaves as if dynamic registration is skipped, but oauth.scope is not propagated into the authorization request.

This causes standards-compliant OAuth providers to reject the flow because the request is missing the required scope.

Expected behavior:
OpenCode should include the configured oauth.scope in the generated authorization URL and use it consistently throughout the OAuth flow for pre-registered remote MCP servers.

Additional note:
Manual token injection into the local OpenCode MCP auth cache allows the MCP server to work afterward, which suggests the failure is in OpenCode's OAuth flow rather than in general MCP connectivity.

Plugins

No response

OpenCode version

No response

Steps to reproduce

  1. Configure any OAuth-protected remote MCP server with:
    • type: "remote"
    • url: "<oauth-protected-mcp-endpoint>"
    • oauth.clientId
    • oauth.scope
  2. Run opencode mcp auth <name>
  3. Inspect the generated authorization URL or runtime logs
  4. Observe that the URL includes parameters such as response_type, client_id, code_challenge, redirect_uri, and state, but does not include scope
  5. Complete the provider login and observe that the OAuth provider rejects the flow because scope is missing

Screenshot and/or share link

No response

Operating System

Linux

Terminal

Alacritty

Activity

  1. github-actions commented on May 22, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. lexlian commented on May 28, 2026

    @lexlian

    I created a fix in PR #29219 . When running opencode mcp auth <name> for a remote MCP server with a pre-registered OAuth client (oauth.clientId + oauth.scope), the generated authorization URL was missing the scope parameter. This is because the current @modelcontextprotocol/sdk v1.27.1 doesn't fall back to clientMetadata.scope when building the auth URL for pre-registered clients — the scope only appears in the WWW-Authenticate header, Protected Resource Metadata (PRM) scopes_supported, or in SDK v2+.

    The fix augments the authorization URL in McpOAuthProvider.redirectToAuthorization before the redirect callback fires. A guard (!url.searchParams.has("scope")) ensures no duplication once the SDK is upgraded. This single change covers both the startAuth (CLI auth) and connectRemote (runtime connection) code paths since both use the same redirectToAuthorization method.

  3. added a commit that references this issue on Jun 1, 2026
    70eda0c
  4. rekram1-node commented on Jun 24, 2026

    @rekram1-node
    Contributor

    Closing as fixed and duplicate of #28811. The fix landed in #28810: OpenCode now includes the configured oauth.scope in MCP OAuth client metadata, and the current MCP SDK uses that scope when neither the challenge nor protected-resource metadata supplies one. The older redirect-time workaround in #29219 is therefore obsolete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions