mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-23 19:06:31 +00:00
Fix MCP getPage tool returning page not found (#4166)
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user