PHP code example of wpboilerplate / wpb-mcp-servers-list

1. Go to this page and download the library: Download wpboilerplate/wpb-mcp-servers-list library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wpboilerplate / wpb-mcp-servers-list example snippets




use WPBoilerplate\McpServersList\McpServersList;

// Option A – one-liner bootstrap (registers the hook automatically)
add_action( 'plugins_loaded', [ McpServersList::class, 'bootstrap' ] );

// Option B – manual hook (more control)
add_action( 'rest_api_init', function () {
    McpServersList::instance()->collect();
}, 20 );

use WPBoilerplate\McpServersList\McpServersList;

$servers = McpServersList::instance()->get_servers();
// $servers → ServerData[]

foreach ( $servers as $server ) {
    echo $server->get_name();         // "WordPress MCP Server"
    echo $server->get_id();           // "default"
    echo $server->get_version();      // "0.5.0"
    echo $server->get_endpoint_url(); // "https://example.com/wp-json/wp/mcp/v1/mcp"

    foreach ( $server->get_tools() as $tool ) {
        echo $tool->get_name();        // "discover_abilities"
        echo $tool->get_description(); // "..."
    }

    foreach ( $server->get_resources() as $resource ) {
        echo $resource->get_name();
        echo $resource->get_uri();
        echo $resource->get_description();
    }

    foreach ( $server->get_prompts() as $prompt ) {
        echo $prompt->get_name();
        echo $prompt->get_description();
    }
}

use WPBoilerplate\McpServersList\RestEndpoint;

add_action( 'rest_api_init', function () {
    // Default: GET /wp-json/wpb-mcp-servers-list/v1/servers  (rvers' );
}, 20 );

// Allow editors to access the endpoint:
add_filter( 'wpb_mcp_servers_list_rest_capability', function ( string $cap ): string {
    return 'edit_posts';
} );

// Allow any logged-in user:
add_filter( 'wpb_mcp_servers_list_rest_capability', function ( string $cap ): string {
    return 'read';
} );

if ( McpServersList::is_adapter_available() ) {
    // MCP Adapter plugin is active
}

// Default behaviour (administrators only):
// apply_filters( 'wpb_mcp_servers_list_rest_capability', 'manage_options' )