WordPress MCP服务器

一个全面的模型上下文协议(MCP)服务器,使AI助手能够通过WordPress REST API与WordPress站点交互,提供程序化管理WordPress内容的功能。

  • by prathammanocha
  • JavaScript
  • 本地部署
  • 50 星标
  • 更新于
在 GitHub 查看 prathammanocha/wordpress-mcp-server

使用说明

全面的WordPress MCP服务器

一个全面的模型上下文协议(MCP)服务器,使人工智能助手能够通过WordPress REST API与WordPress网站进行交互。该服务器提供了以编程方式管理WordPress各个方面的工具,包括帖子、用户、评论、类别、标签和自定义端点。

特性

岗位管理

  • 创建、检索、更新和删除WordPress帖子
  • 按各种参数过滤帖子
  • 帖子列表的分页支持

用户管理

  • 通过ID或登录检索用户信息
  • 更新用户详细信息
  • 删除用户

评论管理

  • 创建、检索、更新和删除评论
  • 按帖子过滤评论
  • 评论列表的分页支持

分类管理

  • 管理类别和标签
  • 创建、检索、更新和删除分类法
  • 按slug查找类别和标签

站点信息

  • 检索WordPress网站的一般信息

自定义请求

  • 支持自定义REST API端点
  • 自定义HTTP方法(GET、POST、PUT、DELETE)
  • 自定义数据和参数

先决条件

  • Node.js v18或更高版本
  • 启用REST API的WordPress网站
  • 用于身份验证的WordPress应用程序密码

安装

  1. 克隆此存储库:
git clone [repository-url]
cd wordpress-mcp-server
  1. 安装依赖项:
npm install
  1. 构建服务器:
npm run build

WordPress配置

在使用服务器之前,您需要设置您的WordPress网站:

  1. 确保你的WordPress网站启用了REST API(默认情况下在WordPress 4.7+中启用)
  2. 创建应用程序密码:
    • 登录您的WordPress管理面板
    • 转到用户→ 个人资料
    • 向下滚动到“应用程序密码”
    • 输入应用程序的名称(例如“MCP服务器”)
    • 点击“添加新应用程序密码”
    • 复制生成的密码(您将无法再次看到它)

MCP配置

将服务器添加到MCP设置文件(通常位于 ~/AppData/Roaming/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json):

{
  "mcpServers": {
    "wordpress": {
      "command": "node",
      "args": ["path/to/wordpress-mcp-server/build/index.js"]
    }
  }
}

可用工具

岗位管理

1.create_post

创建一个新的WordPress帖子。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • title (必填):职位名称
  • content (必填):帖子内容
  • status (可选):发布状态(“草稿”、“发布”或“私人”,默认为“草稿”)

例子:

{
  "tool": "create_post",
  "siteUrl": "https://example.com",
  "username": "admin",
  "password": "xxxx xxxx xxxx xxxx",
  "title": "My First Post",
  "content": "Hello, world!",
  "status": "draft"
}

2.获取帖子

使用分页检索WordPress帖子。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • perPage (可选):每页帖子数(默认值:10)
  • page (可选):页码(默认:1)
  • customParams (可选):其他查询参数

例子:

{
  "tool": "get_posts",
  "siteUrl": "https://example.com",
  "username": "admin",
  "password": "xxxx xxxx xxxx xxxx",
  "perPage": 5,
  "page": 1
}

3.更新_帖子

更新现有的WordPress帖子。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • postId (必填):要更新的帖子ID
  • title (可选):新帖子标题
  • content (可选):新帖子内容
  • status (可选):新帖子状态(“草稿”、“发布”或“私人”)

例子:

{
  "tool": "update_post",
  "siteUrl": "https://example.com",
  "username": "admin",
  "password": "xxxx xxxx xxxx xxxx",
  "postId": 123,
  "title": "Updated Title",
  "content": "Updated content",
  "status": "publish"
}

4.删除_帖子

删除WordPress帖子。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • postId (必填):要删除的帖子的ID

例子:

{
  "tool": "delete_post",
  "siteUrl": "https://example.com",
  "username": "admin",
  "password": "xxxx xxxx xxxx xxxx",
  "postId": 123
}

用户管理

1.用户设置

检索WordPress用户。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • perPage (可选):每页用户数(默认值:10)
  • page (可选):页码(默认:1)

2.用户名

通过ID检索特定的WordPress用户。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • userId (必填):要检索的用户的ID

3.用户登录

按登录名检索WordPress用户。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • userLogin (必填):要检索的用户的登录名

评论管理

1.获取_注释

检索WordPress评论。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • perPage (可选):每页评论数(默认值:10)
  • page (可选):页码(默认:1)
  • postIdForComment (可选):按帖子ID过滤评论

2.创建_注释

在帖子上创建新评论。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • postIdForComment (必填):要评论的帖子的ID
  • commentContent (必填):评论内容
  • customData (可选):附加评论数据

类别和标签管理

1.get_categories

检索WordPress类别。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • perPage (可选):每页类别数(默认值:10)
  • page (可选):页码(默认:1)

2.创建_类别

创建一个新的WordPress类别。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • categoryName (必填):要创建的类别的名称
  • customData (可选):附加类别数据(描述、父项等)

自定义请求

1.定制请求

向任何WordPress REST API端点发出自定义请求。

参数:

  • siteUrl (必填):您的WordPress网站URL
  • username (必填):WordPress用户名
  • password (必填):WordPress应用程序密码
  • customEndpoint (必需):API终结点路径
  • customMethod (可选):HTTP方法(“GET”、“POST”、“PUT”、“DELETE”,默认值:“GET”)
  • customData (可选):POST/PUT请求的数据
  • customParams (可选):GET请求的URL参数

例子:

{
  "tool": "custom_request",
  "siteUrl": "https://example.com",
  "username": "admin",
  "password": "xxxx xxxx xxxx xxxx",
  "customEndpoint": "wp/v2/media",
  "customMethod": "GET",
  "customParams": {
    "per_page": 5
  }
}

响应格式

所有工具都以以下格式返回响应:

成功响应

{
  "success": true,
  "data": {
    // WordPress API response data
  },
  "meta": {
    // Optional metadata (pagination info, etc.)
  }
}

错误响应

{
  "success": false,
  "error": "Error message here"
}

安全考虑

  • 始终为您的WordPress网站使用HTTPS URL
  • 使用应用程序密码而不是WordPress主密码
  • 确保您的应用程序密码安全,不要共享
  • 考虑使用WordPress角色和功能来限制访问
  • 定期轮换应用程序密码

发展

为发展做出贡献:

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 运行测试(如果可用)
  5. 提交拉取请求

对于自动重新编译的开发模式:

npm run dev

许可证

该项目根据ISC许可证获得许可。

贡献

欢迎投稿!请随时提交拉取请求。