WordPress内容协议服务器

一个用于与WordPress站点交互的模型上下文协议服务器,提供从启用REST API的WordPress安装中获取文章、页面、分类和站点信息的工具。

  • by gopalcnepal
  • Python
  • 本地部署
  • 3 星标
  • 更新于
在 GitHub 查看 gopalcnepal/mcp-wordpress

使用说明

WordPress MCP服务器

用于与WordPress站点交互的模型上下文协议(MCP)服务器。该服务器提供了从任何启用REST API的WordPress安装中获取帖子、页面、类别和网站信息的工具。

先决条件

  • Python 3.13
  • 启用 REST API 的 WordPress 网站
  • UV封装安装程序(推荐)

安装

  1. 安装UV(通用Virtualenv):
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. 克隆存储库:
git clone <repository-url>
cd wordpress
  1. 创建并激活虚拟环境:
uv venv
source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`
  1. 使用UV安装依赖项:
uv add "mcp[cli]" httpx

配置

  1. 创建一个 .env 项目根目录中的文件:
WORDPRESS_URL="https://your-wordpress-site.com"

用法

将Claude用于桌面:

  • 首先,启动服务器:
uv run main.py
  • 在Claude for Desktop中,转到“设置”>“开发人员”
  • 点击“编辑配置”
  • 在Mac/Windows中使用VSCode的替代编辑配置方法:
    # For Mac Users
    code ~/Library/Application\ Support/Claude/claude_desktop_config.json
    
    # For Windows Users
    code $env:AppData\Claude\claude_desktop_config.json
    
  • 将文件添加到配置:
{
    "mcpServers": {
        "weather": {
            "command": "uv",
            "args": [
                "--directory",
                "/ABSOLUTE/PATH/TO/PARENT/FOLDER/wordpress",
                "run",
                "main.py"
            ]
        }
    }
}

服务器提供以下可测试的工具:

  • fetch_wordpress_info:获取网站基本信息
  • fetch_posts:获取最新帖子
  • fetch_categories:列出所有类别
  • fetch_posts_by_category:获取特定类别中的帖子
  • fetch_pages:获取网站页面
  • fetch_post_by_id:获得一个特定的职位
  • fetch_page_by_id:获取特定页面

错误处理

该服务器包括强大的错误处理功能,用于:

  • JSON响应无效
  • 网络错误
  • WordPress API错误
  • URL无效
  • API身份验证问题