Search by

humanmade / hm-rest-ability

roborourkejoehoylemissjwo

OAuth2 discovery endpoints and a REST API ability for exposing WordPress to MCP clients via the MCP Adapter

Package info

github.com/humanmade/hm-rest-ability

Type:wordpress-plugin

pkg:composer/humanmade/hm-rest-ability

Statistics

Installs: 973

Dependents: 0

Suggesters: 0

Stars: 6

Open Issues: 10

v1.1.0 2026-11-18 14:19 UTC

README

Give MCP clients such as Claude the whole WordPress REST API through three tools. Any route a plugin registers works straight away, even if the plugin defines no abilities. Built on the Abilities API and the official MCP Adapter.

Features

Works with every REST route

Most plugins have REST endpoints but no abilities. This plugin dispatches any internal REST request, so an agent can use core, WooCommerce, or your own custom routes without writing an ability for each one. Each call runs the route's own permission_callback, so a user can only do what their WordPress capabilities already allow.

MCP tool Ability Methods Annotations
rest-api-read rest-api/read GET, OPTIONS read-only, idempotent
rest-api-write rest-api/write POST, PUT, PATCH —
rest-api-delete rest-api/delete DELETE destructive

The split lets a client auto-approve reads and still ask before a write or a delete.

Low context

  • Three tools, not one per endpoint, so the tool list stays small.
  • GET / returns a condensed route index of a few kilobytes, not the ~1MB core index. On a large site it falls back to a count per namespace and points at GET /<namespace>.
  • OPTIONS /wp/v2/posts returns one route's parameters, only when the agent needs them.
  • Responses are capped at 50KB. A trimmed response says what was left out and how to narrow it with _fields. Oversized GET responses also supply truncated.response_cursor. Call the read tool with that cursor and the same route and params, concatenate the decoded base64-json chunks in byte-offset order, verify total_bytes and sha256, then parse the JSON. Continue until response.next_cursor is null. A 409 means the response changed and the read must restart. Cursors never bypass current permissions.
  • Truncated responses include truncated.sha256 for the complete, JSON-encoded native data. A client can verify an oversized write response by reading its saved resource and matching those bytes. This never repeats the write; a different representation or changed resource cannot establish the original write result.
  • An oversized core REST batch can return truncated.batch_receipt: true. Its data.responses retains one status per request in the original order and omits item bodies and headers. A validation failure keeps data.failed: "validation" and a null entry for each skipped request. Inspect every item status before reporting success or considering a retry.
  • _embed follows WordPress’s normal behaviour, including named relations such as _embed=author.
  • An unknown route returns the nearest real routes, so the agent doesn't have to search again.

Built-in guardrails

  • Delete is always marked destructive, and the write and delete tools ask the client to confirm with the user.
  • Calls are rated routine, site-config or irreversible. A write is site-config when it goes to a core settings, users, plugins, themes or design route, or when the route's own permission check asks for a capability such as install_plugins or manage_options, so a plugin's own installer counts too. OPTIONS adds guidance to the risky routes.
  • Route guidance steers the agent away from common mistakes: new posts stay drafts unless the user asks to publish, content is block markup, and core's design routes explain where their IDs come from.
  • The plugin switches itself off when the site disables AI through WP_AI_SUPPORT or the wp_supports_ai filter (WordPress 7.0+).

Confirmation through elicitation

On clients that support MCP elicitation (2026-07-28), a delete or a write to a risky route first shows the user a confirmation form. Nothing changes until they accept. The confirmation only works for the same user, route and params, and expires after ten minutes. Routine writes, such as editing a post, run straight away. Clients without elicitation run every call straight away.

Your own guardrails

Filters let you tighten access or change the advice, without forking the plugin. See Filters.

Edit part of a post's content

Sending a large post's whole content back to change a few lines is slow and costly, and a model can't reliably copy it exactly. Instead, rest-api-write takes two extra params on any route that returns content.raw:

  • _content_edits: a list of {old_string, new_string, expected_matches}, applied in order. expected_matches defaults to 1.
  • _content_sha256: the content_sha256 from the last read or write of the item.

Any tool response that includes content.raw also has content_sha256. That covers a GET with context=edit and the response to a write, so edits can follow each other without another read.

The server applies the edits and sends a normal write with the new content. The endpoint's permission check, the hm_rest_ability_policy filter, the confirmation prompt and the response cap all see that write. Nothing is saved when:

  • the content changed since it was read
  • an old_string doesn't match expected_matches times
  • the edits would break the nesting of block comments, for example a block that opens inside a group and closes outside it

OPTIONS on a route with block content tells the agent about these params.

