Skip follow-up questions in ?ask= answers and the MCP askQuestion tool (#4880)

This commit is contained in:
Nolann B.
2026-12-03 12:28:13 +01:00
committed by GitHub
parent 04f20c9130
commit b7fdddd3dd
6 changed files with 10 additions and 70 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Stop asking for follow-up questions in `?ask=` answers and the MCP `askQuestion` tool, so answers come back sooner.
+2 -2
View File
@@ -357,7 +357,7 @@
},
"catalog": {
"@base-ui/react": "^1.7.0",
"@gitbook/api": "0.218.0",
"@gitbook/api": "0.219.0",
"@scalar/api-client-react": "^1.3.46",
"@tsconfig/node20": "^20.1.6",
"@tsconfig/strictest": "^2.0.6",
@@ -725,7 +725,7 @@
"@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@7.2.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "7.2.0" } }, "sha512-6639htZMjEkwskf3J+e6/iar+4cTNM9qhoWuRfj9F3eJD6r7iCzV1SWnQr2Mdv0QT0suuqU8BoJCZUyCtP9R4Q=="],
"@gitbook/api": ["@gitbook/api@0.218.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-znLZYddV7LOT0TJ1CeSWd39rUA+T8h/2egEmOXDmO/n9utoTIthTOSdo8AaOJdfFMtDpeJaLzngi1Uk7bKJK6g=="],
"@gitbook/api": ["@gitbook/api@0.219.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-huFtK2K6FMpqjJEudoeejZdhCeqFAKQZrzpyH0nlzewGl8Up8D2oyUHiWAcWMt0atp5dUzCG0qbmchdjgABAhw=="],
"@gitbook/browser-types": ["@gitbook/browser-types@workspace:packages/browser-types"],
+1 -1
View File
@@ -48,7 +48,7 @@
"@tsconfig/strictest": "^2.0.6",
"@tsconfig/node20": "^20.1.6",
"@base-ui/react": "^1.7.0",
"@gitbook/api": "0.218.0",
"@gitbook/api": "0.219.0",
"@scalar/api-client-react": "^1.3.46",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
+2
View File
@@ -50,6 +50,8 @@ export async function streamSiteAskAnswer(
mode: 'default',
currentSiteSpace: context.siteSpace.id,
},
// Agents don't use suggestions, and generating them delays the answer.
followupQuestions: false,
},
{ format: 'markdown' },
{ headers: getAskForwardedHeaders(options.visitorAgent) }
@@ -1,48 +0,0 @@
import { describe, expect, it, mock } from 'bun:test';
import type { GitBookSiteContext } from '@/lib/context';
import { createLinker } from '@/lib/links';
mock.module('server-only', () => ({}));
const { serveAskMarkdown } = await import('./markdownAsk');
const context = {
organizationId: 'org-1',
site: { id: 'site-1' },
siteSpace: { id: 'site-space-1' },
customization: { ai: { mode: 'assistant' } },
linker: createLinker({
host: 'docs.example.com',
siteBasePath: '/docs/',
spaceBasePath: '/docs/',
}),
dataFetcher: {
api: async () => ({
orgs: {
async *streamAskInSite() {
yield {
type: 'answer',
answer: {
answer: { markdown: 'Publish from the site settings.' },
followupQuestions: ['How do I add a custom domain?'],
sources: [],
},
};
},
},
}),
},
} as unknown as GitBookSiteContext;
describe('serveAskMarkdown', () => {
it('links follow-up questions to the markdown ask route', async () => {
const response = await serveAskMarkdown(context, 'How do I publish?', {
goal: 'ship docs',
});
expect(await response.text()).toContain(
'- [How do I add a custom domain?](https://docs.example.com/docs/index.md?ask=How%20do%20I%20add%20a%20custom%20domain%3F&goal=ship%20docs)'
);
});
});
@@ -79,25 +79,6 @@ export async function serveAskMarkdown(
result += answerMarkdown.trim();
result += '\n\n';
const followupQuestions = latestAnswer.followupQuestions ?? [];
if (followupQuestions.length > 0) {
const askURL = markdownLinker.toAbsoluteURL(
markdownLinker.toPathForPagePath({ path: 'index' })
);
result += '# Suggested Follow-up Questions:\n\n';
result +=
'If you need more information, consider asking one of these follow-up questions by performing an HTTP GET request on the URL:\n\n';
result += followupQuestions
.map((q) => {
const base = `${askURL}?ask=${encodeURIComponent(q)}`;
// Carry the goal forward so a multi-step agent keeps its end goal across asks.
const url = goal ? `${base}&goal=${encodeURIComponent(goal)}` : base;
return `- [${q}](${url})`;
})
.join('\n');
result += '\n\n';
}
if (sourcesMarkdown) {
result += '# Sources:\n\n';
result += sourcesMarkdown;