Views
No views yet
McpTransportInterface to create specialized communication protocolsMcpErrorHandlerInterface for custom logging, monitoring, or notification
systemsMcpObservabilityHandlerInterface for integration with monitoring
systems./includes/
│ # Core system components
├── Core/
│ ├── McpAdapter.php # Main registry and server management
│ ├── McpServer.php # Individual server configuration
│ ├── McpComponentRegistry.php # Component registration and management
│ └── McpTransportFactory.php # Transport instantiation factory
│
│ # Built-in abilities for MCP functionality
├── Abilities/
│ ├── DiscoverAbilitiesAbility.php # Ability discovery
│ ├── ExecuteAbilityAbility.php # Ability execution
│ └── GetAbilityInfoAbility.php # Ability introspection
│
│ # CLI and STDIO transport support
├── Cli/
│ ├── McpCommand.php # WP-CLI commands
│ └── StdioServerBridge.php # STDIO transport bridge
│
│ # Business logic and MCP components
├── Domain/
│ │ # MCP Tools implementation
│ ├── Tools/
│ │ ├── McpTool.php # Base tool class
│ │ ├── RegisterAbilityAsMcpTool.php # Ability-to-tool conversion
│ │ └── McpToolValidator.php # Tool validation
│ │ # MCP Resources implementation
│ ├── Resources/
│ │ ├── McpResource.php # Base resource class
│ │ ├── RegisterAbilityAsMcpResource.php # Ability-to-resource conversion
│ │ └── McpResourceValidator.php # Resource validation
│ │ # MCP Prompts implementation
│ └── Prompts/
│ ├── Contracts/ # Prompt interfaces
│ │ └── McpPromptBuilderInterface.php # Prompt builder interface
│ ├── McpPrompt.php # Base prompt class
│ ├── McpPromptBuilder.php # Prompt builder implementation
│ ├── McpPromptValidator.php # Prompt validation
│ └── RegisterAbilityAsMcpPrompt.php # Ability-to-prompt conversion
│
│ # Request processing handlers
├── Handlers/
│ ├── HandlerHelperTrait.php # Shared handler utilities
│ ├── Initialize/ # Initialization handlers
│ ├── Tools/ # Tool request handlers
│ ├── Resources/ # Resource request handlers
│ ├── Prompts/ # Prompt request handlers
│ └── System/ # System request handlers
│
│ # Infrastructure concerns
├── Infrastructure/
│ │ # Error handling system
│ ├── ErrorHandling/
│ │ ├── Contracts/ # Error handling interfaces
│ │ │ └── McpErrorHandlerInterface.php # Error handler interface
│ │ ├── ErrorLogMcpErrorHandler.php # Default error handler
│ │ ├── NullMcpErrorHandler.php # Null object pattern
│ │ └── McpErrorFactory.php # Error response factory
│ │ # Monitoring and observability
│ └── Observability/
│ ├── Contracts/ # Observability interfaces
│ │ └── McpObservabilityHandlerInterface.php # Observability interface
│ ├── ErrorLogMcpObservabilityHandler.php # Default handler
│ ├── NullMcpObservabilityHandler.php # Null object pattern
│ └── McpObservabilityHelperTrait.php # Helper trait
│
│ # Transport layer implementations
├─── Transport/
│ ├── Contracts/
│ │ ├── McpTransportInterface.php # Base transport interface
│ │ └── McpRestTransportInterface.php # REST transport interface
│ ├── HttpTransport.php # Unified HTTP transport (MCP 2025-06-18)
│ │ # Transport infrastructure
│ └── Infrastructure/
│ ├── HttpRequestContext.php # HTTP request context
│ ├── HttpRequestHandler.php # HTTP request processing
│ ├── HttpSessionValidator.php # Session validation
│ ├── JsonRpcResponseBuilder.php # JSON-RPC response building
│ ├── McpTransportContext.php # Transport context
│ ├── RequestRouter.php # Request routing
│ └── SessionManager.php # Session management
│
│ # Server factories
├── Servers/
└── DefaultServerFactory.php # Default server creationMcpAdapterMcpServerwp_register_ability())wp_get_ability())composer require wordpress/abilities-api wordpress/mcp-adaptercomposer require automattic/jetpack-autoloader1<?php
2// Load the Jetpack autoloader instead of vendor/autoload.php
3require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload_packages.php';1# Clone the repository
2git clone https://github.com/WordPress/mcp-adapter.git wp-content/plugins/mcp-adapter
3
4# Navigate to the plugin directory
5cd wp-content/plugins/mcp-adapter
6
7# Install dependencies
8composer installtrunk branch with all dependencies installed.1// .wp-env.json
2{
3 "$schema": "https://schemas.wp.org/trunk/wp-env.json",
4 // ... other config ...
5 "plugins": [
6 "WordPress/abilities-api",
7 "WordPress/mcp-adapter",
8 // ... other plugins ...
9 ],
10 // ... more config ...
11}1use WP\MCP\Core\McpAdapter;
2
3// 1. Check if MCP Adapter is available
4if ( ! class_exists( McpAdapter::class ) ) {
5 // Handle missing dependency (show admin notice, etc.)
6 return;
7}
8
9// 2. Initialize the adapter
10McpAdapter::instance();
11// That's it!wp_register_ability() are automatically available/wp-json/mcp/mcp-adapter-default-serverwp mcp-adapter serve --server=mcp-adapter-default-server1// Simply register a WordPress ability
2add_action( 'wp_abilities_api_init', function() {
3 wp_register_ability( 'my-plugin/get-posts', [
4 'label' => 'Get Posts',
5 'description' => 'Retrieve WordPress posts with optional filtering',
6 'input_schema' => [
7 'type' => 'object',
8 'properties' => [
9 'numberposts' => [
10 'type' => 'integer',
11 'description' => 'Number of posts to retrieve',
12 'default' => 5,
13 'minimum' => 1,
14 'maximum' => 100
15 ],
16 'post_status' => [
17 'type' => 'string',
18 'description' => 'Post status to filter by',
19 'enum' => ['publish', 'draft', 'private'],
20 'default' => 'publish'
21 ]
22 ]
23 ],
24 'output_schema' => [
25 'type' => 'array',
26 'items' => [
27 'type' => 'object',
28 'properties' => [
29 'ID' => ['type' => 'integer'],
30 'post_title' => ['type' => 'string'],
31 'post_content' => ['type' => 'string'],
32 'post_date' => ['type' => 'string'],
33 'post_author' => ['type' => 'string']
34 ]
35 ]
36 ],
37 'execute_callback' => function( $input ) {
38 $args = [
39 'numberposts' => $input['numberposts'] ?? 5,
40 'post_status' => $input['post_status'] ?? 'publish'
41 ];
42 return get_posts( $args );
43 },
44 'permission_callback' => function() {
45 return current_user_can( 'read' );
46 }
47 ]);
48});
49
50// The ability is automatically available via the default MCP server
51// No additional configuration needed!1# List all available MCP servers
2wp mcp-adapter list
3
4# Test the discover abilities tool to see all available WordPress abilities
5echo '{"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
6
7# Test listing available tools
8echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server1{
2 "mcpServers": {
3 "wordpress-default": {
4 "command": "wp",
5 "args": [
6 "--path=/path/to/your/wordpress/site",
7 "mcp-adapter",
8 "serve",
9 "--server=mcp-adapter-default-server",
10 "--user=admin"
11 ]
12 },
13 "wordpress-custom": {
14 "command": "wp",
15 "args": [
16 "--path=/path/to/your/wordpress/site",
17 "mcp-adapter",
18 "serve",
19 "--server=your-custom-server-id",
20 "--user=admin"
21 ]
22 }
23 }
24}1{
2 "mcpServers": {
3 "wordpress-http-default": {
4 "command": "npx",
5 "args": [
6 "-y",
7 "@automattic/mcp-wordpress-remote@latest"
8 ],
9 "env": {
10 "WP_API_URL": "http://your-site.test/wp-json/mcp/mcp-adapter-default-server",
11 "LOG_FILE": "/path/to/logs/mcp-adapter.log",
12 "WP_API_USERNAME": "your-username",
13 "WP_API_PASSWORD": "your-application-password"
14 }
15 },
16 "wordpress-http-custom": {
17 "command": "npx",
18 "args": [
19 "-y",
20 "@automattic/mcp-wordpress-remote@latest"
21 ],
22 "env": {
23 "WP_API_URL": "http://your-site.test/wp-json/your-namespace/your-route",
24 "LOG_FILE": "/path/to/logs/mcp-adapter.log",
25 "WP_API_USERNAME": "your-username",
26 "WP_API_PASSWORD": "your-application-password"
27 }
28 }
29 }
30}1add_action('mcp_adapter_init', function($adapter) {
2 $adapter->create_server(
3 'my-server-id', // Unique server identifier
4 'my-namespace', // REST API namespace
5 'mcp', // REST API route
6 'My MCP Server', // Server name
7 'Description of my server', // Server description
8 'v1.0.0', // Server version
9 [ // Transport methods
10 \WP\MCP\Transport\HttpTransport::class, // Recommended: MCP 2025-06-18 compliant
11 ],
12 \WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler::class, // Error handler
13 \WP\MCP\Infrastructure\Observability\NullMcpObservabilityHandler::class, // Observability handler
14 ['my-plugin/my-ability'], // Abilities to expose as tools
15 [], // Resources (optional)
16 [], // Prompts (optional)
17 );
18});is_user_logged_in() check, you can implement custom authentication for your MCP servers.