MCP 服务器
Page summary:Strapi 包含一个内置的 模型上下文协议 (MCP) 服务器。一旦启用,它允许 AI 客户端通过 Strapi 的内容管理器直接创建、读取、更新、删除、发布和取消发布内容。所有操作都受管理员令牌权限的控制。
🌐 Strapi includes a built-in Model Context Protocol (MCP) server. Once enabled, it lets AI clients create, read, update, delete, publish, and unpublish content directly through Strapi's Content Manager. All operations are gated by Admin token permissions.
MCP 服务器向 AI 客户端(比如 Claude Desktop、Claude Code、Codex、Cursor 或任何兼容 MCP 的工具)提供一套内容管理工具。连接到 MCP 服务器的 AI 客户端可以做的事情包括创建博客文章、列出最近的条目或发布页面。可使用哪些工具取决于用于身份验证的管理员令牌所授予的权限。
🌐 The MCP server exposes a set of content management tools to AI clients such as Claude Desktop, Claude Code, Codex, Cursor, or any MCP-compatible tool. An AI client connected to the MCP server can, for example, create a blog article, list recent entries, or publish a page. Which tools are available depends on the permissions granted to the Admin token used for authentication.
配置
🌐 Configuration
在首次使用之前,必须对 Strapi MCP 服务器进行:
🌐 Before first use, the Strapi MCP server must be:
- 通过服务器配置文件启用,并使用在管理面板中创建的管理员令牌进行身份验证
- 已连接到你的 AI 客户端。
基于代码的 Strapi 配置
🌐 Strapi code-based configuration
通过将 mcp 对象添加到服务器配置文件中来启用 MCP 服务器:
🌐 Enable the MCP server by adding the mcp object to the server configuration file:
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
app: {
keys: env.array('APP_KEYS'),
},
mcp: {
enabled: true,
},
});
import type { Core } from '@strapi/strapi';
const config = ({ env }: Core.Config.Shared.ConfigParams): Core.Config.Server => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
app: {
keys: env.array('APP_KEYS'),
},
mcp: {
enabled: true,
},
});
export default config;
设置完成后,重启 Strapi。MCP 端点将在你的 Strapi 服务器上通过 /mcp 可用(例如,http://localhost:1337/mcp)。
🌐 Once the setting is in place, restart Strapi. The MCP endpoint becomes available at /mcp on your Strapi server (e.g., http://localhost:1337/mcp).
高级选项
🌐 Advanced options
可以将以下可选键添加到 mcp 配置对象中:
🌐 The following optional keys can be added to the mcp configuration object:
| 选项 | 类型 | 默认值 | 描述 |
|---|---|---|---|
enabled | 布尔值 | false | 启用或禁用 MCP 服务器。 |
connectTimeoutMs | 数字 | 5000 | 内部 MCP 传输在请求中止前的最大连接时间(毫秒)。 |
requestTimeoutMs | 数字 | 60000 | 单个 MCP 请求在超时前完成的最大时间(毫秒)。 |
mcp: {
enabled: true,
connectTimeoutMs: 10000, // 10 seconds
requestTimeoutMs: 120000, // 2 minutes
},
Strapi 管理面板配置
🌐 Strapi admin panel configuration
MCP 服务器使用管理员令牌对请求进行身份验证。每个 MCP 会话的权限范围取决于用来连接的令牌:
🌐 The MCP server authenticates requests using Admin tokens. Each MCP session is scoped to the permissions of the token used to connect:
- 创建新的管理员令牌(请参阅管理员令牌功能页面上的创建管理员令牌)。
- 复制令牌值。在配置 AI 客户端时你将需要它。
令牌的权限决定了哪些 MCP 工具对 AI 客户端可见。例如,如果令牌仅在 Article 内容类型上授予 read