Skip to content

Latest commit

 

History

History
126 lines (98 loc) · 4.78 KB

File metadata and controls

126 lines (98 loc) · 4.78 KB

Getting Started with MCP Adapter

This guide will help you quickly set up the WordPress MCP Adapter to expose your WordPress abilities as MCP (Model Context Protocol) tools, resources, and prompts.

Quick Overview

The MCP Adapter transforms WordPress abilities into AI-accessible interfaces, allowing AI agents to interact with your WordPress functionality through standardized protocols.

Prerequisites

  • PHP 7.4 or higher
  • WordPress 6.9 or higher (Abilities API is built into core — no separate plugin)

Quick Start

Step 1: Install MCP Adapter

MCP Adapter is a WordPress plugin. Install and activate it:

wp plugin install https://github.com/WordPress/mcp-adapter/releases/latest/download/mcp-adapter.zip --activate

Or download the latest release from GitHub and install it like any other plugin. See the Installation Guide for more options.

Step 2: Register a Simple Ability

Create a WordPress ability that will be exposed via MCP:

// Register a simple ability to get site information
add_action( 'wp_abilities_api_init', function() {
    wp_register_ability( 'my-plugin/get-site-info', [
        'label' => 'Get Site Information',
        'description' => 'Retrieves basic information about the current WordPress site',
        'category' => 'site',
        'input_schema' => [
            'type' => 'object',
            'properties' => [
                'include_stats' => [
                    'type' => 'boolean',
                    'description' => 'Whether to include post/page statistics',
                    'default' => false
                ]
            ]
        ],
        'execute_callback' => function( $input ) {
            $result = [
                'site_name' => get_bloginfo( 'name' ),
                'site_url' => get_site_url(),
                'description' => get_bloginfo( 'description' )
            ];
            
            if ( $input['include_stats'] ?? false ) {
                $result['stats'] = [
                    'post_count' => wp_count_posts( 'post' )->publish,
                    'page_count' => wp_count_posts( 'page' )->publish
                ];
            }
            
            return $result;
        },
        'permission_callback' => function() {
            return current_user_can( 'read' );
        }
    ]);
});

Step 3: Create Your MCP Server (Optional)

The adapter creates a default server automatically, but you can create custom servers:

add_action( 'mcp_adapter_init', function( $adapter ) {
    $adapter->create_server(
        'my-first-server',                          // Unique server ID
        'my-plugin',                                // REST API namespace
        'mcp',                                      // REST API route
        'My First MCP Server',                      // Human-readable name
        'A simple MCP server for demonstration',    // Description
        '1.0.0',                                    // Version
        array( \WP\MCP\Transport\HttpTransport::class ), // Transport methods
        \WP\MCP\Infrastructure\ErrorHandling\ErrorLogMcpErrorHandler::class, // Error handler
        null,                                       // Observability handler (null = default)
        array( 'my-plugin/get-site-info' )          // Abilities to expose as tools
    );
});

Step 4: Test Your Setup

Test your MCP server:

Using WP-CLI (STDIO transport):

# List available tools
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server

# Execute the site info tool
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"my-plugin-get-site-info","arguments":{"include_stats":true}}}' | wp mcp-adapter serve --user=admin --server=mcp-adapter-default-server

Using HTTP REST API:

# Test basic connectivity
curl "https://yoursite.com/wp-json/"

# Test MCP endpoint (requires authentication)
curl -X POST "https://yoursite.com/wp-json/mcp/mcp-adapter-default-server" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'

Next Steps

Troubleshooting

See the Common Issues guide.