Skip to content

[PoC] WP Rocket Abilities and MCP server implementation#8180

Open
remyperona wants to merge 30 commits into
developfrom
feature/mcp
Open

[PoC] WP Rocket Abilities and MCP server implementation#8180
remyperona wants to merge 30 commits into
developfrom
feature/mcp

Conversation

@remyperona
Copy link
Copy Markdown
Contributor

@remyperona remyperona commented Mar 17, 2026

Description

Add 4 WordPress abilities for WP Rocket, and add the MCP server to be able to use the abilities using a MCP client.

Type of change

  • New feature (non-breaking change which adds functionality).

Detailed scenario

What was tested

This PR provides 4 abilities accessible through the MCP server:

  • wp-rocket/get-options: Get a list of WP Rocket options and their status, excluding the ones that are hidden or sensitive.
  • wp-rocket/set-option: Set an option value. The ability requires the option name and the value as inputs.
  • wp-rocket/get-insights-scores: Get a list of Rocket Insights pages currently monitored, with their relevant data.
  • wp-rocket/add-page-insights: Add a page to Rocket Insights. The ability requires an URL as input.

How to test

To test, you need to configure your IDE to connect to a WordPress site with this version of WPR enabled, with a mcp.json file. Here is an example:

{
	"servers": {
		"wordpress-http-default": {
			"command": "npx",
			"args": [
				"-y",
				"@automattic/mcp-wordpress-remote@latest"
			],
			"env": {
				"WP_API_URL": "https://example.org/wp-json/mcp/mcp-adapter-default-server",
				"LOG_FILE": "path/wp-content/mcp-adapter.log",
				"WP_API_USERNAME": "username",
				"WP_API_PASSWORD": "application password"
			}
		}
	},
	"inputs": []
}

Affected Features & Quality Assurance Scope

This PR offers abilities for options and Rocket Insights. It only provides new abilities, without impact on the existing features.

Technical description

Documentation

Adds an MCP server integration to WP Rocket and exposes new WordPress “Abilities” for reading/updating WP Rocket options and interacting with Rocket Insights (list scores, add monitored pages), with accompanying unit/integration tests.

Changes:

  • Add new Abilities module (options get/set) and Rocket Insights abilities (get scores, add page).
  • Initialize the MCP adapter when available and register ability subscribers via service providers.
  • Add unit/integration tests + fixtures for the new abilities and update CI/deps accordingly.

New dependencies

wordpress/mcp-adapter

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

Additional Checks

  • In the case of complex code, I wrote comments to explain it.
  • When possible, I prepared ways to observe the implemented system (logs, data, etc.).
  • I added error handling logic when using functions that could throw errors (HTTP/API request, filesystem, etc.)

@remyperona remyperona self-assigned this Mar 30, 2026
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 2, 2026

Not up to standards ⛔

🔴 Issues 3 medium · 1 minor

Alerts:
⚠ 4 issues (≤ 1 issue of at least minor severity)

Results:
4 new issues

Category Results
CodeStyle 1 minor
Complexity 3 medium

View in Codacy

🟢 Metrics 62 complexity · 1 duplication

Metric Results
Complexity 62
Duplication 1

View in Codacy

🟢 Coverage 91.97% diff coverage · +0.92% coverage variation

