mcp-context-forge icon indicating copy to clipboard operation
mcp-context-forge copied to clipboard

[FEATURE][AUTH]: OAuth 2.0 authentication for MCP clients with browser-based SSO

Open AmshegaR opened this issue 10 months ago • 6 comments

I want MCP clients (like Claude Code) to authenticate to Context Forge Virtual Servers using OAuth 2.0 with browser-based IDP SSO, instead of pre-generated JWT bearer tokens.

I've reviewed the docs on [OAuth 2.0 Integration](https://ibm.github.io/mcp-context-forge/manage/oauth), [SSO](https://ibm.github.io/mcp-context-forge/manage/sso), and [DCR](https://ibm.github.io/mcp-context-forge/manage/dcr), but couldn't figure out how to configure this. The OAuth docs cover gateway-to-backend auth, and SSO appears to be for Admin UI only.

Claude Code → Context Forge (401 + discovery) → Browser → IDP → Token → Context Forge

Per the [MCP Authorization spec](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization), this requires RFC 9728 Protected Resource Metadata (/.well-known/oauth-protected-resource).

Is this currently possible? If so, how?

AmshegaR avatar Jan 10 '26 16:01 AmshegaR

Thank you for the detailed question and for referencing the relevant specs.

Short answer: This is not currently supported. MCP clients accessing Virtual Servers must authenticate using pre-generated JWT tokens, Basic Auth, or session cookies—there is no browser-based OAuth flow for MCP client authentication to the gateway itself.

Current State

Context Forge has two OAuth-related capabilities, but neither addresses your use case:

  1. Gateway-to-Upstream OAuth — When Context Forge connects to upstream MCP servers that require OAuth, it supports Authorization Code, Client Credentials, and PKCE flows. This is documented in the OAuth 2.0 Integration docs you reviewed.

  2. Admin UI SSO — OIDC/OAuth2 providers (GitHub, Google, Okta, Keycloak, etc.) can authenticate users to the Admin UI. This is the SSO feature—but it's scoped to the web UI, not MCP protocol clients.

What's Missing for Your Use Case

To support the MCP Authorization spec flow you described:

MCP Client → Gateway (401 + discovery) → Browser → IDP → Token → Gateway

We will need to implement:

  • /.well-known/oauth-protected-resource (RFC 9728 Protected Resource Metadata)
  • 401 responses with WWW-Authenticate headers containing authorization server discovery info
  • Client-facing OAuth authorization/token endpoints (separate from gateway-to-server OAuth)

Current Workaround

For now, you can:

  1. Generate a JWT token using python -m mcpgateway.utils.create_jwt_token
  2. Configure your MCP client to include the token in the Authorization: Bearer header

Next Steps

We're converting this to a feature request and targeting it for 1.0.0-BETA2. Implementation would involve adding RFC 9728 support to enable MCP Authorization spec compliance for client authentication. Our current target date for 1.0.0-BETA2 is 20 January. Watch this issue if you want to catch the feature when it's available in the main branch.

jonpspri avatar Jan 11 '26 10:01 jonpspri

@AmshegaR Please take a look at https://github.com/IBM/mcp-context-forge/pull/2029 to see if it works for you. We've unit tested but not performed full integration tests.

jonpspri avatar Jan 11 '26 13:01 jonpspri

Tested with Microsoft Entra ID and Claude Code, but I'm not sure I understand how it's supposed to function. @jonpspri Could you please clarify?

curl -X 'POST' \
  'http://localhost:4444/servers' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
  -d '{
  "server": {
    "id": "",
    "name": "test-oauth-vrt",
    "description": "Test OAuth server",
    "icon": "",
    "tags": ["test"],
    "associated_tools": [
      "43bc3122d8094f47904b2fc64ada9f42"
    ],
    "associated_resources": [],
    "associated_prompts": [],
    "associated_a2a_agents": [],
    "team_id": "5f6e89aa0eff410d948e8fbcfb211185",
    "owner_email": "[email protected]",
    "visibility": "public",
    "oauth_enabled": true,
    "oauth_config": {
      "provider": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
      "scopes": ["openid", "profile", "email"]
    }
  },
  "team_id": "5f6e89aa0eff410d948e8fbcfb211185",
  "visibility": "public"
}'

