# Troubleshooting Guide Common issues and quick solutions for the MCP Adapter. ## Quick Fixes ### REST API 404 Errors ```bash # Check WordPress REST API works curl "https://yoursite.com/wp-json/" # Check permalinks (must not be "Plain") wp option get permalink_structure ``` ### Permission Denied ```bash # Test with admin user echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server # Check user capabilities wp user list --fields=ID,user_login,roles ``` ### HTTP session errors (missing or invalid Mcp-Session-Id) When using the HTTP REST API, all requests after `initialize` must include the `Mcp-Session-Id` header. Omitting it or sending an invalid value are the most common causes of unexpected errors. **Symptom: JSON-RPC error `-32600` — "Missing Mcp-Session-Id header"** The request is missing the `Mcp-Session-Id` header. Every request except `initialize` must include it. ```bash # Wrong — no session header curl -s -X POST "https://yoursite.com/wp-json/mcp/mcp-adapter-default-server" \ --user "username:application_password" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' # Correct — include the session header received from initialize curl -s -X POST "https://yoursite.com/wp-json/mcp/mcp-adapter-default-server" \ --user "username:application_password" \ -H "Content-Type: application/json" \ -H "Mcp-Session-Id: " \ -d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' ``` **Symptom: "Invalid or expired session" in JSON-RPC error response** The session ID is not recognized or has exceeded the inactivity timeout. Re-initialize to obtain a new session: ```bash # Re-initialize to get a fresh session curl -s -D - -X POST "https://yoursite.com/wp-json/mcp/mcp-adapter-default-server" \ --user "username:application_password" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"my-client","version":"1.0.0"}}}' ``` **Tip:** The default inactivity timeout is 24 hours (`DAY_IN_SECONDS`). If your client is long-lived, keep the session active by sending requests periodically. You can also adjust the timeout with the `mcp_adapter_session_inactivity_timeout` filter. **Note:** STDIO transport (WP-CLI) does not use HTTP sessions. If you see session errors, verify you are using the correct transport for your use case. See the [HTTP Sessions section](../guides/default-server.md#http-sessions) for the full session flow. ## Installation Issues ### Plugin Not Active ```bash # Activate the plugin wp plugin activate mcp-adapter # Check status wp plugin status mcp-adapter ``` ### Composer Autoloader Missing If you see *"The Composer autoloader was not found"*, the plugin's dependencies have not been installed. The release zip ships with its `vendor/` directory, so this only happens when the plugin was installed from a source checkout. ```bash # Install dependencies in the plugin directory cd wp-content/plugins/mcp-adapter composer install # Check the autoloader exists (Jetpack Autoloader, not autoload.php) ls vendor/autoload_packages.php ``` Alternatively, install a release build instead of a source checkout: ```bash wp plugin install https://github.com/WordPress/mcp-adapter/releases/latest/download/mcp-adapter.zip --activate --force ``` ### Class Not Found `WP\MCP\*` classes are provided by the MCP Adapter plugin. If they are missing, the plugin is not active. Check for it rather than trying to load an autoloader yourself: ```php if ( ! class_exists( 'WP\MCP\Core\McpAdapter' ) ) { add_action( 'admin_notices', function() { echo '

MCP Adapter plugin must be active.

'; }); return; } ``` Add `Requires Plugins: mcp-adapter` to your plugin header so WordPress loads MCP Adapter before your plugin. ### Abilities API Missing ```php // Check in your plugin if ( ! function_exists( 'wp_register_ability' ) ) { add_action( 'admin_notices', function() { echo '

MCP Adapter requires WordPress 6.9 or newer. The Abilities API is included in core.

