Agent Bridge
Agent-friendly REST API plugin that pairs with an MCP for WordPress
by Your Name · github.com/nonmaskableint/php-agent-bridge · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/nonmaskableint/php-agent-bridge/archive/refs/heads/main.zipA WordPress plugin that exposes a structured, agent-friendly REST API at the agent/v1 namespace. Every write operation is idempotent via the X-Idempotency-Key header. All responses follow a consistent { ok, data/code/message } envelope.
Features
- Idempotent writes — replay-safe via
X-Idempotency-Key - Consistent JSON envelope —
{ ok: bool, data | code + message } - Capability-tiered auth — four permission levels mapped to WordPress capabilities
- Feature-flagged routes — database and CLI endpoints disabled by default
- WooCommerce module — auto-loaded when WooCommerce is active
Installation
Drop the plugin folder into wp-content/plugins/ and activate:
wp plugin activate php-agent-bridge
Activation creates the {prefix}agent_idempotency table via dbDelta.
Authentication
All endpoints use WordPress Application Passwords:
Authorization: Basic base64(username:app_password)
Configuration
Define in wp-config.php:
| Constant | Default | Description |
|---|---|---|
AGENT_BRIDGE_LOG_REQUESTS |
false |
Log requests to wp-content/agent-bridge.log |
AGENT_BRIDGE_IDEMPOTENCY_TTL |
86400 |
Idempotency key TTL in seconds |
AGENT_BRIDGE_CLI_ALLOWLIST |
built-in list | Array of allowed WP-CLI command prefixes |
AGENT_BRIDGE_CLI_OPEN |
false |
Allow any WP-CLI command (denylist-only mode) |
AGENT_BRIDGE_DB_API |
false |
Enable /db/* endpoints |
AGENT_BRIDGE_DB_ALLOW_DDL |
false |
Permit DDL statements in DB API |
Endpoints
See endpoints.md for the full reference.
Routes registered:
GET/POST/PATCH/DELETE /agent/v1/postsGET/POST/PATCH/DELETE /agent/v1/mediaGET/POST/PATCH/DELETE /agent/v1/termsGET/PATCH /agent/v1/optionsGET/POST/PATCH/DELETE /agent/v1/usersGET/POST/PATCH/DELETE /agent/v1/menusGET/POST/PATCH/DELETE /agent/v1/pluginsGET/POST /agent/v1/themesPOST /agent/v1/cli(feature-flagged)GET/POST /agent/v1/db/*(feature-flagged)- WooCommerce routes (auto-loaded when WooCommerce active)
Adding a Route
- Create
includes/Routes/NewThingRoute.phpin namespaceAgentBridge\Routes - Implement
public static function register(): void - Use
Auth::require_*forpermission_callback - Wrap mutating callbacks:
fn($r) => Idempotency::wrap($r, [self::class, 'handler']) - Return
Response::success()/Response::created()/Response::error() - Register in
agent-bridge.phpinside therest_api_initaction
Requirements
- PHP 8.1+
- WordPress 6.0+
License
MIT