curl -X 'GET' \
  'http://localhost:4444/servers' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN"
  
 [
  {
    "id": "82594d6b88be4e21a0ab97fe5c44e23a",
    "name": "test-oauth-vrt",
    "description": "Test OAuth server",
    "icon": "",
    "createdAt": "2026-01-12T12:02:51.614077",
    "updatedAt": "2026-01-12T12:02:51.614085",
    "enabled": true,
    "associatedTools": [
      "aws-knowledge-aws-list-regions"
    ],
    "associatedResources": [],
    "associatedPrompts": [],
    "associatedA2aAgents": [],
    "metrics": null,
    "tags": [
      {
        "id": "test",
        "label": "test"
      }
    ],
    "createdBy": "[email protected]",
    "createdFromIp": "127.0.0.1",
    "createdVia": "api",
    "createdUserAgent": "curl/8.16.0",
    "modifiedBy": null,
    "modifiedFromIp": null,
    "modifiedVia": null,
    "modifiedUserAgent": null,
    "importBatchId": null,
    "federationSource": null,
    "version": 1,
    "teamId": "5f6e89aa0eff410d948e8fbcfb211185",
    "team": "Harry Hart's Team",
    "ownerEmail": "[email protected]",
    "visibility": "public",
    "oauthEnabled": true,
    "oauthConfig": {
      "provider": "https://login.microsoftonline.com/common/oauth2/v2.0/token",
      "scopes": [
        "openid",
        "profile",
        "email"
      ]
    }
  }
]


claude --version
2.1.2 (Claude Code)

claude mcp add -s project -t http test-oauth-vrt http://localhost:4444/servers/82594d6b88be4e21a0ab97fe5c44e23a/mcp

 Test-oauth-vrt MCP Server                                                                                                       

Status: failed                                                                                                                
Auth: not authenticated                                                                                                       
URL: http://localhost:4444/servers/82594d6b88be4e21a0ab97fe5c44e23a/mcp                                                         
Config location: C:\temp\.mcp.json                                                                                              

Error: HTTP 404: Invalid OAuth error response: ZodError: [                                                                      
  {                                                                                                                             
    "expected": "string",                                                                                                       
    "code": "invalid_type",                                                                                                     
    "path": [                                                                                                                   
      "error"                                                                                                                   
    ],                                                                                                                          
    "message": "Invalid input: expected string, received undefined"                                                             
  }                                                                                                                             
]. Raw body: {"detail":"Not Found"}                                                                                             


curl http://localhost:4444/.well-known/oauth-protected-resource/82594d6b88be4e21a0ab97fe5c44e23a

{ "detail": "Not found" }

curl http://localhost:4444/.well-known/oauth-protected-resource/test-oauth-vrt

{ "detail": "Not found" }

curl http://localhost:4444/.well-known/oauth-protected-resource?server_id=82594d6b88be4e21a0ab97fe5c44e23a

{
  "detail": "OAuth authorization_server not configured"
}

AmshegaR avatar Jan 12 '26 12:01 AmshegaR

There's a gap in the implementation on which I'm working, but even once it's filled it will be necessary to configure an external proxy to re-route named traffic appropriately. For example 'https://my-virtual-server.example.com/.well-known/foo' gets routed to 'https://mcpgateway.example.com/servers/{server_id}/.well-known/foo'. That's necessary to meet the requirements of RFC 9728 without polluting the mcpgateway server's root namespace with virual server details. I'd rather that configuration happen as automation outside of MCP Gateway, so I'm not going to try to code it in here.

(You production ship becomes "Make API call to MCP Gateway to configure server; Make API call to proxy server to add virtual name; Make API call to DNS to register virtual name to proxy IP")

jonpspri avatar Jan 12 '26 17:01 jonpspri

Tested once again, probably did something incorrect... however, it's not working as Claude tries to DCR :(


