一个用于无缝集成 WordPress 的模型上下文协议(MCP)服务器
将像 Claude Desktop 这样的AI助手连接到您的 WordPress 站点,支持多种认证方法,包括 OAuth 2.0、JWT 令牌和应用密码。
npm install @automattic/mcp-wordpress-remote
添加到您的 MCP 客户端配置(例如,Claude Desktop 的 claude_desktop_config.json):
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com"
}
}
}
}
您可以使用 CUSTOM_HEADERS 环境变量向所有 API 请求添加自定义头部。这对于 API 密钥、自定义认证或其他头部要求非常有用。
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com",
"CUSTOM_HEADERS": "{\"X-MCP-API-Key\": \"*Ibo7tweixlbfuwaiufxgakjyefctwajcetb*\", \"X-Custom-Header\": \"value\"}"
}
}
}
}
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com",
"CUSTOM_HEADERS": "X-MCP-API-Key:IOskncfyes78U8on3q7ry43o487tybrc,X-Custom-Header:value"
}
}
}
}
CUSTOM_HEADERS='{"X-MCP-API-Key": "wc_mcp_FaQduhQcW0mfVaZgP3yaaqDuXaZ3mw7j"}' \
WP_API_URL="https://your-site.com" \
npx @automattic/mcp-wordpress-remote
自定义头部包含在:
JWT_TOKEN 环境变量WP_API_USERNAME 和 WP_API_PASSWORD您需要在 WordPress 网站上安装 wordpress-mcp 插件,并在设置 > MCP 设置中启用 MCP 功能。
OAuth 2.1 提供最安全且用户友好的体验,完全符合 MCP 授权规范。
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com",
"OAUTH_ENABLED": "true"
}
}
}
}
MCP 授权规范功能:
优点:
用于服务器到服务器的认证或当 OAuth 不可用时。
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com",
"JWT_TOKEN": "your-jwt-token-here"
}
}
}
}
使用 WordPress 用户名和应用密码进行基本认证。
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com",
"WP_API_USERNAME": "your-username",
"WP_API_PASSWORD": "your-application-password",
"OAUTH_ENABLED": "false"
}
}
}
}
要创建应用密码:
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com",
"OAUTH_CALLBACK_PORT": "7665",
"OAUTH_HOST": "127.0.0.1",
"WP_OAUTH_CLIENT_ID": "your-custom-client-id"
}
}
}
}
针对 WooCommerce 特定工具和报告:
{
"mcpServers": {
"wordpress": {
"command": "npx",
"args": ["-y", "@automattic/mcp-wordpress-remote"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com",
"WOO_CUSTOMER_KEY": "ck_your-consumer-key",
"WOO_CUSTOMER_SECRET": "cs_your-consumer-secret"
}
}
}
}
| 变量 | 描述 | 默认值 | 是否必需 |
|---|---|---|---|
WP_API_URL | WordPress 站点 URL | - | ✅ |
OAUTH_ENABLED | 启用 OAuth 认证 | true | - |
OAUTH_CALLBACK_PORT | OAuth 回调端口 | 7665 | - |
OAUTH_HOST | OAuth 回调主机名 | 127.0.0.1 | - |
WP_OAUTH_CLIENT_ID | 自定义 OAuth 客户端 ID | - | - |
| OAuth 端点 | |||
OAUTH_AUTHORIZE_ENDPOINT | OAuth 授权端点 | - | ✅ (自定义 OAuth) |
OAUTH_TOKEN_ENDPOINT | OAuth 令牌端点 | - | ✅ (自定义 OAuth) |
OAUTH_AUTHENTICATE_ENDPOINT | OAuth 认证端点 | - | - |
| MCP OAuth 2.1 设置 | |||
OAUTH_FLOW_TYPE | OAuth 流类型(authorization_code 或 implicit) | authorization_code | - |
OAUTH_USE_PKCE | 使用 PKCE(OAuth 2.1 必需) | true | - |
OAUTH_DYNAMIC_REGISTRATION | 启用动态客户端注册 | true | - |
OAUTH_RESOURCE_INDICATOR | 使用资源指示符(RFC 8707) | true | - |
| 配置 | |||
WP_MCP_CONFIG_DIR | 配置目录覆盖 | ~/.mcp-auth | - |
LOG_FILE | 日志文件路径 | - | - |
LOG_LEVEL | 日志级别(0-3) | 2 | - |
| 遗留认证 | |||
JWT_TOKEN | JWT 令牌用于认证 | - | - |
WP_API_USERNAME | WordPress 用户名(遗留) | - | - |
WP_API_PASSWORD | WordPress 应用密码(遗留) | - | - |
WOO_CUSTOMER_KEY | WooCommerce 消费者密钥 | - | - |
WOO_CUSTOMER_SECRET | WooCommerce 消费者密钥 | - | - |
仅使用 JWT 或基本认证:
{
"env": {
"OAUTH_ENABLED": "false",
"JWT_TOKEN": "your-jwt-token"
}
}
为了开发和测试,您可以使用本地仓库:
克隆仓库:
git clone https://github.com/Automattic/mcp-wordpress-remote.git
cd mcp-wordpress-remote
安装依赖项:
npm install
构建项目:
npm run build
配置您的 MCP 客户端以使用本地版本:
{
"mcpServers": {
"wordpress": {
"command": "node",
"args": ["/path/to/your/mcp-wordpress-remote/dist/proxy.js"],
"env": {
"WP_API_URL": "https://your-wordpress-site.com"
}
}
}
}
npm run build:watch - 文件更改时自动重新构建npm test - 运行测试套件npm run check - 运行 TypeScript 和 Prettier 检查令牌自动存储在:
~/.mcp-auth/wordpress-remote-{version}/
# 查看存储的令牌
ls -la ~/.mcp-auth/wordpress-remote-*/
# 清除所有令牌(强制重新认证)
rm -rf ~/.mcp-auth/wordpress-remote-*/
# 清除特定版本的令牌
rm -rf ~/.mcp-auth/wordpress-remote-0.2.1/
代理自动在多个实例之间协调:
如果您看到“等待其他实例”的消息,这是正常行为。
OAuth 浏览器未打开:
OAUTH_CALLBACK_PORTOAuth 授权失败:
JWT 认证失败:
基本认证失败:
API 端点未找到:
WP_API_URL 正确权限被拒绝:
如果端口 3000 已经被占用:
{
"env": {
"OAUTH_CALLBACK_PORT": "8080"
}
}
“等待其他实例”消息在多个 MCP 客户端同时启动时是正常的。系统协调认证以避免冲突。
启用详细日志:
{
"env": {
"LOG_LEVEL": "3",
"LOG_FILE": "/path/to/logfile.log"
}
}
日志级别:
0 - 仅错误1 - 警告和错误2 - 信息、警告和错误(默认)3 - 调试、信息、警告和错误GPL v2 或更高版本
欢迎贡献!该项目由 Automattic Inc 维护。
需要帮助? 查看 故障排除部分 或打开一个问题。