Skip to content

feat(ai): add MCP activity log link and Tracks analytics events#48298

Merged
eoigal merged 6 commits into
trunkfrom
aiint-357-jetpack-ai-mcp-activity-log-and-metrics
May 1, 2026
Merged

feat(ai): add MCP activity log link and Tracks analytics events#48298
eoigal merged 6 commits into
trunkfrom
aiint-357-jetpack-ai-mcp-activity-log-and-metrics

Conversation

@eoigal
Copy link
Copy Markdown
Contributor

@eoigal eoigal commented Apr 24, 2026

Fixes #

Proposed changes

  • Add an "Activity log" link card to the MCP hub, shown when MCP is enabled. The URL is computed in PHP: on Atomic sites it uses https://wordpress.com/activity-log/{host} directly (matching jetpack-mu-wpcom's sidebar behavior); on self-hosted/JN it uses the cloud-activity-log-wp-menu redirect slug. The resolved URL is passed to React as activityLogUrl in the jetpackAiSettings inline script.
  • Use wp_parse_url( home_url(), PHP_URL_HOST ) for the Atomic URL to avoid broken links on subdirectory installs where get_site_suffix() can return values containing ::.
  • Add three Tracks analytics events to the MCP settings UI:
    • jetpack_mcp_settings_viewed — fires on page load when the user has MCP access
    • jetpack_mcp_enabled_toggled — fires when the site-level MCP toggle is changed, with { enabled: bool }
    • jetpack_mcp_allowlist_updated — fires on per-tool and category "Enable all" toggles, with { tool_id?, enabled, tool_count?, view: 'read'|'write' }

Related product discussion/links

Does this pull request change what data or activity we track or use?

Yes — adds three new Tracks events (jetpack_mcp_settings_viewed, jetpack_mcp_enabled_toggled, jetpack_mcp_allowlist_updated) as specified in the PRD's Data Tracking Requirements section.

Testing instructions

Activity log link:

  1. On a self-hosted Jetpack site connected to WordPress.com, go to wp-admin/admin.php?page=ai
  2. Enable MCP access using the toggle
  3. Verify an "Activity log" card appears below "Connect external AI agent"
  4. Click it — on Atomic it should open https://wordpress.com/activity-log/{domain}; on self-hosted/JN it should open https://cloud.jetpack.com/activity-log/{blogId}
  5. Disable MCP — confirm the activity log card disappears

Tracks events (requires MC/Tracks test environment):

  1. Navigate to wp-admin/admin.php?page=ai — confirm jetpack_mcp_settings_viewed fires once
  2. Toggle the "Enable MCP access" toggle on/off — confirm jetpack_mcp_enabled_toggled fires with correct enabled value
  3. Go to Read or Write sub-view, toggle an individual tool — confirm jetpack_mcp_allowlist_updated fires with tool_id, enabled, and view
  4. Use the "Enable all" category toggle — confirm jetpack_mcp_allowlist_updated fires with tool_count and view