# Create Virtual Server with oauth_config
curl -X 'POST' \
  'http://localhost:4444/servers' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $env:MCPGATEWAY_BEARER_TOKEN" \
  -d '{
  "server": {
    "name": "test-oauth-vrt",
    "description": "Test OAuth server",
    "tags": ["test"],
    "associated_tools": ["d5bd9c4455c74cb0a6737f1704022eb7"],
    "associated_resources": [],
    "associated_prompts": [],
    "team_id": "a9fbf6a2b10b43bf9d134f55aa305334",
    "owner_email": "[email protected]",
    "visibility": "public",
    "oauth_enabled": true,
    "oauth_config": {
      "authorization_servers": ["https://login.microsoftonline.com/common/v2.0"],
      "scopes_supported": ["openid", "profile", "email"]
    }
  }
}'

# Creation response: 
{
    "id": "1c906413a171466ea749bd648f8148d6",
    "name": "test-oauth-vrt",
    "description": "Test OAuth server",
    "icon": null,
    "createdAt": "2026-01-13T10:02:56.780268",
    "updatedAt": "2026-01-13T10:02:56.780269",
    "enabled": true,
    "associatedTools": [
        "aws-knowledge-remote-aws-list-regions"
    ],
    "associatedResources": [],
    "associatedPrompts": [],
    "associatedA2aAgents": [],
    "metrics": null,
    "tags": [
        {
            "id": "test",
            "label": "test"
        }
    ],
    "createdBy": "[email protected]",
    "createdFromIp": "127.0.0.1",
    "createdVia": "api",
    "createdUserAgent": "curl/8.16.0",
    "modifiedBy": null,
    "modifiedFromIp": null,
    "modifiedVia": null,
    "modifiedUserAgent": null,
    "importBatchId": null,
    "federationSource": null,
    "version": 1,
    "teamId": "a9fbf6a2b10b43bf9d134f55aa305334",
    "team": "Platform Administrator's Team",
    "ownerEmail": "[email protected]",
    "visibility": "public",
    "oauthEnabled": true,
    "oauthConfig": {
        "authorization_servers": [
            "https://login.microsoftonline.com/common/v2.0"
        ],
        "scopes_supported": [
            "openid",
            "profile",
            "email"
        ]
    }
}

# List Virtual Server
curl -X 'GET' \
  'http://localhost:4444/servers' \
  -H 'accept: application/json' \
  -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN"
  
# Response oauthEnabled true
[
  {
    "id": "1c906413a171466ea749bd648f8148d6",
    "name": "test-oauth-vrt",
    "description": "Test OAuth server",
    "icon": null,
    "createdAt": "2026-01-13T10:02:56.780268",
    "updatedAt": "2026-01-13T10:02:56.780269",
    "enabled": true,
    "associatedTools": [
      "aws-knowledge-remote-aws-list-regions"
    ],
    "associatedResources": [],
    "associatedPrompts": [],
    "associatedA2aAgents": [],
    "metrics": null,
    "tags": [
      {
        "id": "test",
        "label": "test"
      }
    ],
    "createdBy": "[email protected]",
    "createdFromIp": "127.0.0.1",
    "createdVia": "api",
    "createdUserAgent": "curl/8.16.0",
    "modifiedBy": null,
    "modifiedFromIp": null,
    "modifiedVia": null,
    "modifiedUserAgent": null,
    "importBatchId": null,
    "federationSource": null,
    "version": 1,
    "teamId": "a9fbf6a2b10b43bf9d134f55aa305334",
    "team": "Platform Administrator's Team",
    "ownerEmail": "[email protected]",
    "visibility": "public",
    "oauthEnabled": true,
    "oauthConfig": {
      "authorization_servers": [
        "https://login.microsoftonline.com/common/v2.0"
      ],
      "scopes_supported": [
        "openid",
        "profile",
        "email"
      ]
    }
  }
]

# Test the well-known endpoint
curl -s "http://localhost:4444/.well-known/oauth-protected-resource?server_id=1c906413a171466ea749bd648f8148d6"

