Skip to content

Commit e228211

Browse files
eoigalCopilot
andauthored
Update/mcp actor (#47223)
* MCP: enrich actor * Add changelog entries. * Update projects/packages/sync/changelog/update-mcp-actor Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update projects/packages/sync/src/class-listener.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fa4b30c commit e228211

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: added
3+
4+
Sync: Add MCP information to the actor.

projects/packages/sync/src/class-listener.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,30 @@ public function get_actor( $current_filter, $args ) {
453453
$actor['user_agent'] = isset( $_SERVER['HTTP_USER_AGENT'] ) ? filter_var( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : 'unknown';
454454
}
455455

456+
$raw_mcp_header = '';
457+
if ( isset( $_SERVER['HTTP_X_WPCOM_MCP'] ) && is_string( $_SERVER['HTTP_X_WPCOM_MCP'] ) ) {
458+
$raw_mcp_header = trim( wp_unslash( $_SERVER['HTTP_X_WPCOM_MCP'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitization happens below.
459+
}
460+
461+
if ( ! empty( $raw_mcp_header ) && preg_match( '/^[A-Za-z0-9+\/=]+$/', $raw_mcp_header ) ) {
462+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- Decoding MCP header payload.
463+
$decoded = base64_decode( $raw_mcp_header, true );
464+
if ( false !== $decoded ) {
465+
$mcp_data = json_decode( $decoded, true );
466+
if ( is_array( $mcp_data ) ) {
467+
if ( isset( $mcp_data['mcp_client_name'] ) && is_string( $mcp_data['mcp_client_name'] ) ) {
468+
$actor['mcp_client_name'] = sanitize_text_field( $mcp_data['mcp_client_name'] );
469+
}
470+
if ( isset( $mcp_data['mcp_client_version'] ) && is_string( $mcp_data['mcp_client_version'] ) ) {
471+
$actor['mcp_client_version'] = sanitize_text_field( $mcp_data['mcp_client_version'] );
472+
}
473+
if ( ! empty( $actor['mcp_client_name'] ) || ! empty( $actor['mcp_client_version'] ) ) {
474+
$actor['is_mcp_agent'] = true;
475+
}
476+
}
477+
}
478+
}
479+
456480
return $actor;
457481
}
458482

0 commit comments

Comments
 (0)