When to build a WordPress MCP server

The standard advice this year is that once your agents start duplicating tools, you move the tools onto an MCP server and let every client connect to it. Priyansh Bhardwaj wrote up exactly that migration on Towards Data Science, including the boring operational parts most writeups skip, and I found it useful. What it leaves out, for a WordPress shop anyway, is whether you need a WordPress MCP server at all, or whether you have a code organization problem that a protocol won’t fix.

I’ve watched this debate run before under a different name. Someone proposes centralizing all the REST route definitions, or putting every WooCommerce helper call into one shared class, and it holds until the third consumer needs a slightly different version of the same function. In Bhardwaj’s case the trigger was a two-column schema change that touched four files across an orchestrator, a validation agent, and a utility module written three sprints earlier. The duplication was the emergency, and the protocol was the fix they reached for second.

The registry was never the hard part

Bhardwaj anticipates the question a senior engineer would ask:

“A senior engineer reading this article will immediately ask: couldn’t I just build a centralised tool registry and inject it into each agent at startup?”

His answer is yes, and if you already have one working, MCP is not an emergency. A registry fixes duplication but not ownership. MCP is a protocol rather than a library, so any compatible client can connect, a TypeScript client can call a Python server, and the team that owns the tools gets a contract with the team that owns the graph without sharing a codebase. His team ended up with seven tools on the server, three of them approval-gated, and the orchestrator knows nothing about what any of them do.

WordPress developers should find that familiar, because we run a version of this argument constantly. register_rest_route() fired on rest_api_init is a registry with a discovery story, a namespace like woocommerce/v3 is a contract between a plugin and its consumers, and the REST API handbook has insisted on permission_callback since 5.5 made it mandatory. So for us the MCP question is narrower than the articles make it sound. It only becomes a live question when something outside your PHP needs to consume the same tools, whether that’s a Python agent runtime, a desktop client, or another team’s orchestrator. If the only consumer is your own plugin, a class or a namespaced route does the same job with fewer moving parts.

A shared class, a REST namespace, or a WordPress MCP server

The cheapest option is a plain class of tool functions inside your plugin. There’s no network, schema, or discovery involved, and deployment is your normal plugin release. Every caller lives in the same codebase, which is also the limitation: there’s no boundary, so nothing stops a caller from using the wrong version, and nothing authenticates a caller that isn’t your code. That’s fine with one plugin and one team; it stops being fine the moment a second consumer shows up.

A REST namespace is the option I’d reach for first when an external agent needs to act on a store. You get versioned routes, argument validation in the args array, and an auth model you already operate: cookies, application passwords, or keys. If you haven’t built one before, the mechanics of a custom REST API endpoint are worth a read. The cost is operational: each tool call is an HTTP round trip that boots WordPress, so an agent making five sequential calls pays your full stack five times, and on a busy store with a heavy plugin stack that’s real latency.

An MCP server is a separate process with typed tools, generated from function signatures by FastMCP in the Python SDK, plus a discovery handshake where the client asks what exists and binds the result. Two transports matter in practice. Stdio runs the server as a subprocess of the client with no network involved, and Bhardwaj puts that latency in single-digit milliseconds, which is plausible for a local pipe. Streamable HTTP runs the server as an independent service you can containerize and scale. Switching between them is one line in FastMCP. On stdio, never write to stdout: stdout is the protocol channel, and one stray print() corrupts the message stream.

So which option you pick depends on the site. With one plugin, one team, and internal tools only, keep the functions where they are. If an agent runtime needs to place orders or edit stock on a single site, a REST namespace comes first, because you inherit auth, roles, and the whole WooCommerce REST surface. If you’re earlier in the process, getting client stores ready for WooCommerce AI workflows is the conversation that comes before this one. When you have multiple consumers in different languages, or a tools team separate from the app team, which is the situation Bhardwaj describes, a WordPress MCP server earns its keep. It’s the only option of the three where the protocol itself does work a shared class can’t.

Where the approval gate goes

This is the part of his article I’d keep even if you never adopt MCP. Before the migration, their approval gate lived in the graph, wired into edges per tool, and adding a sensitive tool meant coordinating three teams. After the migration, the gate moved to a single layer between the executor and the MCP client, backed by a frozenset of sensitive tool names loaded from config at startup, so the policy could change without a code deployment. The graph knows nothing about it.