@eoigal eoigal added the [Status] Needs Review This PR is ready for review. label Apr 24, 2026
@eoigal eoigal self-assigned this Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack), and enable the aiint-357-jetpack-ai-mcp-activity-log-and-metrics branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack aiint-357-jetpack-ai-mcp-activity-log-and-metrics

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions github-actions Bot added [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Admin Page React-powered dashboard under the Jetpack menu labels Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen as soon as you deploy your changes after merging this PR (PCYsg-Jjm-p2).
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly:
    • Scheduled release: May 5, 2026
    • Code freeze: May 4, 2026

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented Apr 24, 2026

Code Coverage Summary

Coverage changed in 5 files.

File Coverage Δ% Δ Uncovered
projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-ai-page.php 0/60 (0.00%) 0.00% 7 💔
projects/plugins/jetpack/_inc/client/ai/main.jsx 0/18 (0.00%) 0.00% 3 ❤️‍🩹
projects/plugins/jetpack/_inc/client/ai/mcp/read.jsx 0/54 (0.00%) 0.00% 2 ❤️‍🩹
projects/plugins/jetpack/_inc/client/ai/mcp/write.jsx 0/54 (0.00%) 0.00% 2 ❤️‍🩹
projects/plugins/jetpack/_inc/client/ai/mcp/index.jsx 0/41 (0.00%) 0.00% 1 ❤️‍🩹

Full summary · PHP report · JS report

Coverage check overridden by I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. .

@eoigal eoigal added the I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. label Apr 27, 2026
@eoigal eoigal force-pushed the aiint-357-jetpack-ai-mcp-activity-log-and-metrics branch 2 times, most recently from d0c7d6d to fec715c Compare April 28, 2026 09:32
@eoigal eoigal requested a review from Copilot April 28, 2026 09:34
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 Activity Log entry point and instrumentation to the Jetpack AI MCP settings admin UI, so users can navigate to the site’s Activity Log and product can measure MCP settings usage.

Changes:

  • Exposes an activityLogUrl value to the AI admin React app and renders a new “Activity log” action card when MCP is enabled.
  • Adds new Tracks events for MCP settings page view, site-level toggle changes, and allowlist changes.
  • Adds a Jetpack changelog fragment describing the feature.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
projects/plugins/jetpack/changelog/aiint-357-jetpack-ai-mcp-activity-log-and-metrics Changelog entry for the Activity Log link + analytics events.
projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-ai-page.php Computes and inlines activityLogUrl into jetpackAiSettings for the React app.
projects/plugins/jetpack/_inc/client/ai/main.jsx Fires “settings viewed” Tracks event and passes activityLogUrl into the hub component.
projects/plugins/jetpack/_inc/client/ai/mcp/index.jsx Adds site-level toggle Tracks event and renders the Activity Log action card.
projects/plugins/jetpack/_inc/client/ai/mcp/read.jsx Adds allowlist Tracks events for per-tool and per-category toggles (read view).
projects/plugins/jetpack/_inc/client/ai/mcp/write.jsx Adds allowlist Tracks events for per-tool and per-category toggles (write view).
projects/plugins/jetpack/_inc/client/ai/mcp/style.scss Styling tweaks to support the new action card and link-row rendering.
Comments suppressed due to low confidence (1)

projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-ai-page.php:99

  • This page records Tracks events from the React bundle, but it doesn’t enqueue the Tracks client (jp-tracks / w.js) or inject window.jpTracksContext.blog_id (usually via Automattic\Jetpack\Connection\Initial_State::render_script). Without those, events may never be sent and/or won’t get a blog_id injected. Consider mirroring class.jetpack-react-page.php by conditionally enqueuing jp-tracks when connected & not offline, and rendering the Connection initial state for this handle.
		$blog_id     = Connection_Manager::get_site_id( true );
		$site_suffix = ( new Status() )->get_site_suffix();
		// On Atomic, jetpack-mu-wpcom replaces the cloud redirect with a direct WPCOM URL.
		// Mirror that behaviour here so the activity log link resolves consistently.
		$activity_log_url = ( new Host() )->is_woa_site()
			? 'https://wordpress.com/activity-log/' . $site_suffix
			: Redirect::get_url( 'cloud-activity-log-wp-menu', array( 'site' => $blog_id ? $blog_id : $site_suffix ) );

		wp_enqueue_script(
			'jetpack-ai-admin',
			plugins_url( '_inc/build/jetpack-ai-admin.js', JETPACK__PLUGIN_FILE ),
			$script_deps,
			$script_version,
			true
		);

		wp_set_script_translations( 'jetpack-ai-admin', 'jetpack' );

Comment thread projects/plugins/jetpack/_inc/client/ai/main.jsx Outdated
Comment thread projects/plugins/jetpack/_inc/client/ai/mcp/index.jsx Outdated
Comment thread projects/plugins/jetpack/_inc/client/ai/mcp/read.jsx
Comment thread projects/plugins/jetpack/_inc/client/ai/mcp/read.jsx
Comment thread projects/plugins/jetpack/_inc/client/ai/mcp/write.jsx
Comment thread projects/plugins/jetpack/_inc/client/ai/mcp/write.jsx
Comment thread projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-ai-page.php Outdated
@eoigal eoigal requested a review from a team as a code owner April 29, 2026 07:30
@github-actions github-actions Bot added the Actions GitHub actions used to automate some of the work around releases and repository management label Apr 29, 2026
@eoigal eoigal force-pushed the aiint-357-jetpack-ai-mcp-activity-log-and-metrics branch from db10db1 to bf3315b Compare April 29, 2026 07:36
Comment thread .github/files/setup-wordpress-env.sh Outdated
eoigal and others added 6 commits April 29, 2026 19:07
- Add activity log link card to MCP hub (links to calypso-activity-log via siteRawUrl)
- Expose siteRawUrl via jetpackAiSettings inline script using Status::get_site_suffix()
- Add jp_mcp_settings_viewed on page load, jp_mcp_enabled_toggled on main toggle,
  and jp_mcp_allowlist_updated on per-tool and category bulk toggles

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use cloud-activity-log-wp-menu redirect slug with blogId (same as Jetpack
  sidebar) so the link correctly resolves to wordpress.com on Atomic and
  cloud.jetpack.com on Jurassic Ninja / self-hosted
- Add color/text-decoration resets to __connect-row for when it renders as <a>
- Remove siteRawUrl from McpHub props and jetpackAiSettings (not needed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Compute activityLogUrl in PHP: use direct wordpress.com/activity-log/$domain
  on Atomic (matching jetpack-mu-wpcom sidebar behavior) and the cloud redirect
  for self-hosted, then pass it to JS via jetpackAiSettings
- Add box-sizing: border-box to __connect-row so <a> width:100% + padding
  doesn't overflow the card (fixes chevron appearing outside container)
- Add overflow: hidden via __action-card on Cards wrapping connect-rows so
  hover background respects the card's rounded corners

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… on Write row

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ty log URL

- Rename all Tracks events from jp_ to jetpack_ prefix so @automattic/jetpack-analytics
  records them (jp_ events are silently dropped by the analytics library)
- Use wp_parse_url(home_url(), PHP_URL_HOST) instead of get_site_suffix() for the
  Atomic activity log URL to avoid broken links on subdirectory installs where
  get_site_suffix() can return values containing '::'

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@eoigal eoigal force-pushed the aiint-357-jetpack-ai-mcp-activity-log-and-metrics branch from bf3315b to 914dcfb Compare April 29, 2026 18:07
@eoigal eoigal requested a review from anomiex April 29, 2026 18:07
@anomiex
Copy link
Copy Markdown
Contributor

anomiex commented Apr 29, 2026

I'll leave review of the code to someone more familiar with the feature, now that the CI is cleaned up. 🙂

@anomiex anomiex removed their request for review April 29, 2026 19:32
Copy link
Copy Markdown
Contributor

@sergeymitr sergeymitr left a comment

Choose a reason for hiding this comment

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

Works well 👍

It took me some time to find a way to come back from "Read" or "Write" screens, it wasn't obvious that you can click "AI" to come back.
So maybe we could add an arrow similar to WPCOM MCP settings to make it easier to go back to the main AI settings screen?

@eoigal
Copy link
Copy Markdown
Contributor Author

eoigal commented May 1, 2026

There's no established Jetpack admin pattern for a back arrow in breadcrumb, so going to merge this as is. Thanks for reviews.

@eoigal eoigal merged commit 4e4d5d3 into trunk May 1, 2026
71 checks passed
@eoigal eoigal deleted the aiint-357-jetpack-ai-mcp-activity-log-and-metrics branch May 1, 2026 10:23
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels May 1, 2026
@github-actions github-actions Bot added this to the jetpack/15.8 milestone May 1, 2026
Copilot AI pushed a commit to dognose24/jetpack that referenced this pull request May 4, 2026
…mattic#48298)

* feat(ai): add MCP activity log link and Tracks analytics events

- Add activity log link card to MCP hub (links to calypso-activity-log via siteRawUrl)
- Expose siteRawUrl via jetpackAiSettings inline script using Status::get_site_suffix()
- Add jp_mcp_settings_viewed on page load, jp_mcp_enabled_toggled on main toggle,
  and jp_mcp_allowlist_updated on per-tool and category bulk toggles

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ai): fix activity log link URL and anchor link styles

- Use cloud-activity-log-wp-menu redirect slug with blogId (same as Jetpack
  sidebar) so the link correctly resolves to wordpress.com on Atomic and
  cloud.jetpack.com on Jurassic Ninja / self-hosted
- Add color/text-decoration resets to __connect-row for when it renders as <a>
- Remove siteRawUrl from McpHub props and jetpackAiSettings (not needed)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ai): fix activity log URL, chevron overflow, and hover corner bleed

