一个用于与 Strapi CMS 交互的模型上下文协议服务器。该服务器使 AI 助手能够通过标准化接口与您的 Strapi 实例进行交互,支持内容类型和 REST API 操作。
⚠️ 重要免责声明:本软件是在 AI 技术的协助下开发的。它以“原样”提供,未经全面测试和验证,不应在生产环境中使用。代码可能包含错误、安全漏洞或意外行为。仅供研究、学习或开发目的使用,风险自负。
您可以在 Claude Desktop 配置中直接使用 npx 运行此服务器:
{
"mcpServers": {
"strapi": {
"command": "npx",
"args": ["-y", "@bschauer/strapi-mcp-server@2.5.0"]
}
}
}

在 ~/.mcp/strapi-mcp-server.config.json
中创建配置文件:
{
"myserver": {
"api_url": "http://localhost:1337",
"api_key": "your-jwt-token-from-strapi-admin",
"version": "5.*" // 可选:指定 Strapi 版本(例如 "5.*", "4.1.5", "v4")
}
}

您可以通过向此文件添加多个 Strapi 实例来配置多个服务器。
服务器现在支持多种版本格式:
这有助于服务器提供版本特定指导,并适当处理 API 差异。
strapi_list_servers();
// 现在包括版本信息以及 v4 和 v5 之间的差异

// 从特定服务器获取所有内容类型
strapi_get_content_types({
server: "myserver",
});
// 分页获取组件
strapi_get_components({
server: "myserver",
page: 1,
pageSize: 25,
});

REST API 提供了全面的 CRUD 操作,内置验证和版本特定处理:
// 使用过滤器查询内容
strapi_rest({
server: "myserver",
endpoint: "api/articles",
method: "GET",
params: {
filters: {
title: {
$contains: "search term",
},
},
},
});
// 创建新内容
strapi_rest({
server: "myserver",
endpoint: "api/articles",
method: "POST",
body: {
data: {
title: "New Article",
content: "Article content",
category: "news",
},
},
});
// 更新内容
strapi_rest({
server: "myserver",
endpoint: "api/articles/123",
method: "PUT",
body: {
data: {
title: "Updated Title",
content: "Updated content",
},
},
});
// 删除内容
strapi_rest({
server: "myserver",
endpoint: "api/articles/123",
method: "DELETE",
});

// 上传图像并自动优化
strapi_upload_media({
server: "myserver",
url: "https://example.com/image.jpg",
format: "webp",
quality: 80,
metadata: {
name: "My Image",
caption: "Image Caption",
alternativeText: "Alt Text",
},
});

服务器自动处理的 Strapi 版本之间的关键差异:
服务器实施了严格的写保护策略:
strapi_get_content_types
检查模式// 按字段值过滤
params: {
filters: {
title: "Exact Match";
}
}
// 包含过滤器
params: {
filters: {
title: {
$contains: "partial";
}
}
}
// 多个条件
params: {
filters: {
$and: [{ category: "news" }, { published: true }];
}
}

params: {
sort: ["createdAt:desc"];
}

params: {
pagination: {
page: 1,
pageSize: 25
}
}

// 基本请求,不填充
params: {
}
// 需要时选择性填充
params: {
populate: ["category"];
}
// 详细填充,选择字段
params: {
populate: {
category: {
fields: ["name", "slug"];
}
}
}

常见问题及解决方案:
404 错误
认证问题
版本相关问题
写保护错误
欢迎贡献!请随时提交 Pull Request。
MIT