# Respose RFC 9728 endpoint is working
{
  "resource": "http://localhost:4444/servers/1c906413a171466ea749bd648f8148d6",
  "authorization_servers": [
    "https://login.microsoftonline.com/common/v2.0"
  ],
  "bearer_methods_supported": [
    "header"
  ],
  "scopes_supported": [
    "openid",
    "profile",
    "email"
  ]
}

# Test path-based endpoint
curl -s "http://localhost:4444/servers/1c906413a171466ea749bd648f8148d6/.well-known/oauth-protected-resource" | jq

{
  "resource": "http://localhost:4444/servers/1c906413a171466ea749bd648f8148d6",
  "authorization_servers": [
    "https://login.microsoftonline.com/common/v2.0"
  ],
  "bearer_methods_supported": [
    "header"
  ],
  "scopes_supported": [
    "openid",
    "profile",
    "email"
  ]
}

# Test with claude Code
claude mcp add -s project -t http test-oauth-vrt http://localhost:4444/servers/1c906413a171466ea749bd648f8148d6/mcp

	Test-oauth-vrt MCP Server    
	Status: ✘ failed             
	Auth: ✘ not authenticated    
	URL: http://localhost:4444/servers/1c906413a171466ea749bd648f8148d6/mcp                                                                                     
	Config location: C:\temp\.mcp.json   
	Error: HTTP 404: Invalid OAuth error response: ZodError: [                                                                                                  
	  {                          
		"expected": "string",    
		"code": "invalid_type",  
		"path": [                
		  "error"                
		],                       
		"message": "Invalid input: expected string, received undefined"                                                                                         
	  }                          
	]. Raw body: {"detail":"Not Found"}


# Test the MCP endpoint directly
curl -sI "http://localhost:4444/servers/1c906413a171466ea749bd648f8148d6/mcp"

# Respose 
HTTP/1.1 401 Unauthorized
date: Tue, 13 Jan 2026 10:16:12 GMT
server: uvicorn
www-authenticate: Bearer
content-length: 34
content-type: application/json
x-correlation-id: a60f3ff976a647a5bb54376903c0e29a

! per RFC 9728, it should be: !
www-authenticate: Bearer resource_metadata="http://localhost:4444/servers/1c906413a171466ea749bd648f8148d6/.well-known/oauth-protected-resource"


# Config HOSTS file for routing test
127.0.0.1 my-virtual-server.local

# Caddyfile for testing
http://my-virtual-server.local {
    handle /.well-known/oauth-protected-resource {
        header Content-Type application/json
        respond \{"resource":"http://my-virtual-server.local/mcp","authorization_servers":["https://login.microsoftonline.com/common/v2.0"],"bearer_methods_supported":["header"],"scopes_supported":["openid","profile","email"]}\ 200
    }

    handle /mcp* {
        rewrite * /servers/1c906413a171466ea749bd648f8148d6/mcp
        reverse_proxy localhost:4444 {
            @unauthorized status 401
            handle_response @unauthorized {
                header >WWW-Authenticate \Bearer resource_metadata="http://my-virtual-server.local/.well-known/oauth-protected-resource"\
                copy_response
            }
        }
    }

    handle {
        respond "Not found" 404
    }
}

# Test Claude with the proxy
claude mcp add -s project -t http test-oauth-vrt http://my-virtual-server.local/mcp

 Test-oauth-vrt MCP Server 
 
 Status: ✘ failed
 Auth: ✘ not authenticated 
 URL: http://my-virtual-server.local/mcp 
 Config location: C:\temp\.mcp.json
 
 Error: Incompatible auth server: does not support dynamic client registration

AmshegaR avatar Jan 13 '26 13:01 AmshegaR

@AmshegaR Sorry it took me a hot minute to get back on this. I'm going to push the work so far to a merge, then we can pick up the DCR issue with https://github.com/IBM/mcp-context-forge/issues/2148 I just created. Feel free to review and comment on that issue.

jonpspri avatar Jan 17 '26 11:01 jonpspri