feat: resolve virtual servers by name in RFC 9728 well-known and MCP endpoints#4237
Open
feat: resolve virtual servers by name in RFC 9728 well-known and MCP endpoints#4237
Conversation
…endpoints The well-known OAuth Protected Resource endpoint (RFC 9728) only accepted UUID server identifiers, forcing clients to use opaque hex strings in URLs. This adds server name resolution as a fallback while keeping full UUID backward compatibility. Changes: - well_known.py: accept server name in addition to UUID, resolve to canonical UUID for the resource URL (RFC 9728 stability) - server_service.py: add resolve_server_id() that tries PK lookup first, then falls back to name lookup - streamablehttp_transport.py: use resolve_server_id() in _validate_server_id and _check_server_oauth_enforcement for consistent name support - Update tests to reflect name resolution behavior Security: server name input is validated against a strict alphanumeric pattern (SERVER_NAME_PATTERN) to prevent path traversal and injection. Signed-off-by: Sébastien MORAND <sebastien.morand@ibm.com>
f0beca5 to
702aaec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/.well-known/oauth-protected-resourceendpoint only accepted UUID server identifiers, requiring clients to use opaque hex strings likeb1a1acaa408744919481e10fca4ce9f2in URLs/servers/gdrive/mcpwhile keeping full UUID backward compatibilityresourceURL in the well-known response always uses the canonical UUID, ensuring stable resource identifiers per RFC 9728Changes
mcpgateway/routers/well_known.py: accept server name (validated againstSERVER_NAME_PATTERN) in addition to UUID, resolve to canonical UUID via DB lookupmcpgateway/services/server_service.py: addresolve_server_id()method that tries PK lookup first, then falls back to name lookupmcpgateway/transports/streamablehttp_transport.py: useresolve_server_id()in_validate_server_idand_check_server_oauth_enforcementfor consistent name support across MCP transport layertests/unit/mcpgateway/routers/test_well_known_rfc9728.py: update test expectations to reflect name resolution behaviorSecurity
Server name input is validated against a strict alphanumeric pattern (
^[a-zA-Z0-9][a-zA-Z0-9_-]{0,253}[a-zA-Z0-9]$) to prevent path traversal and injection. Path traversal attempts like/../adminare rejected before any DB lookup.Test plan
/servers/{name}/mcpreturns correct 401 + WWW-Authenticate