- Compute activityLogUrl in PHP: use direct wordpress.com/activity-log/$domain
  on Atomic (matching jetpack-mu-wpcom sidebar behavior) and the cloud redirect
  for self-hosted, then pass it to JS via jetpackAiSettings
- Add box-sizing: border-box to __connect-row so <a> width:100% + padding
  doesn't overflow the card (fixes chevron appearing outside container)
- Add overflow: hidden via __action-card on Cards wrapping connect-rows so
  hover background respects the card's rounded corners

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ai): add overflow hidden to access card to fix hover corner bleed on Write row

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ai): address Copilot review — rename Tracks events and fix activity log URL

- Rename all Tracks events from jp_ to jetpack_ prefix so @automattic/jetpack-analytics
  records them (jp_ events are silently dropped by the analytics library)
- Use wp_parse_url(home_url(), PHP_URL_HOST) instead of get_site_suffix() for the
  Atomic activity log URL to avoid broken links on subdirectory installs where
  get_site_suffix() can return values containing '::'

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(ai): rename remaining jp_ Tracks events to jetpack_ prefix

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: dognose24 <6869813+dognose24@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Actions GitHub actions used to automate some of the work around releases and repository management Admin Page React-powered dashboard under the Jetpack menu I don't care about code coverage for this PR Use this label to ignore the check for insufficient code coveage. [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Status] UI Changes Add this to PRs that change the UI so documentation can be updated.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants