斯特拉皮MCP内容管理工具添加福利群:解决AI开发者的「MCP实战痛点」一个为Strapi CMS提供的MCP服务器,通过模型上下文协议提供对内容类型和条目的访问。
该MCP服务器可与任何Strapi CMS实例集成,提供以下功能:
建议在项目根目录使用.env文件存储凭证。
STRAPI_URL: 你的Strapi实例URL(默认:http://localhost:1337)STRAPI_ADMIN_EMAIL: Strapi管理员用户的电子邮件地址(建议用于完整功能,特别是模式访问)STRAPI_ADMIN_PASSWORD: Strapi管理员用户的密码(建议)STRAPI_API_TOKEN: (可选备用)API令牌。如果未提供管理员凭证,可以使用此令牌,但权限可能有限STRAPI_DEV_MODE: 设置为"true"以启用开发模式功能(默认为false)示例.env文件:
STRAPI_URL=http://localhost:1337 STRAPI_ADMIN_EMAIL=your_admin_email@example.com STRAPI_ADMIN_PASSWORD=your_admin_password # STRAPI_API_TOKEN=your_api_token_here # 可选
重要提示: 将.env添加到.gitignore文件中,避免提交凭证。
npm install strapi-mcp
推荐方法(使用Cursor MCP配置):
对于Cursor用户,在~/.cursor/mcp.json文件中配置strapi-mcp服务器:
"strapi-mcp": {
"command": "node",
"args": ["/path/to/strapi-mcp/build/index.js"],
"env": {
"STRAPI_URL": "http://localhost:1337",
"STRAPI_ADMIN_EMAIL": "your_admin_email@example.com",
"STRAPI_ADMIN_PASSWORD": "your_admin_password"
}
}

使用strapi-mcp工具时,Cursor会自动管理服务器生命周期。
替代方法(使用.env文件):
确保已构建项目(npm run build)。然后使用Node.js v20.6.0+和--env-file标志运行服务器:
node --env-file=.env build/index.js

替代方法(直接使用环境变量):
export STRAPI_URL=http://localhost:1337
export STRAPI_ADMIN_EMAIL=your_admin_email@example.com
export STRAPI_ADMIN_PASSWORD=your_admin_password
# export STRAPI_API_TOKEN=your-api-token # 可选备用
export STRAPI_DEV_MODE=true # 可选
# 运行全局安装的包(如果通过npm install -g安装)
strapi-mcp
# 或直接运行本地构建
node build/index.js

create_content_type工具: 允许通过内容类型构建器API创建新的内容类型(需要管理员凭证)ResourceNotFound和AccessDenied错误代码MIT
一个为你的Strapi CMS提供的MCP服务器
这是一个基于TypeScript的MCP服务器,与Strapi CMS集成。它通过MCP协议提供对Strapi内容类型和条目的访问,使你可以:
strapi://content-type/URI列出和访问内容类型list_content_types - 列出Strapi中所有可用的内容类型get_entries - 获取特定内容类型的条目,支持可选过滤、分页、排序和关系填充get_entry - 通过ID获取特定条目create_entry - 为内容类型创建新条目update_entry - 更新现有条目delete_entry - 删除条目upload_media - 将媒体文件上传到Strapiget_content_type_schema - 获取特定内容类型的模式(字段、类型、关系)connect_relation - 将相关条目连接到条目的关系字段disconnect_relation - 将相关条目从条目的关系字段断开create_content_type - 使用内容类型构建器API创建新内容类型(需要管理员权限)publish_entry - 发布特定条目unpublish_entry - 取消发布特定条目list_components - 列出Strapi中所有可用的组件get_component_schema - 获取特定组件的模式create_component - 创建具有指定字段的新组件update_component - 修改现有组件get_entries工具支持高级查询选项:
{
"contentType": "api::article.article",
"filters": {
"title": {
"$contains": "hello"
}
},
"pagination": {
"page": 1,
"pageSize": 10
},
"sort": ["title:asc", "createdAt:desc"],
"populate": ["author", "categories"]
}

资源可以通过各种URI格式访问:
strapi://content-type/api::article.article - 获取所有文章strapi://content-type/api::article.article/1 - 获取ID为1的文章strapi://content-type/api::article.article?filters={"title":{"$contains":"hello"}} - 获取过滤后的文章publish_entry和unpublish_entry工具提供对内容生命周期的控制:
{
"contentType": "api::article.article",
"id": "1"
}

这些工具使用管理员API路径进行发布/取消发布操作,如果管理员权限不可用,则回退到直接更新publishedAt字段。
Strapi组件可以通过以下工具管理:
list_components: 获取所有可用的组件get_component_schema: 查看特定组件的结构create_component: 使用指定的字段创建新组件update_component: 修改现有组件创建组件的示例:
{
"componentData": {
"displayName": "安全设置",
"category": "安全",
"icon": "盾牌",
"attributes": {
"enableTwoFactor": {
"type": "布尔值",
"默认值": false
},
"passwordExpiration": {
"类型": "整数",
"最小值": 0
}
}
}
}

安装依赖:
npm install
构建服务器:
npm run build
开发时自动重建:
npm run watch
有关如何部署和测试此MCP服务器的详细分步说明,请参阅DEPLOYMENT.md文件。
快速设置:
npm run buildMacOS:~/Library/Application Support/Claude/claude_desktop_config.json
Windows:%APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"strapi-mcp": {
"command": "/path/to/strapi-mcp/build/index.js",
"env": {
"STRAPI_URL": "http://localhost:1337",
"STRAPI_API_TOKEN": "your-api-token-here",
"STRAPI_DEV_MODE": "false"
}
}
}
}

