Filter uncanny-automator

automator_mcp_client_sdk_url

Filters the API client SDK URL, allowing for customization of the SDK endpoint.

add_filter( 'automator_mcp_client_sdk_url', $callback, 10, 1 );

Description

Filters the SDK URL for the MCP client API. Developers can use this hook to dynamically change the SDK endpoint, for example, to point to a local development server or a custom CDN. The hook fires before the URL is validated and used.


Usage

add_filter( 'automator_mcp_client_sdk_url', 'your_function_name', 10, 1 );

Parameters

$url (mixed)
This parameter contains the URL for the client SDK, either explicitly defined by a constant or a default value.

Return Value

The filtered value.


Examples

/**
 * Filter the SDK URL to use a staging environment for development purposes.
 *
 * This example demonstrates how to conditionally change the SDK URL based on
 * a WordPress constant that might be set in a local development environment.
 *
 * @param string $url The original SDK URL.
 * @return string The modified SDK URL.
 */
add_filter( 'automator_mcp_client_sdk_url', function( $url ) {
	// Check if a staging environment constant is defined.
	if ( defined( 'MY_AUTOMATOR_STAGING_SDK' ) && MY_AUTOMATOR_STAGING_SDK === true ) {
		// If staging is enabled, use a specific staging URL.
		return 'https://staging.sdk.example.com/api';
	}

	// Otherwise, return the original URL.
	return $url;
}, 10, 1 );

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/application/mcp/class-mcp-client.php:568

private function get_sdk_url(): string {
		// Check if developer explicitly defined a custom SDK URL.
		$is_custom_url = defined( 'AUTOMATOR_MCP_CLIENT_SDK_URL' ) && AUTOMATOR_MCP_CLIENT_SDK_URL;

		$url = $is_custom_url
			? AUTOMATOR_MCP_CLIENT_SDK_URL
			: self::SDK_URL;

		// Only validate URLs that aren't explicitly defined by developers.
		// This allows localhost URLs for development while protecting against injection in production.
		if ( ! $is_custom_url && ! wp_http_validate_url( $url ) ) {
			$url = self::SDK_URL;
		}

		// Allow URL overwrite via filter.
		$url = apply_filters( 'automator_mcp_client_sdk_url', $url );

		// Append license hash for beta enrollment check.
		$license_key = Api_Server::get_license_key();
		if ( ! empty( $license_key ) ) {
			$license_hash = hash_hmac( 'sha256', $license_key, $license_key );
			$url          = add_query_arg( 'l', $license_hash, $url );
		}

		// Append plugin version for cache busting.
		$version = AUTOMATOR_PLUGIN_VERSION; // No need to check constant - defined in main plugin file.
		$url     = add_query_arg( 'v', $version, $url );

		return $url;
	}


Scroll to Top