fix(mcp): Include path in oauth resource parameter (#11654)

This commit is contained in:
Mayur Vaid
2025-10-22 21:18:47 +05:30
committed by GitHub
parent 73b1afb106
commit 0d7da7ecb1
2 changed files with 21 additions and 3 deletions

View File

@@ -297,14 +297,32 @@ describe('OAuthUtils', () => {
const result = OAuthUtils.buildResourceParameter(
'https://example.com/oauth/token',
);
expect(result).toBe('https://example.com');
expect(result).toBe('https://example.com/oauth/token');
});
it('should handle URLs with ports', () => {
const result = OAuthUtils.buildResourceParameter(
'https://example.com:8080/oauth/token',
);
expect(result).toBe('https://example.com:8080');
expect(result).toBe('https://example.com:8080/oauth/token');
});
it('should strip query parameters from the URL', () => {
const result = OAuthUtils.buildResourceParameter(
'https://example.com/api/v1/data?user=123&scope=read',
);
expect(result).toBe('https://example.com/api/v1/data');
});
it('should strip URL fragments from the URL', () => {
const result = OAuthUtils.buildResourceParameter(
'https://example.com/api/v1/data#section-one',
);
expect(result).toBe('https://example.com/api/v1/data');
});
it('should throw an error for invalid URLs', () => {
expect(() => OAuthUtils.buildResourceParameter('not-a-url')).toThrow();
});
});
});

View File

@@ -360,6 +360,6 @@ export class OAuthUtils {
*/
static buildResourceParameter(endpointUrl: string): string {
const url = new URL(endpointUrl);
return `${url.protocol}//${url.host}`;
return `${url.protocol}//${url.host}${url.pathname}`;
}
}