Fix MCP getPage tool returning page not found (#4166)

This commit is contained in:
Nolann B.
2026-04-08 14:28:39 +02:00
committed by GitHub
parent 569d4046be
commit 11df1fd395
2 changed files with 16 additions and 2 deletions
+13
View File
@@ -35,6 +35,19 @@ describe('extractPagePath', () => {
it('returns empty string for root URL', () => {
expect(extractPagePath('https://docs.example.com/api/', baseURL)).toBe('');
});
it('extracts path when base URL is at the root of the domain', () => {
expect(
extractPagePath(
'https://docs.example.com/merchant-account/user-management/sso',
'https://docs.example.com/'
)
).toBe('merchant-account/user-management/sso');
});
it('returns empty string when URL equals root base URL', () => {
expect(extractPagePath('https://docs.example.com/', 'https://docs.example.com/')).toBe('');
});
});
describe('resolveFirstDocument', () => {
+3 -2
View File
@@ -413,11 +413,12 @@ export function extractPagePath(url: string, baseURL: string): string | undefine
const urlPath = getURLPathname(url);
const basePath = getURLPathname(baseURL);
if (!urlPath || !basePath) {
if (urlPath === undefined || basePath === undefined) {
return undefined;
}
if (urlPath.startsWith(`${basePath}/`) || urlPath === basePath) {
// When basePath is empty, the site is at the root of the domain, so any path matches
if (basePath === '' || urlPath.startsWith(`${basePath}/`) || urlPath === basePath) {
return removeLeadingSlash(urlPath.slice(basePath.length));
}
}