Home
Login

A plugin that transforms a WordPress site into a Model Context Protocol (MCP) server, enabling AI agents and large language models to interact with WordPress functionalities via REST API.

PHP 213Automatticwordpress-mcp Last Updated: 2025-06-24

WordPress MCP Project Detailed Introduction

Project Overview

WordPress MCP (Model Context Protocol) is a WordPress plugin developed by Automattic, designed to transform a WordPress site into a simple MCP server. It exposes site functionality through the WordPress REST API, enabling interaction with large language models (LLMs) and AI agents. This project allows developers to leverage AI tools for automating tasks such as content management, user operations, and site configuration, thereby enhancing development efficiency and integration capabilities.

Core Features

  1. MCP Server Support:

    • Provides MCP server functionality through REST API routes (e.g., /wp/v2/wpmcp and /wp/v2/wpmcp/streamable), supporting interaction between AI agents and WordPress.
    • Supports two transport layers: McpStdioTransport (standard input/output) and McpStreamableTransport (streaming, suitable for SSE or other streaming protocols).
  2. Authentication Mechanism:

    • Employs a JWT (JSON Web Token) authentication system to ensure secure communication.
    • Supports WordPress Application Passwords and WooCommerce REST API consumer keys and secret keys for enhanced security.
  3. Method Handlers:

    • Offers method handlers such as Tools, Resources, and Prompts to support content management, site initialization, and other operations.
    • Functionality can be extended through custom tools to meet specific needs.
  4. Admin Interface:

    • Provides a React-based admin interface for users to manage authentication tokens and other configurations in the WordPress backend.
  5. Compatibility with MCP Clients:

    • Seamlessly collaborates with MCP-compatible clients (e.g., Claude Desktop), supporting REST API requests through proxies (e.g., mcp-wordpress-remote) without requiring persistent open connections.

Project Features

  • Security: Ensures data security through JWT authentication and application passwords, recommending the use of HTTPS for encrypted communication.
  • Extensibility: Supports developers in extending plugin functionality by adding custom tools, resources, and prompts.
  • Developer-Friendly: Provides detailed testing documentation (tests/README.md) and contribution guidelines, encouraging community participation in development.
  • Lightweight and Efficient: The proxy mode avoids persistent open connections, optimizing performance and making it suitable for local development and remote deployment.
  • Open Source License: Licensed under GPL v2 or later, open to the WordPress and AI communities.

Technical Architecture

The core architecture of the project includes the following modules:

  • Transport Layer:

    • McpStdioTransport: Handles MCP requests through standard input/output, suitable for local development.
    • McpStreamableTransport: Supports streaming, ideal for real-time interaction scenarios (currently, some clients may not support it).
  • Authentication System:

    • Uses JWT authentication, requiring the definition of WPMCP_JWT_SECRET_KEY in wp-config.php.
    • Supports WordPress Application Passwords and WooCommerce keys for enhanced flexibility.
  • Method Handlers:

    • Tools: Implement operations such as content creation, updating, and deletion.
    • Resources: Provide site data access interfaces.
    • Prompts: Offer context guidance for AI agents.
    • System & Initialization: Handles the startup and configuration of the MCP server.
  • Admin Interface:

    • Built using React, located in the WordPress backend under "Settings > WordPress MCP," used for managing authentication tokens and feature switches.

Installation and Configuration

Installation Steps

  1. Clone the Repository:

    cd wp-content/plugins/
    git clone https://github.com/Automattic/wordpress-mcp.git
    cd wordpress-mcp
    
  2. Install Dependencies:

    composer install --no-dev
    npm install && npm run build
    
  3. Activate the Plugin:

    • Activate the WordPress MCP plugin on the "Plugins" page in the WordPress backend.
  4. Configure MCP Features:

    • Navigate to "Settings > WordPress MCP," enable MCP features, and configure authentication tokens.
  5. Configure JWT Key: Add the following to wp-config.php:

    define('WPMCP_JWT_SECRET_KEY', 'your-secret-key');
    define('WPMCP_DEBUG', true); // Enable debug logging
    
  6. Install Remote Client (Optional):

    • For use with mcp-wordpress-remote, install using the following command:
      npx @modelcontextprotocol/inspector \
      -e WP_API_URL=https://your-site.com/ \
      -e JWT_TOKEN=your-jwt-token-here \
      npx @automattic/mcp-wordpress-remote@latest
      

Configuration Notes

  • Security: Never commit authentication tokens to version control systems; ensure WPMCP_JWT_SECRET_KEY is stored securely.
  • Debugging: Enabling WPMCP_DEBUG records debug logs, facilitating troubleshooting.
  • Deletion Operations: Deleting tools may result in permanent data loss; enable only for trusted users.
  • Dependency on Remote Client: The WordPress MCP plugin needs to be used with mcp-wordpress-remote to achieve full functionality.

Use Cases

The WordPress MCP project is suitable for the following scenarios:

  1. Automated Content Management:

    • Create, update, or delete articles, pages, users, etc., through AI agents, saving manual operation time.
    • Example: Use the Claude Desktop command "Create 10 draft articles titled 'Test Article #1–10'" to automatically generate test content.
  2. Development and Testing:

    • Developers can use MCP tools to quickly generate test data, accelerating feature testing and integration development.
    • Example: Query debug logs and summarize issues through AI agents, simplifying the debugging process.
  3. Site Management:

    • Remotely manage site configurations, user permissions, or media files, suitable for distributed team collaboration.
    • Supports WooCommerce integration, allowing management of e-commerce-related data (e.g., orders, products).
  4. AI-Driven Customization:

    • Developers can add custom tools to expose specific business logic, meeting personalized needs.
    • Example: Create custom tools to batch update article categories or optimize SEO metadata.

Extension and Development

Adding Custom Tools

Developers can extend plugin functionality through the following steps:

  1. Create a Tool File:

    • Add a new tool class in the wp-content/plugins/wordpress-mcp/includes/Tools/ directory.
    • Example tool class:
      <?php
      namespace WPMCP\Tools;
      class CustomTool {
          public function execute($params) {
              // Implement custom logic
              return ['success' => true, 'data' => 'Custom tool executed'];
          }
      }
      
  2. Register the Tool:

    • Register the new tool during plugin initialization to ensure it is available through the MCP interface.
  3. Refer to Existing Implementations:

    • See the example code in the includes/Tools/, includes/Resources/, and includes/Prompts/ directories.

Contributing Code

  • Contribution Guidelines: Refer to the Contributing Guidelines in the repository to submit Pull Requests or report Issues.
  • Testing Documentation: See tests/README.md to understand the testing process and ensure code quality.
  • License Requirements: All contributions must comply with the GPL v2 or later license.

Related Resources

Star History Chart