mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Show MCP page actions for VA & adaptive sites (#4268)
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user