Metric Results
Coverage variation +0.92% coverage variation (-0.10%)
Diff coverage 91.97% diff coverage (50.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (d3f6e54) Report Missing Report Missing Report Missing
Head commit (8eb439c) 43939 (+847) 20630 (+796) 46.95% (+0.92%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#8180) 847 779 91.97%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@remyperona remyperona marked this pull request as ready for review April 7, 2026 19:16
Copilot AI review requested due to automatic review settings April 7, 2026 19:16
@remyperona remyperona changed the title MCP for WP Rocket [PoC] WP Rocket Abilities and MCP server implementation Apr 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an MCP server integration to WP Rocket and exposes new WordPress “Abilities” for reading/updating WP Rocket options and interacting with Rocket Insights (list scores, add monitored pages), with accompanying unit/integration tests.

Changes:

  • Add new Abilities module (options get/set) and Rocket Insights abilities (get scores, add page).
  • Initialize the MCP adapter when available and register ability subscribers via service providers.
  • Add unit/integration tests + fixtures for the new abilities and update CI/deps accordingly.

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
tests/Unit/inc/Engine/Admin/RocketInsights/Abilities/GetInsightsScore/ExecuteTest.php Unit test coverage for GetInsightsScore ability execution
tests/Unit/inc/Engine/Admin/RocketInsights/Abilities/AddPageInsights/ExecuteTest.php Unit test coverage for AddPageInsights ability execution
tests/Unit/inc/Engine/Abilities/Options/SetOption/ExecuteTest.php Unit test coverage for SetOption ability execution
tests/Unit/inc/Engine/Abilities/Options/GetOptions/ExecuteTest.php Unit test coverage for GetOptions ability execution
tests/Integration/inc/Engine/Admin/RocketInsights/Abilities/GetInsightsScore/RegisterGetInsightsScoresAbilityTest.php Integration test for registration/execution of get-insights-scores ability
tests/Integration/inc/Engine/Admin/RocketInsights/Abilities/AddPageInsights/RegisterAddPageInsightsAbilityTest.php Integration test for registration/execution of add-page-insights ability
tests/Integration/inc/Engine/Abilities/Options/SetOption/RegisterSetOptionAbilityTest.php Integration test for registration/execution of set-options ability
tests/Integration/inc/Engine/Abilities/Options/GetOptions/RegisterGetOptionsAbilityTest.php Integration test for registration/execution of get-options ability
tests/Integration/bootstrap.php Disables MCP adapter default server during integration tests
tests/Fixtures/inc/Engine/Admin/RocketInsights/Abilities/GetInsightsScore/RegisterGetInsightsScoresAbilityTest.php Fixtures for Rocket Insights scores integration test
tests/Fixtures/inc/Engine/Admin/RocketInsights/Abilities/GetInsightsScore/ExecuteTest.php Fixtures for GetInsightsScore unit test
tests/Fixtures/inc/Engine/Admin/RocketInsights/Abilities/AddPageInsights/RegisterAddPageInsightsAbilityTest.php Fixtures for AddPageInsights integration test
tests/Fixtures/inc/Engine/Admin/RocketInsights/Abilities/AddPageInsights/ExecuteTest.php Fixtures for AddPageInsights unit test
tests/Fixtures/inc/Engine/Abilities/Options/SetOption/RegisterSetOptionAbilityTest.php Fixtures for SetOption integration test
tests/Fixtures/inc/Engine/Abilities/Options/SetOption/ExecuteTest.php Fixtures for SetOption unit test
tests/Fixtures/inc/Engine/Abilities/Options/GetOptions/RegisterGetOptionsAbilityTest.php Fixtures for GetOptions integration test
tests/Fixtures/inc/Engine/Abilities/Options/GetOptions/ExecuteTest.php Fixtures for GetOptions unit test
inc/Plugin.php Registers the new Abilities service provider and subscribers
inc/main.php Bootstraps the MCP adapter when the dependency is present
inc/Engine/Admin/RocketInsights/ServiceProvider.php Registers Rocket Insights ability services + abilities subscriber
inc/Engine/Admin/RocketInsights/Abilities/Subscriber.php Hooks Rocket Insights abilities into the Abilities API init events
inc/Engine/Admin/RocketInsights/Abilities/GetInsightsScore.php Implements and registers the get-insights-scores ability
inc/Engine/Admin/RocketInsights/Abilities/AddPageInsights.php Implements and registers the add-page-insights ability
inc/Engine/Abilities/ServiceProvider.php Registers options abilities and their subscriber
inc/Engine/Abilities/Options/Subscriber.php Hooks options abilities into the Abilities API init events
inc/Engine/Abilities/Options/SetOption.php Implements and registers the set-options ability
inc/Engine/Abilities/Options/GetOptions.php Implements and registers the get-options ability
inc/Engine/Abilities/AbilitiesInterface.php Introduces a shared interface for abilities implementations
inc/classes/admin/class-options-data.php Adds a pre-filter hook for the full options array
composer.json Adds wordpress/mcp-adapter dependency
.github/workflows/test_wprocket.yml Adjusts CI matrix (PHP version coverage)

Comment on lines +183 to +186

if ( ! empty( $input['include_metrics'] ) ) {
$args['fields'][] = 'metric_data';
}
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execute() allows null input (via the registered input schema), but later accesses $input['include_metrics'] unconditionally. When $input is null this will raise a PHP warning for array offset on null. Guard with is_array( $input ) (or normalize $input to an array) before reading include_metrics.

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +122
'data' => [
'type' => 'string',
],
'modified' => [
'type' => 'string',
'format' => 'date-time',
],
'score' => [
'type' => [
'number',
'null',
],
],
'report_url' => [
'type' => [ 'string', 'null' ],
'format' => 'uri',
],
'metric_data' => [
'type' => [
'string',
'null',
],
],
],
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output_schema doesn’t match the actual types returned by RocketInsights rows: data is decoded to an array and metric_data is parsed to an array (see Database\Rows\RocketInsights), and modified is stored as an int timestamp. With strict schema validation this can break ability execution; either adjust the schema to match the real output types or normalize the query results to the declared schema.

Copilot uses AI. Check for mistakes.
Comment thread inc/Engine/Abilities/Options/SetOption.php Outdated
Comment thread inc/Engine/Abilities/Options/SetOption.php
Comment thread inc/Engine/Admin/RocketInsights/Abilities/AddPageInsights.php Outdated
Comment thread .github/workflows/test_wprocket.yml
Comment on lines +68 to +74
Functions\expect( 'get_rocket_option' )
->with( $option_name )
->andReturn( $previous_value );

Functions\expect( 'update_rocket_option' )
->once()
->with( $option_name, $expected['new_value'] );
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation inside the if ( $expected['success'] ) block is inconsistent, which will likely fail PHPCS/WPCS checks and makes the test harder to read. Please fix indentation to match the surrounding code style (tabs, proper nesting).

Suggested change
Functions\expect( 'get_rocket_option' )
->with( $option_name )
->andReturn( $previous_value );
Functions\expect( 'update_rocket_option' )
->once()
->with( $option_name, $expected['new_value'] );
Functions\expect( 'get_rocket_option' )
->with( $option_name )
->andReturn( $previous_value );
Functions\expect( 'update_rocket_option' )
->once()
->with( $option_name, $expected['new_value'] );

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants