Show MCP page actions for VA & adaptive sites (#4268)

This commit is contained in:
spastorelli
2026-05-22 08:47:13 +02:00
committed by GitHub
parent 0b38f6c93b
commit 287203d197
3 changed files with 28 additions and 4 deletions
@@ -166,9 +166,21 @@ function getPageActionsURLs({
}).toString()}`
)
: undefined,
mcp:
context.site.visibility !== SiteVisibility.VisitorAuth
? context.linker.toAbsoluteURL(context.linker.toPathInSite('~gitbook/mcp'))
: undefined,
mcp: getPageActionsMCPURL(context),
};
}
/**
* Return the MCP URL to be used in the page actions dropdown.
*/
function getPageActionsMCPURL(context: GitBookSiteContext) {
const useAuthenticatedEndpoint = Boolean(
context.site.visibility !== SiteVisibility.VisitorAuth &&
context.site.adaptiveContent?.enabled &&
context.site.urls.login &&
context.isLoggedInVisitor
);
const endpoint = useAuthenticatedEndpoint ? '~gitbook/mcp/auth' : '~gitbook/mcp';
return context.linker.toAbsoluteURL(context.linker.toPathInSite(endpoint));
}
+11
View File
@@ -70,6 +70,11 @@ export type SiteURLData = Pick<
* Computed in middleware from GITBOOK_BLOCK_SEARCH_INDEXATION env var and x-gitbook-search-indexation header.
*/
noIndexSearch?: boolean;
/**
* Whether the request included a visitor token.
*/
isLoggedInVisitor?: boolean;
};
/**
@@ -164,6 +169,9 @@ export type GitBookSiteContext = GitBookSpaceContext & {
/** Whether search indexation is blocked for this deployment. */
noIndexSearch: boolean;
/** Whether the request included a visitor token. */
isLoggedInVisitor: boolean;
};
/**
@@ -244,6 +252,7 @@ export async function fetchSiteContextByURLLookup(
contextId: data.contextId,
isFallback: data.isFallback ?? false,
noIndexSearch: data.noIndexSearch ?? false,
isLoggedInVisitor: data.isLoggedInVisitor ?? false,
});
}
@@ -264,6 +273,7 @@ export async function fetchSiteContextByIds(
contextId?: string;
isFallback: boolean;
noIndexSearch: boolean;
isLoggedInVisitor: boolean;
}
): Promise<GitBookSiteContext> {
const { dataFetcher } = baseContext;
@@ -388,6 +398,7 @@ export async function fetchSiteContextByIds(
contextId: ids.contextId,
isFallback: ids.isFallback,
noIndexSearch: ids.noIndexSearch,
isLoggedInVisitor: ids.isLoggedInVisitor,
};
}
+1
View File
@@ -378,6 +378,7 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
!requestURL.searchParams.has('x-gitbook-search-indexation')
? true
: undefined,
isLoggedInVisitor: visitorToken ? true : undefined,
};
const requestHeaders = new Headers(request.headers);