Using MCP (Model Context Protocol)
Using MCP (Model Context Protocol)
What’s this all about?
Model Context Protocol (MCP) is the open standard Claude (and soon, others, such as ChatGPT) uses to talk to external “tool servers.” When Claude detects an MCP server it can:
- list the server’s tools (
tools/list
),
- ask the user to pick one, or decide autonomously, and then
- call that tool with JSON‑RPC (
tools/call
).
With AI Engine installed, your WordPress site exposes 30‑plus tools that let Claude:
- read / write posts, pages & custom post types
- upload or generate media
- manage categories, tags & any taxonomy
- switch, fork, and live‑edit themes
- list plugins …and more
The little Node script mcp.js
is the bridge. It:
- Opens an SSE stream to WordPress (
/wp-json/mcp/v1/sse
).
- Translates Claude’s JSON‑RPC calls to HTTP POSTs (
/messages
).
- Pushes WordPress responses back to Claude via stdout.
- Cleans up automatically (sends
mwai/kill
, aborts SSE, exits) when Claude closes.
For advanced users only. This stack is still beta. You’ll need command‑line access, ability to restart PHP/FPM, and basic debugging patience.
1 · Install requirements
Requirement | Details |
WordPress 6.x | REST API enabled. |
AI Engine plugin | Folder wp-content/plugins/ai-engine . |
Claude Desktop ≥ 0.9.2 | macOS (tested) • Windows (paths differ). |
Node ≥ 20.19.0 | node -v — multiple versions? use nvm . |
mcp.js
handles everything else: it registers your site, edits Claude’s config, launches the relay, and terminates cleanly.
2 · Connect Claude to your site
# 1 · Register site + update Claude config
ai-engine/labs/mcp.js add https://example.com
# 2 · Launch a visible relay for the first test
ai-engine/labs/mcp.js start example.com
- The first command writes an MCP entry to
~/.config/anthropic/claude.json
(macOS/Linux) or%APPDATA%\Anthropic\claude.json
(Windows).
Prefer manual editing? That’s the file.
- Launch Claude Desktop. Within seconds you should see a plug icon (connected) and a hammer with ~30 tools.
3 · Prompt ideas
Level | Example |
Simple | “List my latest 5 posts.” |
“Create a post titled My AI Journey (one paragraph) and attach a media‑library image.” | |
Intermediate | “Look at the 10 newest posts, then publish a logical follow‑up. Re‑use existing categories & tags. If no image fits, generate one.” |
Advanced | “Fork Twenty Twenty‑One into a grid‑layout theme called Futurism supporting post types Article & Project.” |
4 · Hosting caveats
Each open SSE ties up one PHP worker. The number of PHP workers depend on your servers, your plan, etc. For example, with Kinsta, it's generally between and 5 and 8.
If the site stalls
# Drop Claude’s MCP entry (disables auto‑launch)
ai-engine/labs/mcp.js claude none
# Restart PHP‑FPM or your container
sudo systemctl restart php-fpm
# Relaunch Claude
The relay auto‑kills itself, so stalls are rare; but under heavy traffic you might still need to bump PHP worker count.
5 · mcp.js
CLI cheatsheet
# verbose relay (console output)
mcp.js start example.com
# silent relay (Claude uses this)
mcp.js relay example.com
# manage sites
mcp.js add mysite.com # register
mcp.js claude mysite.com # switch target
mcp.js list # show all
# ad‑hoc call (no curl)
mcp.js post mysite.com '{"method":"tools/list"}' <session_id>
Logs → ~/.mcp/
(mcp.log
, mcp-results.log
, error.log
).
6 · Verbose PHP logging (optional)
// wp-content/plugins/ai-engine/classes/modules/mcp.php
private $logging = true;
Tail wp-content/debug.log
.
7 · How shutdown is handled
Claude doesn’t send SIGTERM to its helper. mcp.js
therefore:
- Detects stdin close.
- Sends a JSON‑RPC notification
{ "method":"mwai/kill" }
to/messages
.
- Aborts the SSE fetch.
- Exits 0.
On the WordPress side the MCP module sees mwai/kill
, ends its loop, and frees the PHP worker.
Windows note — the script is authored on macOS. On Windows native Node the shutdown works, but path separators differ. If you see lingering node.exe, try running the relay inside WSL 2 or add a process.on('SIGTERM') shim.