'; }); return; } ``` ## Server Issues ### Server Not Creating ```php // Debug server creation add_action( 'mcp_adapter_init', function( $adapter ) { error_log( 'MCP Adapter init fired' ); try { $adapter->create_server( 'test-server', 'test', 'mcp', 'Test Server', 'Testing server creation', '1.0.0', [ \WP\MCP\Transport\HttpTransport::class ], \WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler::class, [] ); error_log( 'Server created successfully' ); } catch ( Exception $e ) { error_log( 'Server creation failed: ' . $e->getMessage() ); } }); ``` ### Check Registered Servers Servers are registered while the `mcp_adapter_init` action runs, and the adapter fires that action on `rest_api_init` (priority 15), or on `init` (priority 20) under WP-CLI. `get_servers()` therefore returns an empty array until `mcp_adapter_init` has fired, for example when called on `init`. Hook `mcp_adapter_init` with a priority later than 10 (the default server is created at priority 10) to read the list reliably: ```php add_action( 'mcp_adapter_init', function ( $adapter ) { error_log( 'MCP servers: ' . implode( ', ', array_keys( $adapter->get_servers() ) ) ); }, 20 ); ``` `get_servers()` returns `McpServer` objects keyed by server ID. The JSON from `json_encode()`, or from a REST response built with `rest_ensure_response()`, keeps the server IDs as keys but has no server name or version. Build a plain array from the getters instead, for example `get_server_id()`, `get_server_name()`, and `get_server_version()`. ### REST API Not Working ```bash # Check permalinks (must not be "Plain") wp option get permalink_structure # Test basic REST API curl "https://yoursite.com/wp-json/" # List MCP routes wp rest list | grep mcp ``` ### Routes Not Found ```php // Check registered routes add_action( 'rest_api_init', function() { $routes = rest_get_server()->get_routes(); $mcp_routes = array_filter( array_keys( $routes ), function( $route ) { return strpos( $route, '/mcp' ) !== false; }); error_log( 'MCP routes: ' . implode( ', ', $mcp_routes ) ); }, 999 ); ``` ## Permission Issues ### 401 Unauthorized ```bash # Test with authentication curl -X POST "https://yoursite.com/wp-json/mcp/mcp-adapter-default-server" \ --user "username:application_password" \ -H "Content-Type: application/json" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' # Check user is logged in wp user get admin --field=ID ``` ### 403 Forbidden ```php // Debug user capabilities add_action( 'wp_loaded', function() { $user = wp_get_current_user(); if ( $user->ID ) { error_log( sprintf( 'User %d capabilities: %s', $user->ID, implode( ', ', array_keys( $user->allcaps ) ) )); } }); ``` ### Test Permission Callback ```php // Temporarily allow all users for testing function(): bool { error_log( 'Permission check for user: ' . get_current_user_id() ); return is_user_logged_in(); // Very permissive } ``` ## Ability Issues ### `wp_register_ability()` returns `null` A common cause is a missing or unregistered `category`. `wp_register_ability()` requires a `category`, and that category must already be registered when registration runs. If it is missing or unknown, the function returns `null` and the ability never appears. There is no `WP_Error`; core calls `_doing_it_wrong()`, which only surfaces a notice when `WP_DEBUG` is on. With `WP_DEBUG` off (typical on production) it looks completely silent. Enable `WP_DEBUG` to surface the notice, plus `WP_DEBUG_LOG` to capture it in `wp-content/debug.log`, then look for a message like `Ability category "..." is not registered`. ```php // Wrong: no category → returns null, ability never registers. wp_register_ability( 'my-plugin/my-ability', [ 'label' => 'My Ability', 'description' => 'Test ability', // ... ] ); // Right: use a registered category. Core provides 'site' and 'user'. wp_register_ability( 'my-plugin/my-ability', [ 'label' => 'My Ability', 'description' => 'Test ability', 'category' => 'site', // ... ] ); ``` For a custom category, register it first on the `wp_abilities_api_categories_init` hook (a separate, earlier hook than `wp_abilities_api_init`): ```php add_action( 'wp_abilities_api_categories_init', function () { wp_register_ability_category( 'my-plugin', [ 'label' => 'My Plugin', 'description' => 'Abilities provided by My Plugin.', ] ); } ); ``` See [Ability categories](../guides/creating-abilities.md#ability-categories-required) for details. ### Ability Not Found ```bash # Check ability is registered wp eval "var_dump(wp_get_ability('my-plugin/my-ability'));" # List all abilities wp eval "var_dump(array_keys(wp_get_abilities()));" ``` ### Execution Errors ```php // Debug ability execution 'execute_callback' => function( $input ) { error_log( 'Ability input: ' . wp_json_encode( $input ) ); try { $result = your_operation( $input ); error_log( 'Ability output: ' . wp_json_encode( $result ) ); return $result; } catch ( Exception $e ) { error_log( 'Ability error: ' . $e->getMessage() ); throw $e; } } ``` ### Schema Validation Errors ```php // Test your input schema $test_input = ['title' => 'Test']; $ability = wp_get_ability('my-plugin/my-ability'); if ( $ability ) { $schema = $ability->get_input_schema(); error_log( 'Input schema: ' . wp_json_encode( $schema ) ); } ``` ## Debugging ### Enable Debug Logging ```php // Add to wp-config.php define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false ); ``` ### Check System Status ```php // Quick system check add_action( 'wp_loaded', function() { if ( current_user_can( 'manage_options' ) ) { $adapter = \WP\MCP\Core\McpAdapter::instance(); error_log( sprintf( 'MCP Status - Adapter: %s, Abilities API: %s, Servers: %d', class_exists( 'WP\MCP\Core\McpAdapter' ) ? 'OK' : 'MISSING', function_exists( 'wp_register_ability' ) ? 'OK' : 'MISSING', count( $adapter->get_servers() ) )); } }); ``` ### Log Analysis ```bash # Watch debug log for MCP issues tail -f wp-content/debug.log | grep MCP # Search for recent errors grep "MCP.*Error" wp-content/debug.log | tail -10 # Count error types grep "MCP.*Error" wp-content/debug.log | cut -d']' -f2 | sort | uniq -c ``` ### Performance Monitoring ```php // Simple timing for abilities 'execute_callback' => function( $input ) { $start = microtime( true ); try { $result = your_operation( $input ); $duration = microtime( true ) - $start; if ( $duration > 1.0 ) { error_log( sprintf( 'Slow ability: %.2fs', $duration ) ); } return $result; } catch ( Exception $e ) { error_log( 'Ability failed: ' . $e->getMessage() ); throw $e; } } ``` ## Error Handler Issues ### Handler Not Working ```php // Verify error handler interface class MyErrorHandler implements \WP\MCP\Infrastructure\ErrorHandling\Contracts\McpErrorHandlerInterface { public function log(string $message, array $context = [], string $type = 'error'): void { error_log( "[MCP {$type}] {$message}" ); } } // Check implementation if ( ! in_array( \WP\MCP\Infrastructure\ErrorHandling\Contracts\McpErrorHandlerInterface::class, class_implements( MyErrorHandler::class ), true )) { error_log( 'Error handler missing interface' ); } ``` ### Use Error Factory ```php // Create proper error responses use WP\MCP\Infrastructure\ErrorHandling\McpErrorFactory; if ( empty( $params['name'] ) ) { return McpErrorFactory::missing_parameter( $request_id, 'name' ); } ``` ## Common Fixes ### Permalink Issues ```bash # Check permalink structure wp option get permalink_structure # If empty, set to post name wp option update permalink_structure "/%postname%/" ``` ### Memory Limits ```php // Increase memory for MCP operations add_action( 'mcp_adapter_init', function() { if ( defined( 'REST_REQUEST' ) ) { ini_set( 'memory_limit', '512M' ); ini_set( 'max_execution_time', 300 ); } }); ``` ### Cache Issues ```php // Clear object cache if using persistent caching wp_cache_flush(); // Or via WP-CLI wp cache flush ``` ## Next Steps - **[Installation Guide](../getting-started/installation.md)** - Setup verification - **[Creating Abilities](../guides/creating-abilities.md)** - Working examples - **[Error Handling](../guides/error-handling.md)** - Custom error management