Skip to content

Commit 029bf69

Browse files
Fix MCP OAuth URL normalization - handle trailing slash and hostname case differences (microsoft#255415)
* Initial plan * Fix MCP OAuth URL normalization issue - normalize URLs before comparison Co-authored-by: TylerLeonhardt <[email protected]> * Remove unnecessary normalizeUrlForComparison function - URL constructor handles all normalization Co-authored-by: TylerLeonhardt <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: TylerLeonhardt <[email protected]>
1 parent 33a85fe commit 029bf69

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/vs/base/test/common/oauth.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,5 +749,11 @@ suite('OAuth', () => {
749749
const result = getResourceServerBaseUrlFromDiscoveryUrl(discoveryUrl);
750750
assert.strictEqual(result, 'https://example.com/api%20v1');
751751
});
752+
753+
test('should normalize hostname case consistently', () => {
754+
const discoveryUrl = 'https://MCP.EXAMPLE.COM/.well-known/oauth-protected-resource';
755+
const result = getResourceServerBaseUrlFromDiscoveryUrl(discoveryUrl);
756+
assert.strictEqual(result, 'https://mcp.example.com/');
757+
});
752758
});
753759
});

src/vs/workbench/api/common/extHostMcp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ class McpHTTPHandle extends Disposable {
392392
const body = await resourceMetadataResponse.json();
393393
if (isAuthorizationProtectedResourceMetadata(body)) {
394394
const resolvedResource = getResourceServerBaseUrlFromDiscoveryUrl(resourceMetadata);
395-
if (body.resource !== resolvedResource) {
395+
// Use URL constructor for normalization - it handles hostname case and trailing slashes
396+
if (new URL(body.resource).toString() !== new URL(resolvedResource).toString()) {
396397
throw new Error(`Protected Resource Metadata resource "${body.resource}" does not match MCP server resolved resource "${resolvedResource}". The MCP server must follow OAuth spec https://datatracker.ietf.org/doc/html/rfc9728#PRConfigurationValidation`);
397398
}
398399
return body;

0 commit comments

Comments
 (0)