STRAPI_URL(可选):你的Strapi实例URL(默认为http://localhost:1337)STRAPI_ADMIN_EMAIL和STRAPI_ADMIN_PASSWORD(推荐):Strapi管理员用户的凭证。需要用于完整功能,如获取内容类型模式STRAPI_API_TOKEN(可选备用):你的Strapi API令牌。如果未提供管理员凭证,可以使用此令牌,但根据令牌权限,功能可能受限STRAPI_DEV_MODE(可选):设置为"true"以启用开发模式功能(默认为false)服务器按以下顺序优先考虑认证方法:
STRAPI_ADMIN_EMAIL,STRAPI_ADMIN_PASSWORD)STRAPI_API_TOKEN)强烈建议使用管理员凭证以获得最佳效果。
由于MCP服务器通过stdio通信,调试可能具有挑战性。我们建议使用MCP Inspector,它作为包脚本提供:
npm run inspector
Inspector将提供一个URL,你可以在浏览器中访问调试工具。
配置并运行MCP服务器后,你可以使用它与Claude交互你的Strapi CMS。以下是一些示例:
use_mcp_tool( server_name: "strapi-mcp", tool_name: "list_content_types", arguments: {} )
use_mcp_tool( server_name: "strapi-mcp", tool_name: "get_entries", arguments: { "contentType": "api::article.article", "filters": { "title": { "$contains": "hello" } }, "pagination": { "page": 1, "pageSize": 10 }, "sort": ["title:asc"] } )
use_mcp_tool( server_name: "strapi-mcp", tool_name: "create_entry", arguments: { "contentType": "api::article.article", "data": { "title": "我的新文章", "content": "这是我的文章内容。", "publishedAt": "2023-01-01T00:00:00.000Z" } } )
use_mcp_tool( server_name: "strapi-mcp", tool_name: "upload_media", arguments: { "fileData": "base64-encoded-data-here", "fileName": "image.jpg", "fileType": "image/jpeg" } )
use_mcp_tool( server_name: "strapi-mcp", tool_name: "connect_relation", arguments: { "contentType": "api::article.article", "id": "1", "relationField": "authors", "relatedIds": [2, 3] } )
use_mcp_tool( server_name: "strapi-mcp", tool_name: "disconnect_relation", arguments: { "contentType": "api::article.article", "id": "1", "relationField": "authors", "relatedIds": [3] } )
use_mcp_tool( server_name: "strapi-mcp-local", tool_name: "create_content_type", arguments: { "displayName": "我的新产品", "singularName": "product", "pluralName": "products", "kind": "collectionType", "description": "代表商店中的产品", "draftAndPublish": true, "attributes": { "name": { "type": "string", "required": true }, "description": { "type": "text" }, "price": { "type": "decimal", "required": true }, "stock": { "type": "integer" } } } )
use_mcp_tool( server_name: "strapi-mcp-local", tool_name: "update_content_type", arguments: { "contentType": "api::speaker.speaker", "attributes": { "isHighlightSpeaker": { "type": "boolean", "default": false }, "newTextField": { "type": "string" } } } )