@myea/wordpress-mcp-handler
v1.0.0
Published
Advanced WordPress MCP request handler with intelligent search, multi-locale support, and comprehensive content management capabilities
Maintainers
Readme
WordPress MCP Handler
Advanced WordPress Model Context Protocol (MCP) server with intelligent search, multi-locale support, and comprehensive content management capabilities.
Features
- Complete WordPress REST API Integration: Full support for posts, pages, media, users, categories, tags, and comments
- Enhanced Search Capabilities: Multi-strategy search with fuzzy matching and comprehensive content discovery
- Authentication Support: Application passwords, JWT, and basic authentication
- Error Handling & Retry Logic: Robust error handling with automatic retries for recoverable errors
- TypeScript Support: Fully typed interfaces for all WordPress operations
- MCP Protocol Compliance: Standard JSON-RPC interface for AI agent integration
Quick Start
1. Installation
cd wordpress-mcp
npm install2. Environment Setup
Copy the example environment file and configure your WordPress site:
cp .env.example .envEdit .env with your WordPress site details:
WP_HOST=https://your-wordpress-site.com
WP_USERNAME=admin
WP_APPLICATION_PASSWORD=xxxx-xxxx-xxxx-xxxx3. Generate WordPress Application Password
- Go to your WordPress admin: Users → Profile
- Scroll down to Application Passwords
- Add a new application password for "MCP Handler"
- Copy the generated password to your
.envfile
4. Build and Run
npm run build
npm startAvailable MCP Methods
Connection & Info
testConnection()- Test WordPress connectivitygetSiteInfo()- Get site information and settingsgetContentStats()- Get content statistics
Posts Management
getPosts(params)- Get posts with search/filter optionsgetPost(id)- Get specific postcreatePost(data)- Create new postupdatePost(id, data)- Update existing postdeletePost(id, force?)- Delete post
Pages Management
getPages(params)- Get pages with search/filter optionsgetPage(id)- Get specific pagecreatePage(data)- Create new pageupdatePage(id, data)- Update existing pagedeletePage(id, force?)- Delete page
Media Management
getMedia(params)- Get media itemsgetMediaItem(id)- Get specific media itemuploadMedia(file, metadata)- Upload media file
Taxonomies
getCategories(params)- Get categoriesgetTags(params)- Get tagscreateCategory(name, description?, parent?)- Create categorycreateTag(name, description?)- Create tag
Users
getUsers(params)- Get usersgetCurrentUser()- Get current authenticated user
Comments
getComments(params)- Get commentscreateComment(post, content, author?)- Create comment
Search Operations
searchContent(query, params?)- Basic WordPress searchenhancedSearch(query, options?)- Multi-content-type searchcomprehensiveSearch(term, options?)- Advanced search with fuzzy matching
Utilities
getContentBySlug(slug, type?)- Get content by sluglistMethods()- List all available methods
Usage Examples
Creating a Blog Post
const result = await mcpHandler.handleRequest('createPost', {
title: 'My New Blog Post',
content: 'This is the content of my blog post.',
status: 'publish',
categories: [1, 3],
tags: [5, 7],
meta: {
custom_field: 'custom_value'
}
});Searching Content
// Basic search
const searchResult = await mcpHandler.handleRequest('searchContent', {
query: 'artificial intelligence',
per_page: 10
});
// Enhanced search across multiple content types
const enhancedResult = await mcpHandler.handleRequest('enhancedSearch', {
query: 'AI technology',
options: {
includePosts: true,
includePages: true,
includeMedia: false
}
});
// Comprehensive search with fuzzy matching
const comprehensiveResult = await mcpHandler.handleRequest('comprehensiveSearch', {
searchTerm: 'machine learning',
options: {
fuzzyMatching: true,
includeMeta: true
}
});Uploading Media
const uploadResult = await mcpHandler.handleRequest('uploadMedia', {
file: fileBuffer,
filename: 'image.jpg',
mimeType: 'image/jpeg',
title: 'My Image',
alt_text: 'Description of the image',
caption: 'Image caption'
});Configuration
Authentication Types
Application Passwords (Recommended)
WP_AUTH_TYPE=application_password
WP_USERNAME=admin
WP_APPLICATION_PASSWORD=xxxx-xxxx-xxxx-xxxxBasic Authentication
WP_AUTH_TYPE=basic
WP_USERNAME=admin
WP_PASSWORD=your-passwordJWT Authentication
WP_AUTH_TYPE=jwt
WP_JWT_SECRET=your-secret
WP_JWT_TOKEN=your-tokenContent Configuration
# Allowed post types
WP_ALLOWED_POST_TYPES=post,page,attachment,custom_type
# Allowed post statuses
WP_ALLOWED_STATUSES=publish,draft,private,pending
# Upload settings
WP_MAX_UPLOAD_SIZE=10485760
WP_ALLOWED_MIME_TYPES=image/jpeg,image/png,application/pdfArchitecture
The WordPress MCP follows a layered architecture:
┌─────────────────────────────────────────────────────────────────┐
│ MCP Server │
│ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ STDIO MCP │ │ HTTP MCP │ │ WebSocket │ │
│ └─────────────────┘ └─────────────────┘ └─────────────────┘ │
├─────────────────────────────────────────────────────────────────┤
│ Request Handler │
│ ┌─────────────────────────────────────────────────────────────┤
│ │ • Method routing • Parameter validation │
│ │ • Error handling • Response formatting │
│ └─────────────────────────────────────────────────────────────┤
├─────────────────────────────────────────────────────────────────┤
│ WordPress Connector │
│ ┌─────────────────────────────────────────────────────────────┤
│ │ • REST API client • Authentication │
│ │ • Retry logic • Request/response handling │
│ │ └────────────────────────────────────────────────────────────┤
├─────────────────────────────────────────────────────────────────┤
│ WordPress REST API │
└─────────────────────────────────────────────────────────────────┘Error Handling
The WordPress MCP includes comprehensive error handling:
- Connection Errors: Automatic retry with exponential backoff
- Authentication Errors: Clear error messages with troubleshooting hints
- Rate Limiting: Automatic retry with proper delays
- Validation Errors: Parameter validation with detailed error messages
- WordPress Errors: WordPress-specific error code mapping
Testing
# Run all tests
npm test
# Run specific test suites
npm run test:unit
npm run test:integration
# Run tests with coverage
npm run test:coverageDevelopment
Project Structure
wordpress-mcp/
├── src/
│ ├── wordpress-config.ts # Configuration management
│ ├── error-handler.ts # Error handling utilities
│ ├── wordpress-connector.ts # WordPress REST API client
│ ├── mcp-handler.ts # MCP request handler
│ ├── mcp-server.ts # Main MCP server
│ └── index.ts # Package exports
├── tests/ # Test files
├── package.json
├── tsconfig.json
└── README.mdBuilding
npm run buildDevelopment Mode
npm run devDocker Support
Using Docker Compose
version: '3.8'
services:
wordpress:
image: wordpress:latest
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
wordpress-mcp:
build: .
ports:
- "3000:3000"
environment:
WP_HOST: http://wordpress:80
WP_USERNAME: admin
WP_APPLICATION_PASSWORD: your-app-password
depends_on:
- wordpress
db:
image: mysql:8.0
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: rootpasswordIntegration with AI Agents
Claude Desktop
Add to your Claude Desktop configuration:
{
"mcpServers": {
"wordpress": {
"command": "node",
"args": ["/path/to/wordpress-mcp/build/mcp-server.js"],
"env": {
"WP_HOST": "https://your-wordpress-site.com",
"WP_USERNAME": "admin",
"WP_APPLICATION_PASSWORD": "xxxx-xxxx-xxxx-xxxx"
}
}
}
}Custom Integration
import { WordPressConnector, WordPressMCPRequestHandler } from '@myea/wordpress-mcp-handler';
const connector = new WordPressConnector();
const handler = new WordPressMCPRequestHandler(connector);
// Use the handler in your application
const result = await handler.handleRequest('getPosts', { per_page: 5 });Security Considerations
- Use Application Passwords: More secure than basic authentication
- HTTPS Only: Always use HTTPS for production
- Rate Limiting: Built-in rate limiting and retry logic
- Input Validation: All inputs are validated and sanitized
- Error Sanitization: Sensitive information is not exposed in errors
Troubleshooting
Connection Issues
- Check WordPress REST API: Visit
https://your-site.com/wp-json/to verify the API is accessible - Verify Credentials: Ensure your username and application password are correct
- Check Permissions: Make sure your user has appropriate permissions for the operations you're trying to perform
Authentication Issues
- Application Passwords: Ensure application passwords are enabled on your WordPress site
- User Permissions: Verify the user has the necessary capabilities
- Plugin Conflicts: Some security plugins may block REST API access
Common Error Codes
CONNECTION_FAILED: Cannot connect to WordPress - check host and networkAUTHENTICATION_FAILED: Invalid credentials - check username/passwordINSUFFICIENT_PERMISSIONS: User lacks required permissionsPOST_NOT_FOUND: Requested content doesn't existRATE_LIMITED: Too many requests - automatic retry will occur
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
License
MIT License. See LICENSE file for details.
Support
For issues and questions:
- GitHub Issues: Report bugs and request features
- Documentation: View full documentation
