Expose Server-Timing, database queries, and environment info to Chrome DevTools for agents#2579
Expose Server-Timing, database queries, and environment info to Chrome DevTools for agents#2579adamsilverstein wants to merge 3 commits into
Conversation
Register read-only tools with the experimental Chrome DevTools for agents third-party tools API so AI agents can inspect Server-Timing metrics, database queries (when SAVEQUERIES is enabled), and environment info while debugging page performance. Access is gated on a filterable capability defaulting to manage_options. See #2553
Cover hook wiring, capability gating and filtering, script module enqueueing, JSON data output, environment info shape, and database query mapping including SQL truncation and malformed entries.
Dispatch a synthetic devtoolstooldiscovery event to assert the tool group and each tool's output for an administrator, and assert that neither the data blob nor the discovery listener is present for logged-out visitors. Registers a performance-lab Playwright project.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## trunk #2579 +/- ##
==========================================
+ Coverage 70.35% 70.50% +0.14%
==========================================
Files 91 93 +2
Lines 7867 7940 +73
==========================================
+ Hits 5535 5598 +63
- Misses 2332 2342 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Addresses #2553
Adds an integration with the experimental Chrome DevTools third-party tools API to Performance Lab, so AI agents connected through the Chrome DevTools MCP server (with
--categoryExperimentalThirdParty=true) can inspect WordPress server-side performance state while debugging a page. This is a separate approach from #2571, which exposes Optimization Detective's URL Metric; the two integrations are independent and complementary (each registers its own tool group).Three read-only tools are registered under a "WordPress Performance Lab" tool group:
get_server_timing_metrics- theServer-Timingmetrics sent for the current page load, read client-side from the Navigation Timing API (same-originServer-Timingheaders are exposed to page JS), so this costs nothing extra server-side and composes with the existing per-metricaccess_capgating.get_database_queries- the SQL queries executed while rendering the page (up until the end ofwp_footer), including per-query duration and caller stack, plus totals. Requires theSAVEQUERIESconstant; when it is not enabled the tool explains how to enable it so agents can guide the user.get_environment_info- WordPress/PHP versions, active theme, persistent object cache status,WP_DEBUG/SAVEQUERIESstate, multisite flag, and active plugins.Relevant technical choices
WP_DEBUG-gated. The script module and the data blob are only output for users with a filterable capability (perflab_devtools_capability, defaultmanage_options), following the Server-Timingaccess_capmodel. This works on production sites for administrators and exposes nothing to unauthenticated visitors or regular users.application/jsonscript tag at the end ofwp_footer(JSON_HEX_TAGprevents script-tag breakout), since database queries are per-request and cannot be fetched after the fact via REST.wp_enqueue_script_module(), shipped unbuilt with a webpack-copied.min.js, matching repo conventions. Tool names/descriptions are intentionally not internationalized since they are consumed by AI agents.includes/devtools/feature area in Performance Lab following the existingload.php/helper.php/hooks.phplayout.devtoolstooldiscoveryevent to assert the tool group contents and executes each tool, and asserts nothing is exposed to logged-out visitors.How to test
npm install && npm run build:plugin:performance-lab, run a site with Performance Lab active, defineSAVEQUERIESastrue, and log in as an administrator in Chrome.--categoryExperimentalThirdParty=trueand attach it to that browser.list_3p_developer_tools). Expect a "WordPress Performance Lab" group with the three tools.execute_3p_developer_tool:get_server_timing_metricsreturns the metrics enabled under Settings > Performance.get_database_queriesreturns the page's queries (or an explanation ifSAVEQUERIESis off).get_environment_inforeturns the environment summary.perflab-devtools-datanor thedevtools-discoverymodule.Automated tests:
npm run test-php:performance-lab(includes the newdevtoolsgroup)npm run test-e2e:performance-labUse of AI Tools
This PR was implemented with Claude Code based on my direction and plan (review of the Chrome DevTools third-party tools API, implementation, and tests). I reviewed, refined, and tested the result.