From 0d7da7ecb184e38c6525909c67c56552b13fbf92 Mon Sep 17 00:00:00 2001 From: Mayur Vaid <34806097+MayV@users.noreply.github.com> Date: Wed, 22 Oct 2025 21:18:47 +0530 Subject: [PATCH] fix(mcp): Include path in oauth resource parameter (#11654) --- packages/core/src/mcp/oauth-utils.test.ts | 22 ++++++++++++++++++++-- packages/core/src/mcp/oauth-utils.ts | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/core/src/mcp/oauth-utils.test.ts b/packages/core/src/mcp/oauth-utils.test.ts index 710afe21aa..93aa507e21 100644 --- a/packages/core/src/mcp/oauth-utils.test.ts +++ b/packages/core/src/mcp/oauth-utils.test.ts @@ -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(); }); }); }); diff --git a/packages/core/src/mcp/oauth-utils.ts b/packages/core/src/mcp/oauth-utils.ts index 4787422f52..cf6bfc289d 100644 --- a/packages/core/src/mcp/oauth-utils.ts +++ b/packages/core/src/mcp/oauth-utils.ts @@ -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}`; } }