[PoC] WP Rocket Abilities and MCP server implementation#8180
[PoC] WP Rocket Abilities and MCP server implementation#8180remyperona wants to merge 30 commits into
Conversation
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| CodeStyle | 1 minor |
| Complexity | 3 medium |
🟢 Metrics 62 complexity · 1 duplication
Metric Results Complexity 62 Duplication 1
🟢 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%) 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.
There was a problem hiding this comment.
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) |
|
|
||
| if ( ! empty( $input['include_metrics'] ) ) { | ||
| $args['fields'][] = 'metric_data'; | ||
| } |
There was a problem hiding this comment.
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.
| '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', | ||
| ], | ||
| ], | ||
| ], |
There was a problem hiding this comment.
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.
| Functions\expect( 'get_rocket_option' ) | ||
| ->with( $option_name ) | ||
| ->andReturn( $previous_value ); | ||
|
|
||
| Functions\expect( 'update_rocket_option' ) | ||
| ->once() | ||
| ->with( $option_name, $expected['new_value'] ); |
There was a problem hiding this comment.
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).
| 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'] ); |
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
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.jsonfile. Here is an example: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:
New dependencies
wordpress/mcp-adapterMandatory Checklist
Code validation
Code style
Additional Checks