The AI-Powered CMS: WordPress 7.0+ Connectors, Model Context Protocol (MCP), and Agentic VPS Workflows

Antigravity CLI
Antigravity CLI

The AI-Powered CMS: WordPress 7.0+ Connectors, Model Context Protocol (MCP), and Agentic VPS Workflows

WordPress 7.0 introduced a native AI layer that turns the CMS into a first‑class platform for large language model (LLM) integration, allowing developers to plug in OpenAI, Anthropic, Gemini, and other providers without scattering credentials across the codebase.

Centralized Connector Registry and the Unified PHP AI SDK

The Settings → Connectors page now hosts a Connector Registry where each entry stores the provider name, endpoint URL, and a single API key encrypted at rest. Plugins query this registry through the wp_ai_client_prompt() helper, which builds a provider‑agnostic request object.

/**
 * Unified AI prompt helper.
 *
 * @param string $model   Provider model identifier (e.g., "gpt-4o", "claude-3.5").
 * @param array  $payload Prompt payload with "messages" or "input".
 * @param string $ability Optional ability slug for permission checks.
 * @return array          Decoded response from the LLM.
 */
function wp_ai_client_prompt( $model, $payload, $ability = '' ) {
    $connector = wp_ai_get_connector_for_model( $model );
    if ( ! $connector ) {
        return new WP_Error( 'ai_no_connector', 'No connector configured for model.' );
    }

    // Verify ability if supplied.
    if ( $ability && ! wp_ai_user_has_ability( $ability ) ) {
        return new WP_Error( 'ai_unauthorized', 'User lacks required ability.' );
    }

    $request = [
        'method'  => 'POST',
        'timeout' => 30,
        'headers' => [
            'Authorization' => 'Bearer ' . $connector->get_api_key(),
            'Content-Type'  => 'application/json',
        ],
        'body'    => wp_json_encode( $payload ),
    ];

    $response = wp_remote_request( $connector->get_endpoint(), $request );
    if ( is_wp_error( $response ) ) {
        return $response;
    }

    return json_decode( wp_remote_retrieve_body( $response ), true );
}

Because the SDK fetches the API key from the central store, any plugin that calls wp_ai_client_prompt() automatically respects the same secret, eliminating duplication and reducing the attack surface.

Abilities API for Fine‑Grained Permissioning

The new wp_ai_register_ability() function lets developers declare actions that an LLM may invoke, such as wp_ai_create_post or wp_ai_modify_terms. WordPress stores these abilities in the usermeta table, and the SDK checks them before forwarding a request.

// Register a new ability during plugin activation.
function myplugin_register_abilities() {
    wp_ai_register_ability( 'wp_ai_create_post', [
        'label'       => __( 'Create new posts via AI', 'myplugin' ),
        'description' => __( 'Allows the AI model to call wp_insert_post()', 'myplugin' ),
        'capability'  => 'edit_posts',
    ] );
}
register_activation_hook( __FILE__, 'myplugin_register_abilities' );

Site administrators can grant or revoke these abilities per user from the “AI Abilities” meta box on the profile screen, providing a transparent audit trail.

The Model Context Protocol (MCP) Server Built Into WordPress

WordPress now exposes an MCP endpoint (/wp-json/mcp/v1/) that conforms to the open Model Context Protocol. Clients authenticate using Application Passwords or OAuth 2.0, then exchange JSON‑LD context definitions and invoke registered abilities.

Connecting Claude Desktop via Application Password

Claude Desktop reads a JSON configuration that points to the MCP server. Below is a minimal claude_desktop_config.json example:

{
  "mcp_endpoint": "https://example.com/wp-json/mcp/v1/",
  "auth": {
    "type": "application_password",
    "username": "ai-agent",
    "password": "app_pass_3f2b9c7d8e"
  },
  "context": {
    "@context": {
      "CreatePost": "https://example.com/wp/v1/abilities/wp_ai_create_post",
      "EditCategory": "https://example.com/wp/v1/abilities/wp_ai_edit_category"
    }
  },
  "default_model": "claude-3.5-sonnet"
}

When Claude receives a user request like “Write a blog post about edge AI,” it resolves CreatePost from the context, calls the MCP /abilities/wp_ai_create_post endpoint, and passes the generated markdown. WordPress validates the Application Password, checks that the “ai-agent” user holds the wp_ai_create_post ability, then executes wp_insert_post() on the model’s behalf.

Using OAuth for VS Code Extension

The VS Code AI extension can register an OAuth client in the WordPress admin (Settings → AI → OAuth). After the user authorizes the extension, the token carries a scope list such as wp_ai_create_post wp_ai_inspect_terms. The extension then issues MCP calls like:

POST /wp-json/mcp/v1/abilities/wp_ai_inspect_terms
Authorization: Bearer eyJ0eXAiOiJKV1Qi...
Content-Type: application/json

{
  "term_id": 12
}

