Filter
uncanny-automator
automator_mcp_public_key
Filters the public key used for API integrations, allowing modification before it's applied.
add_filter( 'automator_mcp_public_key', $callback, 10, 3 );
Description
Filters the public key before it's returned by the API client. Developers can modify the PEM-encoded public key, its associated version, and the record data. This hook is useful for dynamically altering or validating the public key used for API communication.
Usage
add_filter( 'automator_mcp_public_key', 'your_function_name', 10, 3 );
Parameters
-
$pem(mixed) - This parameter contains the public key data, likely in PEM format, that will be used for API communication.
-
$version(mixed) - This parameter contains the public key in PEM format.
-
$record(mixed) - This parameter represents the version identifier for the public key.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to hook into the 'automator_mcp_public_key' filter.
*
* This example demonstrates how to modify the public key before it's used.
* It might be useful to obfuscate or further process the key based on specific needs,
* although modifying a public key directly is generally not recommended for security reasons.
* This is more for demonstration of the hook's functionality.
*
* @param string $pem The public key in PEM format.
* @param string $version The version of the public key.
* @param array $record_array An array representation of the public key record.
* @return string The modified public key in PEM format.
*/
function my_automator_modify_public_key( $pem, $version, $record_array ) {
// In a real-world scenario, you'd have a more sophisticated logic here.
// For this example, we'll just prepend a string to the PEM if the version is 'v2'.
// This is purely illustrative and not a recommended security practice.
if ( 'v2' === $version ) {
$pem = "--- CUSTOM_MODIFICATION_FOR_V2 ---n" . $pem;
}
// You could also potentially log information about the key being used.
error_log( "Automator public key used. Version: {$version}. Record ID: " . ( isset( $record_array['id'] ) ? $record_array['id'] : 'N/A' ) );
// Always return the modified value.
return $pem;
}
// Add the filter to WordPress.
// The '3' indicates that our callback function accepts 3 arguments ($pem, $version, $record_array).
add_filter( 'automator_mcp_public_key', 'my_automator_modify_public_key', 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/api/transports/model-context-protocol/client/class-client-public-key-manager.php:135
public function get_public_key( bool $force_refresh = false ): string {
$record = $this->resolve_record( $force_refresh );
$base64 = $record->get_base64();
$version = $record->get_version();
if ( '' === $base64 ) {
return '';
}
$pem = $this->convert_base64_to_pem( $base64 );
return apply_filters( 'automator_mcp_public_key', $pem, $version, $record->to_array() );
}