WordPress管理服务器

一个基于Model Context Protocol (MCP)的服务器,通过WordPress REST API实现AI助手与WordPress站点的交互,支持多站点管理、内容操作和站点配置。

  • by LiamCioci
  • 本地部署
  • 更新于
在 GitHub 查看 liamcioci/server-wp-mcp

使用说明

WordPress MCP服务器

A. 模型上下文协议(MCP) 使人工智能助手能够通过WordPress REST API与WordPress网站交互的服务器。支持多个具有安全身份验证的WordPress网站,通过自然语言实现内容管理、帖子操作和网站配置。

特性

  • 多站点支持:同时连接到多个WordPress网站
  • REST API集成完全访问 WordPress REST API 端点
  • 安全认证:使用应用程序密码进行安全的API访问
  • 动态端点发现:自动映射每个站点的可用端点
  • 灵活操作:支持GET、POST、PUT、DELETE和PATCH方法
  • 错误处理:通过有意义的消息进行优雅的错误处理
  • 简单配置:易于维护的JSON配置文件

安装

通过Smithery安装

通过以下方式自动安装Claude Desktop的WordPress服务器 史密瑟里:

npx -y @smithery/cli install server-wp-mcp --client claude

手动安装

npm install server-wp-mcp

工具参考

wp_discover_endpoints

映射WordPress网站上的所有可用REST API端点。

论据:

{
	"site": {
		"type": "string",
		"description": "Site alias (as defined in configuration)",
		"required": true
	}
}

退货: 可用终结点及其方法和命名空间的列表。

wp_call_endpoint

执行对WordPress网站的REST API请求。

论据:

{
	"site": {
		"type": "string",
		"description": "Site alias",
		"required": true
	},
	"endpoint": {
		"type": "string",
		"description": "API endpoint path",
		"required": true
	},
	"method": {
		"type": "string",
		"enum": ["GET", "POST", "PUT", "DELETE", "PATCH"],
		"description": "HTTP method",
		"default": "GET"
	},
	"params": {
		"type": "object",
		"description": "Request parameters or body data",
		"required": false
	}
}

配置

获取应用程序密码

  1. 登录您的WordPress管理仪表板
  2. 转到用户→ 个人资料
  3. 滚动到“应用程序密码”部分
  4. 输入应用程序的名称(例如“MCP服务器”)
  5. 点击“添加新应用程序密码”
  6. 复制生成的密码(您将无法再次看到它)

注意:应用程序密码需要WordPress 5.6或更高版本和HTTPS。

配置文件设置

创建JSON配置文件(例如。, wp-sites.json)您的WordPress网站详细信息:

{
	"myblog": {
		"URL": "https://myblog.com",
		"USER": "yourusername",
		"PASS": "abcd 1234 efgh 5678"
	},
	"testsite": {
		"URL": "https://test.example.com",
		"USER": "anotherusername",
		"PASS": "wxyz 9876 lmno 5432"
	}
}

每个站点配置都需要:

  • URL:WordPress网站URL(必须包含http://或https://)
  • USER:WordPress用户名
  • PASS:应用程序密码(空格将自动删除)

配置键(例如“myblog”、“testsite”)将成为您在与服务器交互时使用的站点别名。

使用Claude Desktop

添加到您的 claude_desktop_config.json:

{
	"mcpServers": {
		"wordpress": {
			"command": "node",
			"args": ["path/to/server/dist/index.js"],
			"env": {
				"WP_SITES_PATH": "/absolute/path/to/wp-sites.json"
			}
		}
	}
}

这 WP_SITES_PATH 环境变量必须指向配置文件的绝对路径。

示例用法

配置后,您可以要求Claude执行各种WordPress操作:

列表和查询帖子

Can you show me all posts from myblog published in the last month?
Find all posts on testsite tagged with "technology" and "AI"
Show me draft posts from myblog that need review

创建和编辑内容

Create a new draft post on testsite titled "The Future of AI" with these key points: [points]
Update the featured image on myblog's latest post about machine learning
Add a new category called "Tech News" to myblog

管理评论

Show me all pending comments on myblog's latest post
Find comments from testsite that might be spam
List the most engaged commenters on myblog

插件管理

What plugins are currently active on myblog?
Check if any plugins on testsite need updates
Tell me about the security plugins installed on myblog

用户管理

Show me all users with editor role on testsite
Create a new author account on myblog
Update user roles and permissions on testsite

站点设置和配置

What theme is currently active on myblog?
Check the permalink structure on testsite
Show me the current media library settings on myblog

维护和诊断

Check if there are any broken links on myblog
Show me the PHP version and other system info for testsite
List any pending database updates on myblog

错误处理

服务器处理常见错误,包括:

  • 配置文件路径或格式无效
  • 站点配置无效
  • 身份验证失败
  • 端点缺失或无效
  • API速率限制
  • 网络错误

所有错误都会返回描述性消息,以帮助诊断问题。

安全考虑

  • 保持你的 wp-sites.json 文件安全,从不将其提交到版本控制
  • 考虑在生产中为敏感数据使用环境变量
  • 将配置文件存储在公共目录之外
  • 对所有WordPress网站使用HTTPS
  • 定期轮换应用程序密码
  • 分配用户角色时遵循最小权限原则

依赖项

  • @modelcontextprotocol/sdk-MCP协议实现
  • axios-API请求的HTTP客户端

许可证

麻省理工学院