The server maps the scope to the corresponding ability, runs the PHP callback, and returns a structured response that the editor can display inline.

Secure Agentic CLI Access to wp‑cli on a VPS

Running an AI agent that can invoke wp-cli commands directly on a VPS requires strict isolation. The following steps create a dedicated system user, lock down SSH, and wrap wp in a permission‑checked script.

Step‑by‑Step Setup

  1. Create a non‑login user for the agent:
    sudo adduser --system --no-create-home --shell /usr/sbin/nologin aiagent
  2. Generate an SSH key pair for the agent and add the public key to ~aiagent/.ssh/authorized_keys with command="/usr/local/bin/ai-wp-wrapper.sh" forced‑command:
    sudo -u aiagent ssh-keygen -t ed25519 -f /home/aiagent/.ssh/id_ed25519 -N ""
    cat /home/aiagent/.ssh/id_ed25519.pub | sudo tee -a /home/aiagent/.ssh/authorized_keys
    # Edit the last line:
    echo 'command="/usr/local/bin/ai-wp-wrapper.sh" ssh-ed25519 AAAAC3... aiagent-key' | sudo tee -a /home/aiagent/.ssh/authorized_keys
  3. Install a wrapper that validates the incoming command against a whitelist:
    # /usr/local/bin/ai-wp-wrapper.sh
    #!/bin/bash
    ALLOWED=("wp db export" "wp db import" "wp core update" "wp plugin install" "wp plugin activate")
    REQUEST=$SSH_ORIGINAL_COMMAND
    
    # Simple pattern match – reject anything not in the list.
    for cmd in "${ALLOWED[@]}"; do
        if [[ "$REQUEST" == $cmd* ]]; then
            exec su -s /bin/bash -c "$REQUEST" www-data
        fi
    done
    
    echo "Unauthorized command."
    exit 1
    
    sudo chmod +x /usr/local/bin/ai-wp-wrapper.sh
  4. Restrict sudo for the wrapper only (optional):
    sudo visudo
    # Add line:
    aiagent ALL=(www-data) NOPASSWD: /usr/local/bin/ai-wp-wrapper.sh
    
  5. Test the flow from the AI agent:
    ssh -i /home/aiagent/.ssh/id_ed25519 [email protected] "wp db export /tmp/backup.sql"

The wrapper ensures the agent can only execute predefined maintenance tasks, preventing arbitrary shell access while still allowing full wp-cli capabilities within the allowed set.

Sample Backup Script Invoked by an Agent

# backup_and_notify.sh – called by the AI after a successful export
#!/bin/bash
WP_PATH="/var/www/html"
BACKUP="/tmp/wp-$(date +%F).sql.gz"

cd "$WP_PATH"
wp db export - | gzip > "$BACKUP"
if [ $? -eq 0 ]; then
    curl -X POST -H "Content-Type: application/json" 
        -d "{"text":"✅ WordPress backup completed: $BACKUP"}" 
        https://hooks.example.com/notify
else
    echo "Backup failed" >&2
    exit 1
fi

Deploy the script with chmod +x and add wp db export | gzip > $BACKUP && /path/to/backup_and_notify.sh to the wrapper’s whitelist.

Emerging WordPress & LLM Paradigms

Beyond basic generation, the WordPress AI stack is evolving toward more autonomous content pipelines.

Automated Content Auditing and Tone Alignment

  • Plugins can register an audit_content ability that receives the post ID, runs a sentiment‑analysis model (e.g., Gemini’s text-bison), and returns a score.
  • Based on the score, a second ability adjust_tone can invoke a rewrite prompt, preserving SEO metadata while aligning with brand voice guidelines.

Semantic Graph Enrichment

WordPress now supports a wp_ai_semantic_index() helper that stores embeddings in a custom MySQL table. Front‑end queries can retrieve nearest‑neighbor posts via a REST endpoint, enabling “related‑by‑meaning” widgets without third‑party services.

WebGPU‑Accelerated Local Model Execution

Experimental plugins expose a WebGPU shim that compiles small transformer kernels to the browser’s GPU. This allows on‑device inference for tasks like headline generation or keyword extraction, reducing latency and preserving privacy for edge‑first sites.

Model Compilation for Edge Functions

Using the new wp_ai_compile_model() API, developers can convert a TensorFlow Lite model into a Cloudflare Workers compatible WebAssembly module, then register it as an ability that runs directly at the CDN edge.

By unifying connector management, exposing a standards‑based MCP server, and providing hardened agentic CLI pathways, WordPress 7.0+ equips developers with a production‑ready AI platform that scales from local edge inference to multi‑model cloud orchestration.

Antigravity CLI
  • Antigravity CLI is Google's lightweight, Go-based Terminal User Interface (TUI) for AI-driven software development. Launched on May 19, 2026, as the official successor to Gemini CLI, it provides a keyboard-first workflow for developers to interact with autonomous AI agents directly from the shell.

Guides

Leave a Comment

Your email address will not be published. Required fields are marked *