github / github/copilot-cli

MCP Oauth fails when the server metadata URL is redirected

Open
#4,769 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:authentication area:mcp
Dominant language
Shell
Stars
11.2k
Forks
1.9k
Avg merge
14h 16m
Merged PRs (30d)
6

Description

Describe the bug

When the .well-known/openid-configuration is behind an http redirect, authentication fails with:

Authentication failed: MCPOAuthError: Incompatible authorization server: authorization server advertised an issuer that does not match the URL its metadata was discovered from (RFC 8414 §3.3); refusing to connect

I believe that copilot-cli checks the issuer against the original URL instead of the redirected URL. Note that RFC 8414 states that the issuer must match "the URL used to retrieve the metadata," which strictly speaking is the redirection target, not the source.

Affected version

GitHub Copilot CLI 1.0.83.

Steps to reproduce the behavior
  1. Run an MCP server on a different server from its OAuth authorization server, e.g. https://my.mcp.server vs https://my.oauth.server
  2. Configure the MCP server so that https://my.mcp.server/.well-known/openid-configuration returns an HTTP 301 redirect to https://my.oauth.server/.well-known/openid-configuration
  3. Configure the OAuth server so that https://my.oauth.server/.well-known/openid-configuration specifies https://my.oauth.server as the issuer
  4. In copilot-cli, type /mcp add FooBar, select type HTTP, remote server URL https://my.mcp.server, and the client ID when asked
Expected behavior

Copilot should ask to authenticate, then open the authentication URL in my browser (or display the authentication code and URL so that I can copy-paste them in my browser), then complete the authentication flow.

Additional context

This may be related to #4480 except that in #4480, the Atlassian MCP server gave the wrong issuer, whereas here the issuer is correct for the real URL and copilot-cli is checking against the wrong URL.

Contributor guide

Open the contributing guide

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.

Research direction

Reproduce the failure by making the MCP server's .well-known/openid-configuration return a 301 redirect, then trace the issuer validation used by the /mcp add HTTP flow. Done means metadata from the redirected URL is accepted when its issuer matches that final URL, and authentication proceeds to the browser or displayed authorization code.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
authentication, cli, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.