WordPress has this built in, and enforces it. When your tools are REST routes, the gate is the route definition, and the agent can’t route around it, because the server refuses rather than the prompt asking nicely. The shape I use looks like this:

<?php
add_action( 'rest_api_init', function () {
    register_rest_route( 'bbioon-tools/v1', '/db-write', array(
        'methods'             => 'POST',
        'callback'            => 'bbioon_write_to_db',
        'permission_callback' => 'bbioon_gate_sensitive_tools',
        'args'                => array(
            'table'   => array( 'type' => 'string', 'required' => true ),
            'payload' => array( 'type' => 'object', 'required' => true ),
        ),
    ) );
} );

function bbioon_gate_sensitive_tools( WP_REST_Request $request ) {
    $tool  = basename( trim( $request->get_route(), '/' ) ); // db-write
    $gated = (array) get_option( 'bbioon_sensitive_tools', array( 'db-write', 'refund' ) );

    if ( ! current_user_can( 'manage_options' ) ) {
        return new WP_Error( 'bbioon_forbidden', 'Operator permissions required.', array( 'status' => 403 ) );
    }

    if ( in_array( $tool, $gated, true ) ) {
        // in production this is where a Slack prompt or an audit queue goes
        return new WP_Error( 'bbioon_approval_required', 'This write needs manual approval first.', array( 'status' => 428 ) );
    }

    return true;
}

Where the gate sits matters more than the exact code. Whether the server is MCP or REST, the model should never be the only thing standing between a prompt and a write. Bhardwaj is also honest that the protocol won’t make unreliable tools reliable or fix vague tool descriptions, which cost his team real debugging time when write_to_db kept getting called before run_analysis finished. The gate stops unauthorized calls, but it does nothing for the quality of the authorized ones. On failures, both designs end the same way: the model receives an error message, and whether it recovers or loops depends on your system prompt, so log the server side separately or you’re guessing.

One thing translates badly to WordPress. If a human takes five minutes to approve a call, LangGraph can checkpoint state and resume when the decision arrives. A WordPress worker can’t wait like that, so return a 202 and let the client poll.

If you’re wiring agent tooling into a WooCommerce store and want a second opinion on where the gates should sit before the first write tool ships, that’s work I do. Placing the boundary before launch is far cheaper than moving it after an agent has already written somewhere it shouldn’t have.

The spec is moving under you

Before you commit, look at where the protocol itself is heading. The 2026-07-28 spec revision makes MCP stateless, with every request self-contained and method and tool names carried in Mcp-Method and Mcp-Name headers so gateways can route and authorize on headers directly. That removes the session-affinity problem stateful HTTP deployments had, and it also means session behavior you build against today may not match what the next client SDK expects.

The library Bhardwaj uses proves the point. langchain-mcp-adapters was archived in September 2026 and folded into LangChain itself, with MultiServerMCPClient now a deprecated compatibility API behind MCPAdapter. His code is still a clear illustration of the pattern, but if you copy it today you’re starting on a migration path. That doesn’t invalidate his argument: a protocol outliving any one client library is the argument. It does mean you should keep the tool surface small and treat adapters as replaceable, because they demonstrably get replaced.

The thing I still haven’t worked out is versioning. The win he describes, where you change a schema once and every consumer picks it up at the next handshake, is also the failure mode, because nothing announces to the agents that a tool they called yesterday has changed shape. In REST we handle this with /v1 and /v2 in the route path, which is boring and predictable. I don’t know what the equivalent convention for tool servers should be. It matters, because if a server changes a write tool’s arguments without a version bump, an agent can write the wrong shape of data with perfectly valid permissions.

author avatar
Ahmad Wael
I'm a WordPress and WooCommerce developer with 15+ years of experience building custom e-commerce solutions and plugins. I specialize in PHP development, following WordPress coding standards to deliver clean, maintainable code. Currently, I'm exploring AI and e-commerce by building multi-agent systems and SaaS products that integrate technologies like Google Gemini API with WordPress platforms, approaching every project with a commitment to performance, security, and exceptional user experience.

Leave a Comment