From f3affc30341e88f549f563c0cdac5f52d795a763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Tue, 1 Jul 2025 09:58:59 +0200 Subject: [PATCH] Add support for MCP tools (#3410) --- .changeset/few-cars-joke.md | 5 +++++ bun.lock | 4 ++-- package.json | 2 +- .../AI/server-actions/AIToolCallsSummary.tsx | 22 +++++++++++++++++++ .../DocumentView/Integration/contentkit.tsx | 1 + packages/gitbook/src/intl/translations/de.ts | 1 + packages/gitbook/src/intl/translations/en.ts | 1 + packages/gitbook/src/intl/translations/es.ts | 1 + packages/gitbook/src/intl/translations/fr.ts | 1 + packages/gitbook/src/intl/translations/ja.ts | 1 + packages/gitbook/src/intl/translations/nl.ts | 1 + packages/gitbook/src/intl/translations/no.ts | 1 + .../gitbook/src/intl/translations/pt-br.ts | 1 + packages/gitbook/src/intl/translations/zh.ts | 1 + 14 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 .changeset/few-cars-joke.md diff --git a/.changeset/few-cars-joke.md b/.changeset/few-cars-joke.md new file mode 100644 index 000000000..68d4ec2ef --- /dev/null +++ b/.changeset/few-cars-joke.md @@ -0,0 +1,5 @@ +--- +"gitbook": minor +--- + +Display MCP tool calls in AI chat. diff --git a/bun.lock b/bun.lock index baee5a7ee..66a81b5a5 100644 --- a/bun.lock +++ b/bun.lock @@ -250,7 +250,7 @@ "react-dom": "^19.0.0", }, "catalog": { - "@gitbook/api": "^0.123.0", + "@gitbook/api": "^0.125.0", }, "packages": { "@ai-sdk/provider": ["@ai-sdk/provider@1.1.0", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-0M+qjp+clUD0R1E5eWQFhxEvWLNaOtGQRUaBn8CUABnSKredagq92hUS9VjOzGsTm37xLfpaxl97AVtbeOsHew=="], @@ -613,7 +613,7 @@ "@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@6.6.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="], - "@gitbook/api": ["@gitbook/api@0.123.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-BszoIk4H/wWb0jnGSJPSSXSAO8tV4B4/LHwl5ygfERHqk9rOGpM/U7+yOlmbX/tnm30vE+MQ3QQ5i8hN8wVk1w=="], + "@gitbook/api": ["@gitbook/api@0.125.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-8WrsENzW7ehafLWbBfk0zs7xxmCJ/H8yy05BQGdZOR26TJzfMfkqMtuCLFukT8vbgjRgRrHanBoU98cCXHm1rg=="], "@gitbook/cache-tags": ["@gitbook/cache-tags@workspace:packages/cache-tags"], diff --git a/package.json b/package.json index 919ce46cf..a926a4e11 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "workspaces": { "packages": ["packages/*"], "catalog": { - "@gitbook/api": "^0.123.0" + "@gitbook/api": "^0.125.0" } }, "patchedDependencies": { diff --git a/packages/gitbook/src/components/AI/server-actions/AIToolCallsSummary.tsx b/packages/gitbook/src/components/AI/server-actions/AIToolCallsSummary.tsx index fd6f4802b..ed4738751 100644 --- a/packages/gitbook/src/components/AI/server-actions/AIToolCallsSummary.tsx +++ b/packages/gitbook/src/components/AI/server-actions/AIToolCallsSummary.tsx @@ -8,6 +8,7 @@ import type { AIToolCall, AIToolCallGetPageContent, AIToolCallGetPages, + AIToolCallMCP, AIToolCallSearch, ContentRef, } from '@gitbook/api'; @@ -54,6 +55,8 @@ function getDescriptionForToolCall(toolCall: AIToolCall, context: GitBookSiteCon return ; case 'getPages': return ; + case 'mcp': + return ; default: return <>{toolCall.tool}; } @@ -89,6 +92,25 @@ function DescriptionForPageContentToolCall(props: { ); } +function DescriptionForMCPToolCall(props: { + toolCall: AIToolCallMCP; + context: GitBookSiteContext; +}) { + const { toolCall, context } = props; + + const language = getSpaceLanguage(context.customization); + + return ( +

+ {t( + language, + 'ai_chat_tools_mcp_tool', + {toolCall.mcpToolTitle ?? toolCall.mcpToolName} + )} +

+ ); +} + async function DescriptionForSearchToolCall(props: { toolCall: AIToolCallSearch; context: GitBookSiteContext; diff --git a/packages/gitbook/src/components/DocumentView/Integration/contentkit.tsx b/packages/gitbook/src/components/DocumentView/Integration/contentkit.tsx index 155077ca2..3d1f69111 100644 --- a/packages/gitbook/src/components/DocumentView/Integration/contentkit.tsx +++ b/packages/gitbook/src/components/DocumentView/Integration/contentkit.tsx @@ -22,6 +22,7 @@ export const contentKitServerContext: ContentKitServerContext = { lock: (props) => , check: (props) => , 'check-circle': (props) => , + 'eye-off': (props) => , }, codeBlock: (props) => { return ; diff --git a/packages/gitbook/src/intl/translations/de.ts b/packages/gitbook/src/intl/translations/de.ts index f522992cf..49f1eecf4 100644 --- a/packages/gitbook/src/intl/translations/de.ts +++ b/packages/gitbook/src/intl/translations/de.ts @@ -90,4 +90,5 @@ export const de = { searched_for: 'Gesucht nach ${1}', ai_chat_tools_listed_pages: 'Docs durchsucht', ai_chat_tools_read_page: 'Seite ${1} gelesen', + ai_chat_tools_mcp_tool: 'Aufgerufen ${1}', }; diff --git a/packages/gitbook/src/intl/translations/en.ts b/packages/gitbook/src/intl/translations/en.ts index b8536ee1e..5ac034020 100644 --- a/packages/gitbook/src/intl/translations/en.ts +++ b/packages/gitbook/src/intl/translations/en.ts @@ -88,4 +88,5 @@ export const en = { searched_for: 'Searched for ${1}', ai_chat_tools_listed_pages: 'Browsed the docs', ai_chat_tools_read_page: 'Read page ${1}', + ai_chat_tools_mcp_tool: 'Called ${1}', }; diff --git a/packages/gitbook/src/intl/translations/es.ts b/packages/gitbook/src/intl/translations/es.ts index f2106d123..81a0d670b 100644 --- a/packages/gitbook/src/intl/translations/es.ts +++ b/packages/gitbook/src/intl/translations/es.ts @@ -92,4 +92,5 @@ export const es: TranslationLanguage = { searched_for: 'Buscado ${1}', ai_chat_tools_listed_pages: 'Exploró los docs', ai_chat_tools_read_page: 'Leyó la página ${1}', + ai_chat_tools_mcp_tool: 'Llamó a ${1}', }; diff --git a/packages/gitbook/src/intl/translations/fr.ts b/packages/gitbook/src/intl/translations/fr.ts index ec553a583..7d49171cc 100644 --- a/packages/gitbook/src/intl/translations/fr.ts +++ b/packages/gitbook/src/intl/translations/fr.ts @@ -90,4 +90,5 @@ export const fr: TranslationLanguage = { searched_for: 'Recherché ${1}', ai_chat_tools_listed_pages: 'Parcouru les docs', ai_chat_tools_read_page: 'Lu la page ${1}', + ai_chat_tools_mcp_tool: 'Appelé ${1}', }; diff --git a/packages/gitbook/src/intl/translations/ja.ts b/packages/gitbook/src/intl/translations/ja.ts index 3ac6ea1b0..223dc8d70 100644 --- a/packages/gitbook/src/intl/translations/ja.ts +++ b/packages/gitbook/src/intl/translations/ja.ts @@ -91,4 +91,5 @@ export const ja: TranslationLanguage = { searched_for: '${1}を検索しました', ai_chat_tools_listed_pages: 'ドキュメントを閲覧', ai_chat_tools_read_page: 'ページ ${1} を読みました', + ai_chat_tools_mcp_tool: '${1} を呼び出しました', }; diff --git a/packages/gitbook/src/intl/translations/nl.ts b/packages/gitbook/src/intl/translations/nl.ts index d7ae434c3..8f824a72f 100644 --- a/packages/gitbook/src/intl/translations/nl.ts +++ b/packages/gitbook/src/intl/translations/nl.ts @@ -90,4 +90,5 @@ export const nl: TranslationLanguage = { searched_for: 'Gezocht naar ${1}', ai_chat_tools_listed_pages: 'Docs doorzocht', ai_chat_tools_read_page: 'Pagina ${1} gelezen', + ai_chat_tools_mcp_tool: '${1} aangeroepen', }; diff --git a/packages/gitbook/src/intl/translations/no.ts b/packages/gitbook/src/intl/translations/no.ts index 6a7a591f5..e1c962b00 100644 --- a/packages/gitbook/src/intl/translations/no.ts +++ b/packages/gitbook/src/intl/translations/no.ts @@ -90,4 +90,5 @@ export const no: TranslationLanguage = { searched_for: 'Søkte etter ${1}', ai_chat_tools_listed_pages: 'Bladde gjennom docs', ai_chat_tools_read_page: 'Leste side ${1}', + ai_chat_tools_mcp_tool: 'Kallte ${1}', }; diff --git a/packages/gitbook/src/intl/translations/pt-br.ts b/packages/gitbook/src/intl/translations/pt-br.ts index 5338b543c..cc594d582 100644 --- a/packages/gitbook/src/intl/translations/pt-br.ts +++ b/packages/gitbook/src/intl/translations/pt-br.ts @@ -90,4 +90,5 @@ export const pt_br = { searched_for: 'Pesquisou por ${1}', ai_chat_tools_listed_pages: 'Navegou pelos docs', ai_chat_tools_read_page: 'Leu a página ${1}', + ai_chat_tools_mcp_tool: 'Chamou ${1}', }; diff --git a/packages/gitbook/src/intl/translations/zh.ts b/packages/gitbook/src/intl/translations/zh.ts index a2ca612dd..4cb1c07ed 100644 --- a/packages/gitbook/src/intl/translations/zh.ts +++ b/packages/gitbook/src/intl/translations/zh.ts @@ -87,4 +87,5 @@ export const zh: TranslationLanguage = { searched_for: '搜索了 ${1}', ai_chat_tools_listed_pages: '浏览了文档', ai_chat_tools_read_page: '已读取页面 ${1}', + ai_chat_tools_mcp_tool: '调用了 ${1}', };