| 1 |
# MCP Adapter |
| 2 |
|
| 3 |
Part of the [](https://make.wordpress.org/ai/2025/07/17/ai-building-blocks**AI Building Blocks for WordPress** initiative](https://make.wordpress.org/ai/2025/07/17/ai-building-blocks](https://make.wordpress.org/ai/2025/07/17/ai-building-blocks) |
| 4 |
|
| 5 |
The official WordPress package for MCP integration that exposes WordPress abilities as [](https://modelcontextprotocol.ioModel Context Protocol (MCP)](https://modelcontextprotocol.io](https://modelcontextprotocol.io) tools, resources, and prompts for AI agents. |
| 6 |
|
| 7 |
[](https://deepwiki.com/WordPress/mcp-adapter](https://deepwiki.com/WordPress/mcp-adapter](https://deepwiki.com/WordPress/mcp-adapter) |
| 8 |
|
| 9 |
## Overview |
| 10 |
|
| 11 |
This adapter bridges WordPress's Abilities API with the [](https://modelcontextprotocol.io/specification/2025-11-25/MCP specification](https://modelcontextprotocol.io/specification/2025-11-25/](https://modelcontextprotocol.io/specification/2025-11-25/), providing a standardized way for AI agents to interact with WordPress functionality. It includes HTTP and STDIO transport support, comprehensive error handling, and an extensible architecture for custom integrations. |
| 12 |
|
| 13 |
## Features |
| 14 |
|
| 15 |
### Core Functionality |
| 16 |
|
| 17 |
- **Ability-to-MCP Conversion**: Automatically converts WordPress abilities into MCP tools, resources, and prompts |
| 18 |
- **Multi-Server Management**: Create and manage multiple MCP servers with unique configurations |
| 19 |
- **Extensible Transport Layer**: |
| 20 |
- **HTTP Transport**: Unified transport implementing [](https://modelcontextprotocol.io/specification/2025-11-25/basic/transportsMCP 2025-11-25 specification](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports) for HTTP-based communication |
| 21 |
- **STDIO Transport**: Process-based communication via standard input/output for local development and CLI integration |
| 22 |
- **Custom Transport Support**: Implement `McpTransportInterface` to create specialized communication protocols |
| 23 |
- **Multi-Transport Configuration**: Configure servers with multiple transport methods simultaneously |
| 24 |
- **Flexible Error Handling**: |
| 25 |
- **Built-in Error Handler**: Default WordPress-compatible error logging included |
| 26 |
- **Custom Error Handlers**: Implement `McpErrorHandlerInterface` for custom logging, monitoring, or notification |
| 27 |
systems |
| 28 |
- **Server-specific Handlers**: Different error handling strategies per MCP server |
| 29 |
- **Observability**: |
| 30 |
- **Built-in Observability**: Default zero-overhead metrics tracking with configurable handlers |
| 31 |
- **Custom Observability Handlers**: Implement `McpObservabilityHandlerInterface` for integration with monitoring |
| 32 |
systems |
| 33 |
- **Validation**: Built-in validation for tools, resources, and prompts with extensible validation rules |
| 34 |
- **Permission Control**: Granular permission checking for all exposed functionality with configurable [](docs/guides/transport-permissions.mdtransport permissions](docs/guides/transport-permissions.md](docs/guides/transport-permissions.md) |
| 35 |
|
| 36 |
### MCP Component Support |
| 37 |
|
| 38 |
- **[](https://modelcontextprotocol.io/specification/2025-06-18/server/tools.mdTools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools.md](https://modelcontextprotocol.io/specification/2025-06-18/server/tools.md)**: Convert WordPress abilities into executable MCP tools for AI agent interactions |
| 39 |
- **[](https://modelcontextprotocol.io/specification/2025-06-18/server/resources.mdResources](https://modelcontextprotocol.io/specification/2025-06-18/server/resources.md](https://modelcontextprotocol.io/specification/2025-06-18/server/resources.md)**: Expose WordPress data as MCP resources for contextual information access |
| 40 |
- **[](https://modelcontextprotocol.io/specification/2025-06-18/server/prompts.mdPrompts](https://modelcontextprotocol.io/specification/2025-06-18/server/prompts.md](https://modelcontextprotocol.io/specification/2025-06-18/server/prompts.md)**: Transform abilities into structured MCP prompts for AI guidance and templates |
| 41 |
- **Server Discovery**: Automatic registration and discovery of MCP servers following MCP protocol standards |
| 42 |
- **Built-in Abilities**: Core WordPress abilities for system introspection and ability management |
| 43 |
- **CLI Integration**: WP-CLI commands supporting STDIO transport as defined in MCP specification |
| 44 |
|
| 45 |
## Architecture |
| 46 |
|
| 47 |
For a full breakdown of the component structure, see the [](docs/architecture/overview.mdArchitecture Overview](docs/architecture/overview.md](docs/architecture/overview.md). |
| 48 |
|
| 49 |
## Dependencies |
| 50 |
|
| 51 |
- **PHP**: >= 7.4 |
| 52 |
- **WordPress**: >= 6.9 (includes the [](https://developer.wordpress.org/news/2025/11/introducing-the-wordpress-abilities-api/Abilities API](https://developer.wordpress.org/news/2025/11/introducing-the-wordpress-abilities-api/](https://developer.wordpress.org/news/2025/11/introducing-the-wordpress-abilities-api/) in core — no separate plugin) |
| 53 |
- **[](https://github.com/WordPress/php-mcp-schemaphp-mcp-schema](https://github.com/WordPress/php-mcp-schema](https://github.com/WordPress/php-mcp-schema)** (`^0.1.0`): Typed DTOs for MCP protocol types — installed automatically via Composer |
| 54 |
|
| 55 |
## Installation |
| 56 |
|
| 57 |
### As a WordPress Plugin (Recommended) |
| 58 |
|
| 59 |
MCP Adapter is designed to be installed as a WordPress plugin. To install you should download the latest stable release from the [](https://github.com/WordPress/mcp-adapter/releases/latestGitHub Releases page](https://github.com/WordPress/mcp-adapter/releases/latest](https://github.com/WordPress/mcp-adapter/releases/latest) and install it like any other WordPress plugin. |
| 60 |
|
| 61 |
#### With WP-CLI |
| 62 |
|
| 63 |
```bash |
| 64 |
wp plugin install https://github.com/WordPress/mcp-adapter/releases/latest/download/mcp-adapter.zip --activate |
| 65 |
``` |
| 66 |
|
| 67 |
#### With WP-Env |
| 68 |
|
| 69 |
```jsonc |
| 70 |
// .wp-env.json |
| 71 |
{ |
| 72 |
"$schema": "https://schemas.wp.org/trunk/wp-env.json", |
| 73 |
"plugins": [ |
| 74 |
"https://github.com/WordPress/mcp-adapter/releases/latest/download/mcp-adapter.zip" |
| 75 |
] |
| 76 |
} |
| 77 |
``` |
| 78 |
|
| 79 |
### As a Composer Library (for plugin developers) |
| 80 |
|
| 81 |
Plugin developers may wish to install MCP Adapter as a Composer dependency to integrate MCP functionality into their own plugins. |
| 82 |
|
| 83 |
```bash |
| 84 |
composer require wordpress/mcp-adapter |
| 85 |
``` |
| 86 |
|
| 87 |
#### Using Jetpack Autoloader (Highly Recommended) |
| 88 |
|
| 89 |
When multiple plugins use the MCP Adapter, it's highly recommended to use the [](https://github.com/Automattic/jetpack-autoloaderJetpack Autoloader](https://github.com/Automattic/jetpack-autoloader](https://github.com/Automattic/jetpack-autoloader) to prevent version conflicts. The Jetpack Autoloader ensures that only the latest version of shared packages is loaded, eliminating conflicts when different plugins use different versions of the same dependency. |
| 90 |
|
| 91 |
```bash |
| 92 |
composer require automattic/jetpack-autoloader |
| 93 |
``` |
| 94 |
|
| 95 |
Then load it in your main plugin file instead of the standard Composer autoloader: |
| 96 |
|
| 97 |
```php |
| 98 |
<?php |
| 99 |
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload_packages.php'; |
| 100 |
``` |
| 101 |
|
| 102 |
### Using MCP Adapter in Your Plugin |
| 103 |
|
| 104 |
Check availability and initialize on `plugins_loaded` so all plugins are available before the adapter starts: |
| 105 |
|
| 106 |
```php |
| 107 |
add_action( 'plugins_loaded', function() { |
| 108 |
if ( ! class_exists( 'WP\MCP\Core\McpAdapter' ) ) { |
| 109 |
// MCP Adapter is not active — show an admin notice or return early. |
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
\WP\MCP\Core\McpAdapter::instance(); |
| 114 |
} ); |
| 115 |
``` |
| 116 |
|
| 117 |
## Basic Usage |
| 118 |
|
| 119 |
The MCP Adapter automatically creates a default server that exposes registered WordPress abilities through a layered architecture. This provides immediate MCP functionality without requiring manual server configuration. |
| 120 |
|
| 121 |
**How it works:** |
| 122 |
- WordPress abilities registered via `wp_register_ability()` with `meta.public` set to `true` are discoverable and executable on the default server via its built-in adapter tools |
| 123 |
- Set `meta.mcp.public` explicitly to override the high-level setting for MCP only; `false` opts a public ability out, while `true` exposes an otherwise private ability to MCP |
| 124 |
- On the default server, public abilities are accessed through `mcp-adapter/discover-abilities`, `mcp-adapter/get-ability-info`, and `mcp-adapter/execute-ability` rather than being auto-registered individually in `tools/list` |
| 125 |
- Alternatively, abilities can be explicitly listed when creating a [](#creating-custom-mcp-serverscustom MCP server](#creating-custom-mcp-servers](#creating-custom-mcp-servers); in that case, they can be exposed directly as MCP tools, resources, or prompts without requiring the `meta.mcp.public` flag |
| 126 |
- The default server supports both HTTP and STDIO transports and supports multiple MCP protocol versions |
| 127 |
- Built-in error handling and observability are included |
| 128 |
- Access via HTTP: `/wp-json/mcp/mcp-adapter-default-server` |
| 129 |
- Access via STDIO: `wp mcp-adapter serve --server=mcp-adapter-default-server` |
| 130 |
|
| 131 |
<details> |
| 132 |
<summary><strong>Create a new ability (click to expand)</strong></summary> |
| 133 |
|
| 134 |
```php |
| 135 |
// Simply register a WordPress ability |
| 136 |
add_action( 'wp_abilities_api_init', function() { |
| 137 |
wp_register_ability( 'my-plugin/get-posts', [ |
| 138 |
'label' => 'Get Posts', |
| 139 |
'description' => 'Retrieve WordPress posts with optional filtering', |
| 140 |
'category' => 'site', |
| 141 |
'input_schema' => [ |
| 142 |
'type' => 'object', |
| 143 |
'properties' => [ |
| 144 |
'numberposts' => [ |
| 145 |
'type' => 'integer', |
| 146 |
'description' => 'Number of posts to retrieve', |
| 147 |
'default' => 5, |
| 148 |
'minimum' => 1, |
| 149 |
'maximum' => 100 |
| 150 |
], |
| 151 |
'post_status' => [ |
| 152 |
'type' => 'string', |
| 153 |
'description' => 'Post status to filter by', |
| 154 |
'enum' => ['publish', 'draft', 'private'], |
| 155 |
'default' => 'publish' |
| 156 |
] |
| 157 |
] |
| 158 |
], |
| 159 |
'output_schema' => [ |
| 160 |
'type' => 'array', |
| 161 |
'items' => [ |
| 162 |
'type' => 'object', |
| 163 |
'properties' => [ |
| 164 |
'ID' => ['type' => 'integer'], |
| 165 |
'post_title' => ['type' => 'string'], |
| 166 |
'post_content' => ['type' => 'string'], |
| 167 |
'post_date' => ['type' => 'string'], |
| 168 |
'post_author' => ['type' => 'string'] |
| 169 |
] |
| 170 |
] |
| 171 |
], |
| 172 |
'execute_callback' => function( $input ) { |
| 173 |
$args = [ |
| 174 |
'numberposts' => $input['numberposts'] ?? 5, |
| 175 |
'post_status' => $input['post_status'] ?? 'publish' |
| 176 |
]; |
| 177 |
return get_posts( $args ); |
| 178 |
}, |
| 179 |
'permission_callback' => function() { |
| 180 |
return current_user_can( 'read' ); |
| 181 |
}, |
| 182 |
'meta' => [ |
| 183 |
'public' => true, // Expose to clients, including the default MCP server |
| 184 |
], |
| 185 |
]); |
| 186 |
}); |
| 187 |
|
| 188 |
// With the meta.public flag, the ability is exposed through the default MCP server. |
| 189 |
// In the default server configuration, discover it via `discover-abilities` |
| 190 |
// and invoke it via `mcp-adapter/execute-ability` rather than expecting |
| 191 |
// it to appear as its own entry in `tools/list`. |
| 192 |
// To opt out of MCP while remaining public to other clients, explicitly set |
| 193 |
// meta.mcp.public to false. |
| 194 |
// To expose only through MCP, omit `meta.public` and set `meta.mcp.public` to true. |
| 195 |
// Without either public flag, abilities are only accessible through custom MCP |
| 196 |
// servers that explicitly list them. |
| 197 |
// Note: how far `meta.public` reaches depends on the WordPress version. WordPress |
| 198 |
// core starts applying `meta.public` to the REST API (`meta.show_in_rest`) in 7.1. On |
| 199 |
// WordPress 6.9 and 7.0, this adapter honors `meta.public` for MCP, but REST API |
| 200 |
// access still requires setting `meta.show_in_rest` to true. |
| 201 |
``` |
| 202 |
|
| 203 |
</details> |
| 204 |
|
| 205 |
For detailed information about creating WordPress abilities, see the [Abilities API developer documentation](https://developer.wordpress.org/news/2025/11/introducing-the-wordpress-abilities-api/). |
| 206 |
|
| 207 |
### Connecting to MCP Servers |
| 208 |
|
| 209 |
The MCP Adapter supports multiple connection methods. Here are examples for connecting with MCP clients: |
| 210 |
|
| 211 |
#### STDIO Transport (Local Development) |
| 212 |
|
| 213 |
For local development and testing, you can interact directly with MCP servers using WP-CLI commands: |
| 214 |
|
| 215 |
```bash |
| 216 |
# List all available MCP servers |
| 217 |
wp mcp-adapter list |
| 218 |
|
| 219 |
# Test the discover abilities tool to see all available WordPress abilities |
| 220 |
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"mcp-adapter-discover-abilities","arguments":{}}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server |
| 221 |
|
| 222 |
# Test listing available tools |
| 223 |
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server |
| 224 |
``` |
| 225 |
|
| 226 |
#### MCP Client Configuration |
| 227 |
|
| 228 |
Configure MCP clients (Claude Desktop, Claude Code, VS Code, Cursor, etc.) to connect to your WordPress MCP servers. |
| 229 |
|
| 230 |
<details> |
| 231 |
<summary><strong>STDIO Transport Configuration for local sites (click to expand)</strong></summary> |
| 232 |
|
| 233 |
```json |
| 234 |
{ |
| 235 |
"mcpServers": { |
| 236 |
"wordpress-default": { |
| 237 |
"command": "wp", |
| 238 |
"args": [ |
| 239 |
"--path=/path/to/your/wordpress/site", |
| 240 |
"mcp-adapter", |
| 241 |
"serve", |
| 242 |
"--server=mcp-adapter-default-server", |
| 243 |
"--user=admin" |
| 244 |
] |
| 245 |
}, |
| 246 |
"wordpress-custom": { |
| 247 |
"command": "wp", |
| 248 |
"args": [ |
| 249 |
"--path=/path/to/your/wordpress/site", |
| 250 |
"mcp-adapter", |
| 251 |
"serve", |
| 252 |
"--server=your-custom-server-id", |
| 253 |
"--user=admin" |
| 254 |
] |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
``` |
| 259 |
|
| 260 |
</details> |
| 261 |
|
| 262 |
<details> |
| 263 |
<summary><strong>HTTP Transport via Proxy (click to expand)</strong></summary> |
| 264 |
|
| 265 |
The [](https://www.npmjs.com/package/@automattic/mcp-wordpress-remote`@automattic/mcp-wordpress-remote`](https://www.npmjs.com/package/@automattic/mcp-wordpress-remote](https://www.npmjs.com/package/@automattic/mcp-wordpress-remote) proxy runs locally and translates STDIO-based MCP communication from AI clients into HTTP REST API calls that WordPress understands. Authentication uses [](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/WordPress Application Passwords](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/](https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/). |
| 266 |
|
| 267 |
```json |
| 268 |
{ |
| 269 |
"mcpServers": { |
| 270 |
"wordpress-http-default": { |
| 271 |
"command": "npx", |
| 272 |
"args": [ |
| 273 |
"-y", |
| 274 |
"@automattic/mcp-wordpress-remote@latest" |
| 275 |
], |
| 276 |
"env": { |
| 277 |
"WP_API_URL": "http://your-site.test/wp-json/mcp/mcp-adapter-default-server", |
| 278 |
"LOG_FILE": "/path/to/logs/mcp-adapter.log", |
| 279 |
"WP_API_USERNAME": "your-username", |
| 280 |
"WP_API_PASSWORD": "your-application-password" |
| 281 |
} |
| 282 |
}, |
| 283 |
"wordpress-http-custom": { |
| 284 |
"command": "npx", |
| 285 |
"args": [ |
| 286 |
"-y", |
| 287 |
"@automattic/mcp-wordpress-remote@latest" |
| 288 |
], |
| 289 |
"env": { |
| 290 |
"WP_API_URL": "http://your-site.test/wp-json/your-namespace/your-route", |
| 291 |
"LOG_FILE": "/path/to/logs/mcp-adapter.log", |
| 292 |
"WP_API_USERNAME": "your-username", |
| 293 |
"WP_API_PASSWORD": "your-application-password" |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
} |
| 298 |
``` |
| 299 |
|
| 300 |
</details> |
| 301 |
|
| 302 |
## Advanced Usage |
| 303 |
|
| 304 |
### Creating Custom MCP Servers |
| 305 |
|
| 306 |
For advanced use cases, you can create custom MCP servers with specific configurations: |
| 307 |
|
| 308 |
```php |
| 309 |
add_action( 'mcp_adapter_init', function( $adapter ) { |
| 310 |
$adapter->create_server( |
| 311 |
'my-server-id', // Unique server identifier |
| 312 |
'my-namespace', // REST API namespace |
| 313 |
'mcp', // REST API route |
| 314 |
'My MCP Server', // Server name |
| 315 |
'Description of my server', // Server description |
| 316 |
'v1.0.0', // Server version |
| 317 |
array( // Transport methods |
| 318 |
\WP\MCP\Transport\HttpTransport::class, |
| 319 |
), |
| 320 |
\WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler::class, // Error handler |
| 321 |
\WP\MCP\Infrastructure\Observability\NullMcpObservabilityHandler::class, // Observability handler |
| 322 |
array( 'my-plugin/my-ability' ), // Abilities to expose as tools |
| 323 |
array(), // Resources (optional) |
| 324 |
array() // Prompts (optional) |
| 325 |
); |
| 326 |
} ); |
| 327 |
``` |
| 328 |
|
| 329 |
### Custom Transport Implementation |
| 330 |
|
| 331 |
The MCP Adapter includes production-ready HTTP transports. For specialized requirements like custom authentication, message queues, or enterprise integrations, you can create custom transport protocols. |
| 332 |
|
| 333 |
See the [](docs/guides/custom-transports.mdCustom Transports Guide](docs/guides/custom-transports.md](docs/guides/custom-transports.md) for detailed implementation instructions. |
| 334 |
|
| 335 |
|
| 336 |
### Custom Transport Permissions |
| 337 |
|
| 338 |
The MCP Adapter supports custom authentication logic through transport permission callbacks. Instead of the default `is_user_logged_in()` check, you can implement custom authentication for your MCP servers. |
| 339 |
|
| 340 |
See the [](docs/guides/transport-permissions.mdTransport Permissions Guide](docs/guides/transport-permissions.md](docs/guides/transport-permissions.md) for detailed authentication patterns. |
| 341 |
|
| 342 |
### Custom Error Handler |
| 343 |
|
| 344 |
The MCP Adapter includes a default WordPress-compatible error handler, but you can implement custom error handling to integrate with existing logging systems, monitoring tools, or meet specific requirements. |
| 345 |
|
| 346 |
See the [](docs/guides/error-handling.mdError Handling Guide](docs/guides/error-handling.md](docs/guides/error-handling.md) for detailed implementation instructions. |
| 347 |
|
| 348 |
### Custom Observability Handler |
| 349 |
|
| 350 |
The MCP Adapter includes built-in observability for tracking metrics and events. You can implement custom observability handlers to integrate with monitoring systems, analytics platforms, or performance tracking tools. |
| 351 |
|
| 352 |
See the [](docs/guides/observability.mdObservability Guide](docs/guides/observability.md](docs/guides/observability.md) for detailed metrics tracking and custom handler implementation. |
| 353 |
|
| 354 |
## Migration |
| 355 |
|
| 356 |
- [](docs/migration/v0.5.0.mdMigration Guide: v0.5.0](docs/migration/v0.5.0.md](docs/migration/v0.5.0.md) — Breaking changes and upgrade instructions |
| 357 |
- [](docs/migration/v0.3.0.mdMigration Guide: v0.3.0](docs/migration/v0.3.0.md](docs/migration/v0.3.0.md) — Transport, observability, and hook name changes |
| 358 |
|
| 359 |
## License |
| 360 |
[](https://spdx.org/licenses/GPL-2.0-or-later.htmlGPL-2.0-or-later](https://spdx.org/licenses/GPL-2.0-or-later.html](https://spdx.org/licenses/GPL-2.0-or-later.html) |
| 361 |
|