> For the complete documentation index, see [llms.txt](https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/documentation/zh/ai-yu-sou-suo/mcp-servers-for-published-docs.md).

# 已发布文档的 MCP 服务器

每个已发布的 GitBook 站点都会自动包含一个模型上下文协议（MCP）服务器。

AI 工具可以用它直接读取你已发布的文档。这适用于 Claude Desktop、Cursor 和 VS Code 扩展等工具。

你的 MCP 服务器地址是你的已发布站点 URL 加上 `/~gitbook/mcp`.

例如，GitBook 的文档位于 `https://gitbook.com/docs`。它的 MCP 服务器是 `https://gitbook.com/docs/~gitbook/mcp`.

对于公开站点、所有已发布内容都可见的分享链接站点，以及完全通过身份验证的站点，请使用此端点。

对于完全通过身份验证的站点，MCP 客户端会先通过 MCP 发现和 OAuth 流程完成身份验证，然后才能访问工具。更多详情，请参阅 [MCP 授权流程](https://modelcontextprotocol.io/docs/tutorials/security/authorization#the-authorization-flow-step-by-step).

如果你的站点是部分身份验证，且仍然暴露公开内容或分享链接内容，请改用 `/~gitbook/mcp/auth` 。例如， `https://gitbook.com/docs/~gitbook/mcp/auth`.

{% hint style="info" %}
如果你在浏览器中打开此 URL，你会看到错误。请在能够发出 HTTP 请求的工具中使用它，例如 AI 助手或 IDE。
{% endhint %}

### 连接 AI 工具

{% stepper %}
{% step %}

#### 查找你的 MCP 服务器 URL

获取你已发布的 GitBook 站点 URL，并添加与你站点匹配的端点：

* 使用 `/~gitbook/mcp` 适用于公开站点、所有已发布内容都可见的分享链接站点，或使用 MCP 发现和 OAuth 的完全身份验证站点。
* 使用 `/~gitbook/mcp/auth` 如果你的站点是部分身份验证，且仍然暴露公开内容或分享链接内容。
  {% endstep %}

{% step %}

#### 配置你的 AI 工具

将 MCP 服务器 URL 添加到你的 AI 助手设置中。每个工具的设置流程略有不同，因此你应查看所选工具的文档，了解如何为其配置 MCP 服务器。
{% endstep %}

{% step %}

#### 开始使用你的文档

连接后，你的 AI 助手可以搜索你的文档、检索特定页面，并使用你的内容回答问题。该助手将实时访问你已发布的文档。
{% endstep %}
{% endstepper %}

{% hint style="info" %}
**页面操作** 必须启用，MCP 服务器才能正常工作。如果你关闭 **站点自定义** → **页面操作**，GitBook 会禁用 `~gitbook/mcp` ，并且该端点将返回 `404`. **使用 MCP 服务器连接** 仅控制 MCP 链接是否显示在页面操作菜单中。
{% endhint %}

{% stepper %}
{% step %}
**查找你的 MCP 服务器 URL**

获取你已发布的 GitBook 站点 URL。然后添加 `/~gitbook/mcp`.
{% endstep %}

{% step %}
**配置你的 AI 工具**

打开你工具的 MCP 设置。然后输入服务器 URL。

每个工具的设置方式都不同。请查看你所用工具的文档以获取具体步骤。
{% endstep %}

{% step %}
**开始使用你的文档**

连接后，该工具可以搜索你的文档、打开页面，并用你的内容回答问题。
{% endstep %}
{% endstepper %}

### 要求

MCP 服务器会遵循你站点的可见性设置。请使用 `/~gitbook/mcp` 适用于公开站点、所有已发布内容都可见的分享链接站点，或使用 MCP 发现和 OAuth 的完全身份验证站点。请使用 `/~gitbook/mcp/auth` 如果你的站点是部分身份验证，且仍然暴露公开内容或分享链接内容。

在 **页面操作** 的部分中 [自定义](/url/gitbook.com/docs/documentation/zh/docs-site/customization.md) 设置中，你可以启用 **使用 MCP 服务器连接** 选项。这样，访问你文档站点的访客就可以直接从 [页面操作菜单](/url/gitbook.com/docs/documentation/zh/docs-site/customization/extra-configuration.md#page-actions).

要使用 MCP 服务器：

* 你的站点必须已发布。MCP 服务器仅公开已发布内容。
* **页面操作** 必须在 **站点自定义** → **页面操作**.
* 你的工具必须支持通过 HTTP 的 MCP。
* 如果你的站点使用身份验证访问，MCP 服务器会使用相同的访问规则。
* 如果你的站点使用分享链接，请使用分享链接站点 URL，然后添加 `/~gitbook/mcp`.
* GitBook 仅支持 HTTP 传输。 `stdio` 和 `SSE` 不受支持。

### 将 MCP 链接添加到你的站点

在 [站点自定义](/url/gitbook.com/docs/documentation/zh/docs-site/customization.md)，打开 [页面操作](/url/gitbook.com/docs/documentation/zh/docs-site/customization/extra-configuration.md#page-actions)。确保 **页面操作** 已开启。然后开启 **使用 MCP 服务器连接**.

如果 **页面操作** 已关闭，GitBook 会禁用 `~gitbook/mcp` ，并且该端点将返回 `404`.

**使用 MCP 服务器连接** 仅控制 GitBook 是否在页面操作菜单中显示 MCP 服务器链接。

访客随后就可以从页面操作菜单中复制服务器 URL。

### 隐私与访问

请确保你使用的是正确的 URL 格式。请使用 `/~gitbook/mcp` 适用于公开站点、所有已发布内容都可见的分享链接站点，或使用 MCP 发现和 OAuth 的完全身份验证站点。请使用 `/~gitbook/mcp/auth` 适用于包含公开内容或分享链接内容的部分身份验证站点。

MCP 服务器为你已发布的文档提供只读访问。

隐藏页面仍可通过 MCP 访问。隐藏页面只会将其从已发布的目录中移除。

它绝不会暴露账户数据、分析数据或 GitBook 内部数据。

它只提供最新的已发布版本。草稿和未发布的更改仍保持私密。

### 故障排除

如果某个工具无法连接：

* 确认你已发布的站点可访问。
* 确认 URL 以 `/~gitbook/mcp`.
* 如果该站点使用身份验证，请使用支持 [MCP 授权规范](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization).
* 如果该工具需要 `stdio` 或 `SSE`，它将无法与 GitBook 配合使用。

### 在已验证站点中使用 MCP

如果你的 GitBook 站点使用  [身份验证访问](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access.md)，位于 `/~gitbook/mcp` 的 MCP 服务器会使用相同的身份验证。支持 [MCP 授权规范](https://modelcontextprotocol.io/docs/tutorials/security/authorization) ——包括 Claude 和 Claude Code——的 MCP 客户端可以使用 OAuth 和动态客户端注册（DCR）自动连接到服务器。

如果你的站点改用分享链接，MCP 仍然可用。使用完整的分享链接站点 URL，然后添加 `/~gitbook/mcp`.

GitBook 不支持仅使用分享链接的站点，也不支持将访客身份验证令牌作为静态请求头用于 MCP 身份验证的站点。

如果你的站点使用 [身份验证访问](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access.md)，MCP 服务器会使用相同的访问规则。公开站点保持公开。受保护站点需要相同的登录。

受支持的 MCP 客户端——包括 Claude——会遵循 [MCP 授权规范](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization) 进行连接。

{% stepper %}
{% step %}

#### 发现 OAuth 服务器

在 MCP 握手过程中，客户端会发现你站点的 OAuth 服务器。
{% endstep %}

{% step %}

#### 通过 DCR 注册客户端

客户端通过动态客户端注册注册一个 OAuth 客户端。

你无需手动创建客户端 ID。
{% endstep %}

{% step %}

#### 使用你站点的身份验证提供方登录

客户端会将你重定向到你站点的身份验证提供方。

你使用文档站点已在使用的同一提供方登录。
{% endstep %}

{% step %}

#### 将代码兑换为令牌

登录后，客户端会将授权码兑换为访问令牌。
{% endstep %}

{% step %}

#### 重复使用令牌

客户端会在后续 MCP 请求中携带该令牌，直到它过期。
{% endstep %}
{% endstepper %}

此流程适用于以下已验证访问后端：

* [Auth0](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access/setting-up-auth0.md)
* [Azure AD](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access/setting-up-azure-ad.md)
* [Okta](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access/setting-up-okta.md)
* [AWS Cognito](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access/setting-up-aws-cognito.md)
* [OIDC](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access/setting-up-oidc.md)
* [自定义后端](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access/setting-up-a-custom-backend.md) 带有已配置的 Fallback URL

{% hint style="warning" %}
MCP 身份验证不支持仅依赖请求头中静态访客身份验证令牌的站点。

请改用上述任一已验证访问后端。
{% endhint %}

要进行设置，请从以下内容开始： [已验证访问](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access.md) 和 [启用身份验证访问](/url/gitbook.com/docs/documentation/zh/zhan-dian-fang-wen/authenticated-access/enabling-authenticated-access.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/documentation/zh/ai-yu-sou-suo/mcp-servers-for-published-docs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
