MCP Adapter for WordPress#
The MCP adapter is a library that bridges the Abilities API to the Model Context Protocol, enabling MCP clients to discover and invoke WordPress plugin, theme, and core abilities programmatically.
It is currently a work in progress, also available as a standalone WordPress plugin, and planned to be integrated directly in WordPress core in the future.
Abilities API Jumpstart#
If you are not yet familiar with the Abilities API, the WordPress Developer documentation provides all the information you need to get familiar with the API, and start creating your first abilities.
Code Recommendations#
To keep your abilities code organized and clean, it is recommended to structure them using a PHP interface, and creating one class per ability.
You can find below an example of the PHP interface to use as your base contract:
<?php
declare(strict_types=1);
namespace Org\Project\Abilities;
interface AbilitiesInterface {
/**
* Register the ability
*
* @return void
*/
public function register(): void;
/**
* Check if the current user has permission to execute this ability
*
* @return bool
*/
public function check_permissions(): bool;
/**
* Execute the ability
*
* @return mixed
*/
public function execute();
}
This interface ensures the base contract for registering an ability in the API is respected:
- The method register() to register the ability definition using wp_register_ability()
- The method check_permissions() as the callback for the permissions_callback parameter of the ability
- The method execute() as the callback for the execute_callback parameter of the ability
MCP Adapter Installation & Setup#
The MCP Adapter is available at its Github repository, and can be installed as a composer package.
It automatically will map available abilities into tools, prompts and resources base on the MCP specification.
The adapter provides a default mcp server on the WordPress website, and it also allows creating additional custom servers if needed.
To use the MCP adapter in your plugin, first install it as a composer package:
composer require wordpress/mcp-adapter
Then, initialize it in your main plugin file:
use WP\MCP\Core\McpAdapter;
// 1. Check if MCP Adapter is available
if ( ! class_exists( McpAdapter::class ) ) {
// Handle missing dependency (show admin notice, etc.)
return;
}
// 2. Initialize the adapter
McpAdapter::instance();
// That's it!
Exposing Abilities to the MCP Server#
To expose your abilities to the default MCP server, you need to add the following to the meta parameter during ability registration:
'meta' => [
'mcp' => [
'public' => true, // Required for default MCP server access
],
],
Connecting to the MCP Server#
To connect to the MCP server from your MCP client, you need to configure the mcp.json file following the example below:
{
"mcpServers": {
"wordpress-http-default": {
"command": "npx",
"args": [
"-y",
"@automattic/mcp-wordpress-remote@latest"
],
"env": {
"WP_API_URL": "http://your-site.test/wp-json/mcp/mcp-adapter-default-server",
"LOG_FILE": "/path/to/logs/mcp-adapter.log",
"WP_API_USERNAME": "your-username",
"WP_API_PASSWORD": "your-application-password"
}
}
}
}
The WP_API_PASSWORD is an application password you can create from your WP admin profile. It is not your account password.
Once connected, you can use your chat session to ask for available abilities, or prompt to use them for example.