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
-
MCP Server Support:
- Provides MCP server functionality through REST API routes (e.g.,
/wp/v2/wpmcpand/wp/v2/wpmcp/streamable), supporting interaction between AI agents and WordPress. - Supports two transport layers:
McpStdioTransport(standard input/output) andMcpStreamableTransport(streaming, suitable for SSE or other streaming protocols).
- Provides MCP server functionality through REST API routes (e.g.,
-
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.
-
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.
-
Admin Interface:
- Provides a React-based admin interface for users to manage authentication tokens and other configurations in the WordPress backend.
-
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.
- Seamlessly collaborates with MCP-compatible clients (e.g., Claude Desktop), supporting REST API requests through proxies (e.g.,
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_KEYinwp-config.php. - Supports WordPress Application Passwords and WooCommerce keys for enhanced flexibility.
- Uses JWT authentication, requiring the definition of
-
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
-
Clone the Repository:
cd wp-content/plugins/ git clone https://github.com/Automattic/wordpress-mcp.git cd wordpress-mcp -
Install Dependencies:
composer install --no-dev npm install && npm run build -
Activate the Plugin:
- Activate the WordPress MCP plugin on the "Plugins" page in the WordPress backend.
-
Configure MCP Features:
- Navigate to "Settings > WordPress MCP," enable MCP features, and configure authentication tokens.
-
Configure JWT Key:
Add the following towp-config.php:define('WPMCP_JWT_SECRET_KEY', 'your-secret-key'); define('WPMCP_DEBUG', true); // Enable debug logging -
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
- For use with
Configuration Notes
- Security: Never commit authentication tokens to version control systems; ensure
WPMCP_JWT_SECRET_KEYis stored securely. - Debugging: Enabling
WPMCP_DEBUGrecords 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-remoteto achieve full functionality.
Use Cases
The WordPress MCP project is suitable for the following scenarios:
-
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.
-
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.
-
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).
-
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:
-
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']; } }
- Add a new tool class in the
-
Register the Tool:
- Register the new tool during plugin initialization to ensure it is available through the MCP interface.
-
Refer to Existing Implementations:
- See the example code in the
includes/Tools/,includes/Resources/, andincludes/Prompts/directories.
- See the example code in the
Contributing Code
- Contribution Guidelines: Refer to the Contributing Guidelines in the repository to submit Pull Requests or report Issues.
- Testing Documentation: See
tests/README.mdto understand the testing process and ensure code quality. - License Requirements: All contributions must comply with the GPL v2 or later license.
Related Resources
- GitHub Repository: https://github.com/Automattic/wordpress-mcp
- Remote Client: https://github.com/Automattic/mcp-wordpress-remote
- WordPress MCP Official Website: https://mcp-wp.github.io