Claude Code + WordPress

Connect Claude Code to WordPress.

Give Claude Code a bearer-protected MCP connection to your WPGuard server. Inspect one registered site, preview the exact change, and keep important requirements attached to the field they protect.

Self-hosted · Streamable HTTP · Claude Code project or user scope

How do I connect Claude Code to WordPress?

Add WPGuard as an HTTP MCP server and send its token in the Authorization header. Keep the token in Claude Code’s environment instead of committing it to the project.

.mcp.json
{
  "mcpServers": {
    "wpguard": {
      "type": "http",
      "url": "http://127.0.0.1:8642/mcp",
      "headers": {
        "Authorization": "Bearer ${WPGUARD_TOKEN_RECON}"
      }
    }
  }
}

Choose the right scope

Use a project .mcp.json when the server definition belongs with one trusted workspace. Use Claude Code’s user scope when the connection should remain private across projects. Project configurations require trust before Claude Code uses them.

Use Claude’s documented HTTP format

Claude Code requires type: "http" for a Streamable HTTP entry. It also accepts the CLI form with --transport http and an Authorization header. Review the official Claude Code MCP documentation →

Test the connection before granting write access

The read-only smoke test uses a WPGuard recon token and an already registered staging site. The read-only smoke test ends after site discovery and context inspection, without registering a site, opening a packet or applying a change.

  1. Ask the WPGuard operator to configure WPGUARD_TOKEN_RECON in the server environment and provide that token through your client’s secret environment. The token must match on both sides. Do not copy the server’s admin token into a project file.
  2. Use the HTTP configuration above and confirm claude mcp get wpguard. Open /mcp in Claude Code to inspect the connection.
  3. Discover the current tools and call site_list with no arguments. An empty list confirms an authenticated read but provides no WordPress target; stop and ask the operator to register an authorized staging site separately.
  4. Choose one authorized staging-site name from the result and call wp_site_context with that exact site value. Confirm the expected site URL and context without posting credentials or returned site details to a public issue.
  5. Stop after the context read. Do not call site_register, mutation or packet tools, magic-login tools, or raw command tools as part of this smoke test.
MCP tool request bodies — send through your MCP client
{
  "jsonrpc": "2.0", "id": 1, "method": "tools/call",
  "params": { "name": "site_list", "arguments": {} }
}

{
  "jsonrpc": "2.0", "id": 2, "method": "tools/call",
  "params": { "name": "wp_site_context", "arguments": { "site": "YOUR_REGISTERED_STAGING_SITE" } }
}

These request bodies are examples, not recorded production tests. Recon scope limits the MCP tool tier; it is instance-wide rather than a separate per-client tenant boundary, and some recon tools have side effects. Limit the client’s allowed tools to this test’s site_list and wp_site_context. WordPress SSH or companion credentials remain on the WPGuard server. Do not grant a WordPress administrator login to Claude for this connection check.

A 401 is an authentication problem

Confirm that the header contains Bearer followed by the configured recon token. Check environment expansion in Claude Code without printing the token. The server’s Python entry point does not automatically load a .env file.

A 403 is a permission boundary

Confirm the exact tool and credential scope. A write tool returning 403 under a recon token is expected. Keep the smoke test on its two read tools rather than replacing the credential with an admin token.

Discovery works, site context fails

Check the exact registered site name and ask the operator to verify the server’s SSH/WP-CLI or companion connection. MCP authentication and the WordPress connection are separate layers. Do not re-register or change a production site to repair a smoke test.

Connection refused or rate limited

Use 127.0.0.1 only when the client and server share a host. Check an operator-controlled HTTPS endpoint or tunnel for remote use. Back off on 429 responses; repeated retries do not repair a denied or unreachable connection.

Checked November 3, 2026 against the WPGuard client guide, token configuration and Claude Code MCP documentation. A successful read verifies connection and accessible context; it does not demonstrate a safe edit or a business outcome.

Verify the Claude MCP connection before an edit.

Prove that Claude Code can reach the server and use a read-only tool before you give it a WordPress mutation.

Check server status

Run claude mcp get wpguard or claude mcp list. Open /mcp inside Claude Code to see connection errors. A 401 means the header is missing, unexpanded, or does not match a configured server token.

Start with site_list

Call site_list first. An empty result means the connection works but no WordPress site is registered. Register a staging site, then inspect it with wp_site_context before choosing a field or action.

Use a reachable endpoint

127.0.0.1 works only when Claude Code and WPGuard run on the same host. Put WPGuard behind an authenticated HTTPS endpoint or a tunnel you control when the client runs elsewhere.

Preview the selected value

Name the registered site and exact target. Preview supported option, post-meta, or post-content changes with apply=False. Review the old value, proposed value, correction result, state tag, and change digest before approval.

Claude Code approval and WPGuard approval are separate controls.

Claude Code decides whether the MCP tool may run. WPGuard decides whether a guarded write matches an approved packet and applicable correction checks.

Keep permissions explicit

Use a recon token for discovery when no write is needed. Mutate and admin tokens expose broader operations. A caller with mutate access can approve packets, so enforce a separate human reviewer outside WPGuard when your workflow requires identity separation.

Verify desktop and mobile

After the write, ask WPGuard to capture both viewports and check the expected text, headings, overflow, and broken images. The receipt keeps the screenshots and their hashes with the result.

The WPGuard connection guide documents token scopes and remote access. The security boundary documents the operations each control covers.

Connect Claude Code to one staging site.

List the sites. Inspect the target. Preview one reversible change.