Extras

  • media/upload takes a base64 file and adds it to the media library, which the REST tools can't do with JSON params.
  • GET /hm-rest-ability/v1/url-lookup?url=… finds the post or file at a URL, including a production URL on a staging site.

Requirements

  • WordPress 6.9+
  • PHP 8.2+
  • MCP Adapter 0.7.0+. WordPress can't check the version of a required plugin, so check it yourself.

Installation

composer require humanmade/hm-rest-ability

Or upload a release ZIP to /wp-content/plugins/. Then activate MCP Adapter and HM REST Ability.

Filters

Filter Use it to
hm_rest_ability_policy Deny a call that capabilities would allow. It can only narrow access.
hm_rest_ability_route_risk Change a route's risk rating.
hm_rest_ability_needs_confirmation Change which calls ask the user to confirm.
hm_rest_ability_route_guidance Add to, replace or remove the guidance on a route.
hm_rest_ability_max_response_bytes Change the 50KB response cap. 0 turns it off.
hm_rest_ability_max_upload_bytes Change the upload limit. Defaults to wp_max_upload_size().

Examples

Describe a route

Use hm_rest_ability_route_guidance to tell the agent how your site works. Add to the guidance that is already there instead of replacing it, so the built-in risk advice stays. inc/status-field-guidance.php is a working example.

add_filter( 'hm_rest_ability_route_guidance', function ( string $guidance, string $route ): string {
	if ( ! preg_match( '#^/wp/v2/posts#i', $route ) ) {
		return $guidance;
	}

	$note = 'Posts on this site are read by the whole company. Leave new posts as drafts so the author can review and publish them.';

	return '' === $guidance ? $note : $guidance . ' ' . $note;
}, 10, 2 );

Block something outright

Use hm_rest_ability_policy to deny a call. It can only narrow access, never widen it. The route reaches the filter as the caller sent it, and WordPress matches routes without regard to case, so lowercase the route before you compare it. The agent gets a rest_ability_policy_denied error.

add_filter( 'hm_rest_ability_policy', function ( string $decision, string $method, string $route ): string {
	if ( in_array( $method, [ 'GET', 'OPTIONS' ], true ) ) {
		return $decision;
	}

	$route = '/' . ltrim( strtolower( $route ), '/' );

	foreach ( [ '/wp/v2/plugins', '/wp/v2/themes', '/wp/v2/users' ] as $prefix ) {
		if ( str_starts_with( $route, $prefix ) ) {
			return 'deny';
		}
	}

	return $decision;
}, 10, 3 );

Rate a plugin's route as risky

Use hm_rest_ability_route_risk to rate a plugin's route as site-config, so writes to it ask the user to confirm. The arguments are $risk, $route, $method, which is not the same order as the policy filter. A fifth argument, $caps, lists the capabilities the route's permission check asks for. You don't need code for a route that checks manage_options or install_plugins, because it is already rated site-config.

add_filter( 'hm_rest_ability_route_risk', function ( string $risk, string $route, string $method ): string {
	if ( 'routine' !== $risk || 'GET' === $method ) {
		return $risk;
	}

	if ( str_starts_with( strtolower( $route ), '/gf/v2/forms' ) ) {
		return 'site-config';
	}

	return $risk;
}, 10, 3 );

Ask before publishing

Use hm_rest_ability_needs_confirmation to ask the user before a call runs. Confirmation needs a client with elicitation support, and other clients run the call straight away. So use confirmation for "check with me first", and the policy filter for "never".

add_filter( 'hm_rest_ability_needs_confirmation', function ( bool $needs, string $method, string $route, array $params ): bool {
	if ( 'publish' === ( $params['status'] ?? '' ) ) {
		return true;
	}

	return $needs;
}, 10, 4 );

Change the response cap

Use hm_rest_ability_max_response_bytes to change the 50KB response cap. 0 turns it off.

add_filter( 'hm_rest_ability_max_response_bytes', fn () => 20000 );

Agent skill

skills/wordpress-block-content is a skill for agent harnesses such as Claude Code. It explains route discovery, block markup and image uploads, and points at wesper and block-runner when they are installed. It isn't in the release ZIP or the Composer package, so copy it into your project:

cp -r skills/wordpress-block-content /path/to/your-project/.claude/skills/

Development

composer install
npm install
  • composer lint / composer format run PHPCS and PHPCBF.
  • composer test runs the PHPUnit unit tests.
  • npm run test:e2e runs the Playwright tests against WordPress Playground.
  • npm run eval runs model-in-the-loop scenarios against Playground through your local Claude Code. It's local only, not part of CI. See tests/evals/README.md.

Releases are cut from the Release workflow in the Actions tab.

License

GPL-2.0-or-later. See LICENSE.