首页
学习
活动
专区
圈层
工具
发布
MCP广场 >详情页
斯特拉皮MCP内容管理工具2026-10-21114分享添加福利群:解决AI开发者的「MCP实战痛点」
通过MCP协议提供对Strapi CMS内容的访问,允许用户通过Claude创建、读取、更新和删除内容条目。
By l33tdawg
2026-10-21114
github
详情内容

Strapi MCP

一个为Strapi CMS提供的MCP服务器,通过模型上下文协议提供对内容类型和条目的访问。

概述

该MCP服务器可与任何Strapi CMS实例集成,提供以下功能:

  • 将Strapi内容类型作为资源访问
  • 创建和更新Strapi内容类型的工具
  • 管理内容条目的工具(创建、读取、更新、删除)
  • 支持开发模式下的Strapi

安装设置

环境变量

建议在项目根目录使用.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

功能

  • 列出和读取内容类型
  • 获取、创建、更新和删除条目
  • 上传媒体文件
  • 连接和断开关系
  • 获取内容类型模式

更新日志

0.1.6

  • 添加create_content_type工具: 允许通过内容类型构建器API创建新的内容类型(需要管理员凭证)
  • 优先管理员凭证: 更新逻辑以优先使用管理员电子邮件/密码获取内容类型和模式,提高可靠性
  • 更新文档: 澄清认证方法和推荐运行程序

0.1.5

  • 改进内容类型发现,支持多种备用方法
  • 添加更健壮的错误处理和日志记录
  • 增强内容类型模式推断

0.1.4

  • 改进错误处理,提供更具体的错误代码
  • 添加ResourceNotFound和AccessDenied错误代码
  • 为常见API错误提供更好的错误消息

0.1.3

  • 初始公开发布

许可证

MIT

strapi-mcp MCP服务器

一个为你的Strapi CMS提供的MCP服务器

这是一个基于TypeScript的MCP服务器,与Strapi CMS集成。它通过MCP协议提供对Strapi内容类型和条目的访问,使你可以:

  • 将Strapi内容类型作为资源访问
  • 创建、读取、更新和删除内容条目
  • 通过MCP工具管理你的Strapi内容

功能

资源

  • 通过strapi://content-type/URI列出和访问内容类型
  • 每个内容类型将其条目作为JSON暴露
  • 应用程序/JSON MIME类型用于结构化内容访问

工具

  • list_content_types - 列出Strapi中所有可用的内容类型
  • get_entries - 获取特定内容类型的条目,支持可选过滤、分页、排序和关系填充
  • get_entry - 通过ID获取特定条目
  • create_entry - 为内容类型创建新条目
  • update_entry - 更新现有条目
  • delete_entry - 删除条目
  • upload_media - 将媒体文件上传到Strapi
  • get_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

资源可以通过各种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文件。

快速设置:

  1. 构建服务器:npm run build
  2. 配置你的Strapi实例并获取API令牌
  3. 将服务器配置添加到Claude Desktop:

MacOS:~/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)

认证优先级

服务器按以下顺序优先考虑认证方法:

  1. 管理员电子邮件和密码(STRAPI_ADMIN_EMAIL,STRAPI_ADMIN_PASSWORD)
  2. API令牌(STRAPI_API_TOKEN)

强烈建议使用管理员凭证以获得最佳效果。

获取Strapi凭证

  • 管理员凭证: 使用现有超级管理员的电子邮件和密码,或在Strapi管理面板(设置 > 管理面板 > 用户)中创建专用管理员用户
  • API令牌:(可选备用)
  1. 登录到你的Strapi管理面板
  2. 转到设置 > API令牌
  3. 点击"创建新的API令牌"
  4. 设置名称、描述和令牌类型(最好是"完全访问")
  5. 复制生成的令牌并在你的MCP服务器配置中使用

调试

由于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"
      }
    }
  }
)

访问资源

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档