includes
1 month ago
LICENSE.md
1 month ago
README.md
1 month ago
composer.json
1 month ago
composer.lock
1 month ago
mcp-adapter.php
1 month ago
package-lock.json
1 month ago
package.json
1 month ago
README.md
537 lines
| 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-06-18/MCP specification](https://modelcontextprotocol.io/specification/2025-06-18/](https://modelcontextprotocol.io/specification/2025-06-18/), 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-06-18/basic/transports.mdMCP 2025-06-18 specification](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports.md](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports.md) 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 | ## Understanding Abilities as MCP Components |
| 46 | |
| 47 | The MCP Adapter transforms WordPress abilities into MCP components: |
| 48 | |
| 49 | - **Tools**: WordPress abilities become executable MCP tools for AI agent interactions |
| 50 | - **Resources**: WordPress abilities expose data as MCP resources for contextual information |
| 51 | - **Prompts**: WordPress abilities provide structured MCP prompts for AI guidance |
| 52 | |
| 53 | For detailed information about MCP components, see the [](https://modelcontextprotocol.io/specification/2025-06-18/Model Context Protocol specification](https://modelcontextprotocol.io/specification/2025-06-18/](https://modelcontextprotocol.io/specification/2025-06-18/). |
| 54 | |
| 55 | |
| 56 | ## Architecture |
| 57 | |
| 58 | ### Component Overview |
| 59 | |
| 60 | ``` |
| 61 | ./includes/ |
| 62 | │ # Core system components |
| 63 | ├── Core/ |
| 64 | │ ├── McpAdapter.php # Main registry and server management |
| 65 | │ ├── McpServer.php # Individual server configuration |
| 66 | │ ├── McpComponentRegistry.php # Component registration and management |
| 67 | │ └── McpTransportFactory.php # Transport instantiation factory |
| 68 | │ |
| 69 | │ # Built-in abilities for MCP functionality |
| 70 | ├── Abilities/ |
| 71 | │ ├── DiscoverAbilitiesAbility.php # Ability discovery |
| 72 | │ ├── ExecuteAbilityAbility.php # Ability execution |
| 73 | │ └── GetAbilityInfoAbility.php # Ability introspection |
| 74 | │ |
| 75 | │ # CLI and STDIO transport support |
| 76 | ├── Cli/ |
| 77 | │ ├── McpCommand.php # WP-CLI commands |
| 78 | │ └── StdioServerBridge.php # STDIO transport bridge |
| 79 | │ |
| 80 | │ # Business logic and MCP components |
| 81 | ├── Domain/ |
| 82 | │ │ # Shared contracts |
| 83 | │ ├── Contracts/ |
| 84 | │ │ └── McpComponentInterface.php # Contract for MCP components |
| 85 | │ │ # Shared utilities |
| 86 | │ ├── Utils/ |
| 87 | │ │ ├── McpNameSanitizer.php # MCP name sanitization |
| 88 | │ │ ├── McpValidator.php # MCP name/URI/schema validation |
| 89 | │ │ ├── McpAnnotationMapper.php # Annotation mapping from abilities |
| 90 | │ │ ├── SchemaTransformer.php # Schema format transformation |
| 91 | │ │ ├── ContentBlockHelper.php # Content block DTO factory |
| 92 | │ │ └── AbilityArgumentNormalizer.php # Argument normalization |
| 93 | │ │ # MCP Tools implementation |
| 94 | │ ├── Tools/ |
| 95 | │ │ ├── McpTool.php # Base tool class |
| 96 | │ │ ├── RegisterAbilityAsMcpTool.php # Ability-to-tool conversion |
| 97 | │ │ └── McpToolValidator.php # Tool validation |
| 98 | │ │ # MCP Resources implementation |
| 99 | │ ├── Resources/ |
| 100 | │ │ ├── McpResource.php # Base resource class |
| 101 | │ │ ├── RegisterAbilityAsMcpResource.php # Ability-to-resource conversion |
| 102 | │ │ └── McpResourceValidator.php # Resource validation |
| 103 | │ │ # MCP Prompts implementation |
| 104 | │ └── Prompts/ |
| 105 | │ ├── Contracts/ # Prompt interfaces |
| 106 | │ │ └── McpPromptBuilderInterface.php # Prompt builder interface |
| 107 | │ ├── McpPrompt.php # Base prompt class |
| 108 | │ ├── McpPromptBuilder.php # Prompt builder implementation |
| 109 | │ ├── McpPromptValidator.php # Prompt validation |
| 110 | │ └── RegisterAbilityAsMcpPrompt.php # Ability-to-prompt conversion |
| 111 | │ |
| 112 | │ # Request processing handlers |
| 113 | ├── Handlers/ |
| 114 | │ ├── HandlerHelperTrait.php # Shared handler utilities |
| 115 | │ ├── Initialize/ # Initialization handlers |
| 116 | │ ├── Tools/ # Tool request handlers |
| 117 | │ ├── Resources/ # Resource request handlers |
| 118 | │ ├── Prompts/ # Prompt request handlers |
| 119 | │ └── System/ # System request handlers |
| 120 | │ |
| 121 | │ # Infrastructure concerns |
| 122 | ├── Infrastructure/ |
| 123 | │ │ # Error handling system |
| 124 | │ ├── ErrorHandling/ |
| 125 | │ │ ├── Contracts/ # Error handling interfaces |
| 126 | │ │ │ └── McpErrorHandlerInterface.php # Error handler interface |
| 127 | │ │ ├── ErrorLogMcpErrorHandler.php # Default error handler |
| 128 | │ │ ├── NullMcpErrorHandler.php # Null object pattern |
| 129 | │ │ └── McpErrorFactory.php # Error response factory |
| 130 | │ │ # Monitoring and observability |
| 131 | │ └── Observability/ |
| 132 | │ ├── Contracts/ # Observability interfaces |
| 133 | │ │ └── McpObservabilityHandlerInterface.php # Observability interface |
| 134 | │ ├── ErrorLogMcpObservabilityHandler.php # Default handler |
| 135 | │ ├── NullMcpObservabilityHandler.php # Null object pattern |
| 136 | │ ├── McpObservabilityHelperTrait.php # Helper trait |
| 137 | │ ├── ConsoleObservabilityHandler.php # Console output handler |
| 138 | │ └── FailureReason.php # Standardized failure reasons |
| 139 | │ |
| 140 | │ # Transport layer implementations |
| 141 | ├── Transport/ |
| 142 | │ ├── Contracts/ |
| 143 | │ │ ├── McpTransportInterface.php # Base transport interface |
| 144 | │ │ └── McpRestTransportInterface.php # REST transport interface |
| 145 | │ ├── HttpTransport.php # Unified HTTP transport (MCP 2025-06-18) |
| 146 | │ │ # Transport infrastructure |
| 147 | │ └── Infrastructure/ |
| 148 | │ ├── HttpRequestContext.php # HTTP request context |
| 149 | │ ├── HttpRequestHandler.php # HTTP request processing |
| 150 | │ ├── HttpSessionValidator.php # Session validation |
| 151 | │ ├── JsonRpcResponseBuilder.php # JSON-RPC response building |
| 152 | │ ├── McpTransportContext.php # Transport context |
| 153 | │ ├── RequestRouter.php # Request routing |
| 154 | │ └── SessionManager.php # Session management |
| 155 | │ |
| 156 | │ # Server factories |
| 157 | ├── Servers/ |
| 158 | └── DefaultServerFactory.php # Default server creation |
| 159 | ``` |
| 160 | |
| 161 | ### Key Classes |
| 162 | |
| 163 | #### `McpAdapter` |
| 164 | |
| 165 | The main registry class that manages multiple MCP servers: |
| 166 | |
| 167 | - **Singleton Pattern**: Ensures single instance across the application |
| 168 | - **Server Management**: Create, configure, and retrieve MCP servers |
| 169 | - **Initialization**: Handles WordPress integration and action hooks |
| 170 | - **REST API Integration**: Automatically integrates with WordPress REST API |
| 171 | |
| 172 | #### `McpServer` |
| 173 | |
| 174 | Individual server management with comprehensive configuration: |
| 175 | |
| 176 | - **Server Identity**: Unique ID, namespace, route, name, and description |
| 177 | - **Component Registration**: Tools, resources, and prompts management |
| 178 | - **Transport Configuration**: Multiple transport method support |
| 179 | - **Error Handling**: Server-specific error handling and logging |
| 180 | - **Validation**: Built-in validation for all registered components |
| 181 | |
| 182 | ## Dependencies |
| 183 | |
| 184 | ### Required Dependencies |
| 185 | |
| 186 | - **PHP**: >= 7.4 |
| 187 | - **WordPress**: >= 6.8 (6.9+ recommended) |
| 188 | - **[](https://make.wordpress.org/core/2025/11/10/abilities-api-in-wordpress-6-9/WordPress Abilities API](https://make.wordpress.org/core/2025/11/10/abilities-api-in-wordpress-6-9/](https://make.wordpress.org/core/2025/11/10/abilities-api-in-wordpress-6-9/)**: Included in WordPress core since 6.9. For WordPress 6.8, install the [](https://github.com/WordPress/abilities-apiAbilities API plugin](https://github.com/WordPress/abilities-api](https://github.com/WordPress/abilities-api) separately (note: the plugin repository was archived in February 2026). |
| 189 | - **[](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 (MCP 2025-11-25) |
| 190 | |
| 191 | ### WordPress Abilities API Integration |
| 192 | |
| 193 | Since WordPress 6.9, the [](https://make.wordpress.org/core/2025/11/10/abilities-api-in-wordpress-6-9/Abilities API](https://make.wordpress.org/core/2025/11/10/abilities-api-in-wordpress-6-9/](https://make.wordpress.org/core/2025/11/10/abilities-api-in-wordpress-6-9/) is a core API and does not require a separate plugin. |
| 194 | |
| 195 | The Abilities API provides: |
| 196 | |
| 197 | - Standardized ability registration (`wp_register_ability()`) |
| 198 | - Ability retrieval and management (`wp_get_ability()`) |
| 199 | - Schema definition for inputs and outputs |
| 200 | - Permission callback system |
| 201 | - Execute callback system |
| 202 | |
| 203 | ## Installation |
| 204 | |
| 205 | ### With Composer (Primary Installation Method) |
| 206 | |
| 207 | The MCP Adapter is designed to be installed as a Composer package. This is the primary and recommended installation method: |
| 208 | |
| 209 | ```bash |
| 210 | composer require wordpress/mcp-adapter |
| 211 | ``` |
| 212 | |
| 213 | > **Note:** On WordPress 6.8, you must also install the Abilities API separately: `composer require wordpress/abilities-api wordpress/mcp-adapter`. On WordPress 6.9+, the Abilities API is built into core and does not need to be installed. |
| 214 | |
| 215 | #### Using Jetpack Autoloader (Highly Recommended) |
| 216 | |
| 217 | 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. |
| 218 | |
| 219 | Add the Jetpack Autoloader to your project: |
| 220 | |
| 221 | ```bash |
| 222 | composer require automattic/jetpack-autoloader |
| 223 | ``` |
| 224 | |
| 225 | Then load it in your main plugin file instead of the standard Composer autoloader: |
| 226 | |
| 227 | ```php |
| 228 | <?php |
| 229 | // Load the Jetpack autoloader instead of vendor/autoload.php |
| 230 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload_packages.php'; |
| 231 | ``` |
| 232 | |
| 233 | **Benefits of using Jetpack Autoloader:** |
| 234 | - **Version Conflict Resolution**: Automatically loads the latest version of shared packages |
| 235 | - **Plugin Compatibility**: Prevents errors when multiple plugins use different versions of MCP Adapter |
| 236 | - **WordPress Optimized**: Designed specifically for WordPress plugin development |
| 237 | - **Automatic Management**: No manual intervention needed when plugins update their dependencies |
| 238 | |
| 239 | ### As a Plugin (Alternative Method) |
| 240 | |
| 241 | Alternatively, you can install the MCP Adapter as a traditional WordPress plugin, though the Composer package method is preferred for most use cases. |
| 242 | |
| 243 | #### From GitHub Releases |
| 244 | |
| 245 | 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). |
| 246 | |
| 247 | #### Development Version (Git Clone) |
| 248 | |
| 249 | For the latest development version or to contribute to the project: |
| 250 | |
| 251 | ```bash |
| 252 | # Clone the repository |
| 253 | git clone https://github.com/WordPress/mcp-adapter.git wp-content/plugins/mcp-adapter |
| 254 | |
| 255 | # Navigate to the plugin directory |
| 256 | cd wp-content/plugins/mcp-adapter |
| 257 | |
| 258 | # Install dependencies |
| 259 | composer install |
| 260 | ``` |
| 261 | |
| 262 | This will give you the latest development version from the `trunk` branch with all dependencies installed. |
| 263 | |
| 264 | #### With WP-Env |
| 265 | |
| 266 | ```jsonc |
| 267 | // .wp-env.json |
| 268 | { |
| 269 | "$schema": "https://schemas.wp.org/trunk/wp-env.json", |
| 270 | // ... other config ... |
| 271 | "plugins": [ |
| 272 | "WordPress/mcp-adapter", |
| 273 | // ... other plugins ... |
| 274 | ], |
| 275 | // ... more config ... |
| 276 | } |
| 277 | ``` |
| 278 | |
| 279 | > **Note:** On WordPress 6.8, also add `"WordPress/abilities-api"` to the plugins array. On WordPress 6.9+, the Abilities API is included in core. |
| 280 | |
| 281 | ### Using MCP Adapter in Your Plugin |
| 282 | |
| 283 | Using the MCP Adapter in your plugin is straightforward, just check availability and instantiate: |
| 284 | |
| 285 | ```php |
| 286 | use WP\MCP\Core\McpAdapter; |
| 287 | |
| 288 | // 1. Check if MCP Adapter is available |
| 289 | if ( ! class_exists( McpAdapter::class ) ) { |
| 290 | // Handle missing dependency (show admin notice, etc.) |
| 291 | return; |
| 292 | } |
| 293 | |
| 294 | // 2. Initialize the adapter |
| 295 | McpAdapter::instance(); |
| 296 | // That's it! |
| 297 | ``` |
| 298 | |
| 299 | ## Basic Usage |
| 300 | |
| 301 | 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. |
| 302 | |
| 303 | **How it works:** |
| 304 | - WordPress abilities registered via `wp_register_ability()` with the `meta.mcp.public` flag set to `true` are discoverable and executable on the default server via its built-in adapter tools |
| 305 | - 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` |
| 306 | - Alternatively, abilities can be explicitly listed when creating a [custom MCP server](#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 |
| 307 | - The default server supports both HTTP and STDIO transports and supports multiple MCP protocol versions |
| 308 | - Built-in error handling and observability are included |
| 309 | - Access via HTTP: `/wp-json/mcp/mcp-adapter-default-server` |
| 310 | - Access via STDIO: `wp mcp-adapter serve --server=mcp-adapter-default-server` |
| 311 | |
| 312 | <details> |
| 313 | <summary><strong>Create a new ability (click to expand)</strong></summary> |
| 314 | |
| 315 | ```php |
| 316 | // Simply register a WordPress ability |
| 317 | add_action( 'wp_abilities_api_init', function() { |
| 318 | wp_register_ability( 'my-plugin/get-posts', [ |
| 319 | 'label' => 'Get Posts', |
| 320 | 'description' => 'Retrieve WordPress posts with optional filtering', |
| 321 | 'category' => 'site', |
| 322 | 'input_schema' => [ |
| 323 | 'type' => 'object', |
| 324 | 'properties' => [ |
| 325 | 'numberposts' => [ |
| 326 | 'type' => 'integer', |
| 327 | 'description' => 'Number of posts to retrieve', |
| 328 | 'default' => 5, |
| 329 | 'minimum' => 1, |
| 330 | 'maximum' => 100 |
| 331 | ], |
| 332 | 'post_status' => [ |
| 333 | 'type' => 'string', |
| 334 | 'description' => 'Post status to filter by', |
| 335 | 'enum' => ['publish', 'draft', 'private'], |
| 336 | 'default' => 'publish' |
| 337 | ] |
| 338 | ] |
| 339 | ], |
| 340 | 'output_schema' => [ |
| 341 | 'type' => 'array', |
| 342 | 'items' => [ |
| 343 | 'type' => 'object', |
| 344 | 'properties' => [ |
| 345 | 'ID' => ['type' => 'integer'], |
| 346 | 'post_title' => ['type' => 'string'], |
| 347 | 'post_content' => ['type' => 'string'], |
| 348 | 'post_date' => ['type' => 'string'], |
| 349 | 'post_author' => ['type' => 'string'] |
| 350 | ] |
| 351 | ] |
| 352 | ], |
| 353 | 'execute_callback' => function( $input ) { |
| 354 | $args = [ |
| 355 | 'numberposts' => $input['numberposts'] ?? 5, |
| 356 | 'post_status' => $input['post_status'] ?? 'publish' |
| 357 | ]; |
| 358 | return get_posts( $args ); |
| 359 | }, |
| 360 | 'permission_callback' => function() { |
| 361 | return current_user_can( 'read' ); |
| 362 | }, |
| 363 | 'meta' => [ |
| 364 | 'mcp' => [ |
| 365 | 'public' => true, // Required for default MCP server access |
| 366 | ], |
| 367 | ], |
| 368 | ]); |
| 369 | }); |
| 370 | |
| 371 | // With the meta.mcp.public flag, the ability is exposed through the default MCP server. |
| 372 | // In the default server configuration, discover it via `discover-abilities` |
| 373 | // and invoke it via `mcp-adapter/execute-ability` rather than expecting |
| 374 | // it to appear as its own entry in `tools/list`. |
| 375 | // Without the meta.mcp.public flag, abilities are only accessible |
| 376 | // through custom MCP servers that explicitly list them. |
| 377 | ``` |
| 378 | |
| 379 | </details> |
| 380 | |
| 381 | 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/). |
| 382 | |
| 383 | ### Connecting to MCP Servers |
| 384 | |
| 385 | The MCP Adapter supports multiple connection methods. Here are examples for connecting with MCP clients: |
| 386 | |
| 387 | #### STDIO Transport (Local Development) |
| 388 | |
| 389 | For local development and testing, you can interact directly with MCP servers using WP-CLI commands: |
| 390 | |
| 391 | ```bash |
| 392 | # List all available MCP servers |
| 393 | wp mcp-adapter list |
| 394 | |
| 395 | # Test the discover abilities tool to see all available WordPress abilities |
| 396 | 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 |
| 397 | |
| 398 | # Test listing available tools |
| 399 | echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server |
| 400 | ``` |
| 401 | |
| 402 | #### MCP Client Configuration |
| 403 | |
| 404 | Configure MCP clients (Claude Desktop, Claude Code, VS Code, Cursor, etc.) to connect to your WordPress MCP servers. |
| 405 | |
| 406 | <details> |
| 407 | <summary><strong>STDIO Transport Configuration for local sites (click to expand)</strong></summary> |
| 408 | |
| 409 | ```json |
| 410 | { |
| 411 | "mcpServers": { |
| 412 | "wordpress-default": { |
| 413 | "command": "wp", |
| 414 | "args": [ |
| 415 | "--path=/path/to/your/wordpress/site", |
| 416 | "mcp-adapter", |
| 417 | "serve", |
| 418 | "--server=mcp-adapter-default-server", |
| 419 | "--user=admin" |
| 420 | ] |
| 421 | }, |
| 422 | "wordpress-custom": { |
| 423 | "command": "wp", |
| 424 | "args": [ |
| 425 | "--path=/path/to/your/wordpress/site", |
| 426 | "mcp-adapter", |
| 427 | "serve", |
| 428 | "--server=your-custom-server-id", |
| 429 | "--user=admin" |
| 430 | ] |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | ``` |
| 435 | |
| 436 | </details> |
| 437 | |
| 438 | <details> |
| 439 | <summary><strong>HTTP Transport via Proxy (click to expand)</strong></summary> |
| 440 | |
| 441 | 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/). |
| 442 | |
| 443 | ```json |
| 444 | { |
| 445 | "mcpServers": { |
| 446 | "wordpress-http-default": { |
| 447 | "command": "npx", |
| 448 | "args": [ |
| 449 | "-y", |
| 450 | "@automattic/mcp-wordpress-remote@latest" |
| 451 | ], |
| 452 | "env": { |
| 453 | "WP_API_URL": "http://your-site.test/wp-json/mcp/mcp-adapter-default-server", |
| 454 | "LOG_FILE": "/path/to/logs/mcp-adapter.log", |
| 455 | "WP_API_USERNAME": "your-username", |
| 456 | "WP_API_PASSWORD": "your-application-password" |
| 457 | } |
| 458 | }, |
| 459 | "wordpress-http-custom": { |
| 460 | "command": "npx", |
| 461 | "args": [ |
| 462 | "-y", |
| 463 | "@automattic/mcp-wordpress-remote@latest" |
| 464 | ], |
| 465 | "env": { |
| 466 | "WP_API_URL": "http://your-site.test/wp-json/your-namespace/your-route", |
| 467 | "LOG_FILE": "/path/to/logs/mcp-adapter.log", |
| 468 | "WP_API_USERNAME": "your-username", |
| 469 | "WP_API_PASSWORD": "your-application-password" |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | ``` |
| 475 | |
| 476 | </details> |
| 477 | |
| 478 | ## Advanced Usage |
| 479 | |
| 480 | ### Creating Custom MCP Servers |
| 481 | |
| 482 | For advanced use cases, you can create custom MCP servers with specific configurations: |
| 483 | |
| 484 | ```php |
| 485 | add_action('mcp_adapter_init', function($adapter) { |
| 486 | $adapter->create_server( |
| 487 | 'my-server-id', // Unique server identifier |
| 488 | 'my-namespace', // REST API namespace |
| 489 | 'mcp', // REST API route |
| 490 | 'My MCP Server', // Server name |
| 491 | 'Description of my server', // Server description |
| 492 | 'v1.0.0', // Server version |
| 493 | [ // Transport methods |
| 494 | \WP\MCP\Transport\HttpTransport::class, // Recommended: MCP 2025-06-18 compliant |
| 495 | ], |
| 496 | \WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler::class, // Error handler |
| 497 | \WP\MCP\Infrastructure\Observability\NullMcpObservabilityHandler::class, // Observability handler |
| 498 | ['my-plugin/my-ability'], // Abilities to expose as tools |
| 499 | [], // Resources (optional) |
| 500 | [], // Prompts (optional) |
| 501 | ); |
| 502 | }); |
| 503 | ``` |
| 504 | |
| 505 | ### Custom Transport Implementation |
| 506 | |
| 507 | 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. |
| 508 | |
| 509 | See the [](docs/guides/custom-transports.mdCustom Transports Guide](docs/guides/custom-transports.md](docs/guides/custom-transports.md) for detailed implementation instructions. |
| 510 | |
| 511 | |
| 512 | ### Custom Transport Permissions |
| 513 | |
| 514 | 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. |
| 515 | |
| 516 | See the [](docs/guides/transport-permissions.mdTransport Permissions Guide](docs/guides/transport-permissions.md](docs/guides/transport-permissions.md) for detailed authentication patterns. |
| 517 | |
| 518 | ### Custom Error Handler |
| 519 | |
| 520 | 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. |
| 521 | |
| 522 | See the [](docs/guides/error-handling.mdError Handling Guide](docs/guides/error-handling.md](docs/guides/error-handling.md) for detailed implementation instructions. |
| 523 | |
| 524 | ### Custom Observability Handler |
| 525 | |
| 526 | 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. |
| 527 | |
| 528 | See the [](docs/guides/observability.mdObservability Guide](docs/guides/observability.md](docs/guides/observability.md) for detailed metrics tracking and custom handler implementation. |
| 529 | |
| 530 | ## Migration |
| 531 | |
| 532 | - [](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 |
| 533 | - [](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 |
| 534 | |
| 535 | ## License |
| 536 | [](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) |
| 537 |