Skip to content

Oath MCP always using root level even though my rul is .../xmcp/mcp #7135

Closed

Description

@adiberk

Description

My mcp url is /xmcp/mcp. This works fine for claude code and cursor.
However I think opencode is tyring to authenticate with mcp using root urls only. What do I need to change to fix?

AI informs me opencode may not be using the authroization information?

Here is my authorization resource endpoint:

curl -s http://localhost:8000/.well-known/oauth-protected-resource/xmcp/mcp
{"resource":"http://localhost:8000/xmcp/mcp","authorization_servers":["http://localhost:8000/xmcp"],"scopes_supported":["openid"],"bearer_methods_supported":["header"]}%  

here is authorization servers

curl -i http://localhost:8000/.well-known/oauth-authorization-server/xmcp
HTTP/1.1 200 OK
date: Tue, 06 Jan 2026 22:35:04 GMT
server: uvicorn
cache-control: public, max-age=3600
content-length: 633
content-type: application/json

{"issuer":"http://localhost:8000/xmcp","authorization_endpoint":"http://localhost:8000/xmcp/authorize","token_endpoint":"http://localhost:8000/xmcp/token","registration_endpoint":"http://localhost:8000/xmcp/register","scopes_supported":["openid"],"response_types_supported":["code"],"grant_types_supported":["authorization_code","refresh_token"],"token_endpoint_auth_methods_supported":["client_secret_post","client_secret_basic"],"revocation_endpoint":"http://localhost:8000/xmcp/revoke","revocation_endpoint_auth_methods_supported":["client_secret_post","client_secret_basic"],"code_challenge_methods_supported":["S256"]}%   

Here is my configuration

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "levmcp": {
      "type": "remote",
      "url": "http://localhost:8000/xmcp/mcp"
    },
  }
}

Here are requests being made by opencode

INFO [01/06/26 22:43:57] 172.66.0.243:42116 - "POST /xmcp/mcp HTTP/1.1" 401
[01/06/26 22:43:57] INFO     Auth error returned: invalid_token middleware.py:92
                             (status=401)                                       
INFO [01/06/26 22:43:57] 172.66.0.243:42116 - "GET 
/.well-known/oauth-protected-resource/xmcp/mcp HTTP/1.1" 200
INFO [01/06/26 22:43:57] 172.66.0.243:42116 - "GET 
/.well-known/oauth-authorization-server/xmcp/mcp HTTP/1.1" 404
INFO [01/06/26 22:43:57] 172.66.0.243:33885 - "GET 
/.well-known/oauth-authorization-server HTTP/1.1" 404
INFO [01/06/26 22:43:57] 172.66.0.243:42116 - "POST /register HTTP/1.1" 404

Plugins

mcp

OpenCode version

latest

Steps to reproduce

Use fastmcp app
Set mcp to mcp.http_app("/mcp", stateless_http=True)
Then mount to existing app at "/xmcp"

This will give you the configuration you need. It works for claude code just fine

Screenshot and/or share link

No response

Operating System

Mac OS

Terminal

warp

Activity

  1. jodem commented on Mar 18, 2026

    @jodem

    I have the same issue, my mcp is in localhost, and the auth server is on a different public url. Opencode call /authorize on the mcp url instead of using the WWW-Authenticate ressource_metadata. A hack to make it work is to do a redirect on your mcp for /authorize and a PROXY for /token (you proxy the token request to your actual oauth server, and respond back to opencode).If you are using a reverse proxy type kong or traefik you could play also on the ingress routes to redirect any /authorize or /proxy to your auth server.

    But I agree this is a mis implementation of how Oauth is supposed to work

  2. jodem commented on Mar 18, 2026

    @jodem

    Erratum actually it's working well. On the MCP endpoint, www-authenticate header should point to his own ressource .well-known/oauth-protected-resource so that opencode can fetch it and discover the actual Oauth server

    Expected response format of your own .well-known/oauth-protected-resource/<mcp_path>

    {
      "resource": "https://<your-mcp>/<mcp_path>",
      "authorization_servers": [
        "https://l<your-oauth2-server>"
      ],
      "scopes_supported": [
        "your mcp scope mcp"
      ],
      "resource_name": "whaterver"
    }
    

    then opencode calls https://.well-known/oauth-authorization-server and discovers authorization_endpoint, token_endpoint, etc

  3. removed
    bugSomething isn't working
    on May 3, 2026
  4. rekram1-node commented on Jun 24, 2026

    @rekram1-node
    Collaborator

    Closing as fixed by the current MCP SDK discovery behavior. SDK 1.29 performs path-aware RFC 9728 and RFC 8414/OIDC discovery, including /.well-known/oauth-protected-resource/<mcp-path> and path-aware authorization-server metadata lookup. As noted in the thread, the MCP WWW-Authenticate response must point to its protected-resource metadata document.

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