| @@ -82,13 +82,23 @@ | ||
| 82 | 82 | |
| 83 | 83 | // Register abilities. |
| 84 | 84 | add_action( 'wp_abilities_api_init', array( $this, 'register_abilities' ) ); |
| 85 | 85 | |
| 86 | + // Register resources and prompts. | |
| 87 | + add_action( 'wp_abilities_api_init', array( $this, 'register_resources' ) ); | |
| 88 | + add_action( 'wp_abilities_api_init', array( $this, 'register_prompts' ) ); | |
| 89 | + | |
| 86 | 90 | // Register resource-list abilities (Forms, Tags, Landing Pages, Products). |
| 87 | 91 | // These are owned by the Plugin (not by any single block or feature), |
| 88 | 92 | // so they're added here rather than via a per-class register_abilities(). |
| 89 | 93 | add_filter( 'convertkit_abilities', array( $this, 'register_resource_abilities' ) ); |
| 90 | 94 | |
| 95 | + // Register MCP resources (live-state lists, account, settings and reference docs). | |
| 96 | + add_filter( 'convertkit_resources', array( $this, 'register_mcp_resources' ) ); | |
| 97 | + | |
| 98 | + // Register MCP prompts (guided workflows). | |
| 99 | + add_filter( 'convertkit_prompts', array( $this, 'register_mcp_prompts' ) ); | |
| 100 | + | |
| 91 | 101 | // Register settings get / update abilities for each Plugin settings |
| 92 | 102 | // These are owned by the Plugin (not by any single feature), |
| 93 | 103 | // so they're added here rather than via a per-class register_abilities(). |
| 94 | 104 | add_filter( 'convertkit_abilities', array( $this, 'register_settings_abilities' ) ); |
| @@ -203,8 +213,69 @@ | ||
| 203 | 213 | |
| 204 | 214 | } |
| 205 | 215 | |
| 206 | 216 | /** |
| 217 | + * Appends the MCP resources (live-state lists, account, settings and | |
| 218 | + * reference docs) to the convertkit_resources filter, so they are | |
| 219 | + * registered with the Abilities API and exposed as MCP Resources. | |
| 220 | + * | |
| 221 | + * @since 3.5.0 | |
| 222 | + * | |
| 223 | + * @param array $resources Resources to register. | |
| 224 | + * @return array | |
| 225 | + */ | |
| 226 | + public function register_mcp_resources( $resources ) { | |
| 227 | + | |
| 228 | + $mcp_resources = array( | |
| 229 | + new ConvertKit_MCP_Resource_Forms(), | |
| 230 | + new ConvertKit_MCP_Resource_Tags(), | |
| 231 | + new ConvertKit_MCP_Resource_Landing_Pages(), | |
| 232 | + new ConvertKit_MCP_Resource_Products(), | |
| 233 | + new ConvertKit_MCP_Resource_Account(), | |
| 234 | + new ConvertKit_MCP_Resource_Settings(), | |
| 235 | + new ConvertKit_MCP_Resource_Overview(), | |
| 236 | + new ConvertKit_MCP_Resource_Forms_Reference(), | |
| 237 | + new ConvertKit_MCP_Resource_Restrict_Content_Reference(), | |
| 238 | + new ConvertKit_MCP_Resource_Settings_Reference(), | |
| 239 | + ); | |
| 240 | + | |
| 241 | + foreach ( $mcp_resources as $resource ) { | |
| 242 | + $resources[ $resource->get_name() ] = $resource; | |
| 243 | + } | |
| 244 | + | |
| 245 | + return $resources; | |
| 246 | + | |
| 247 | + } | |
| 248 | + | |
| 249 | + /** | |
| 250 | + * Appends the MCP prompts (guided workflows) to the convertkit_prompts | |
| 251 | + * filter, so they are registered with the Abilities API and exposed as | |
| 252 | + * MCP Prompts. | |
| 253 | + * | |
| 254 | + * @since 3.5.0 | |
| 255 | + * | |
| 256 | + * @param array $prompts Prompts to register. | |
| 257 | + * @return array | |
| 258 | + */ | |
| 259 | + public function register_mcp_prompts( $prompts ) { | |
| 260 | + | |
| 261 | + $mcp_prompts = array( | |
| 262 | + new ConvertKit_MCP_Prompt_Setup(), | |
| 263 | + new ConvertKit_MCP_Prompt_Add_Form(), | |
| 264 | + new ConvertKit_MCP_Prompt_Restrict_Content(), | |
| 265 | + new ConvertKit_MCP_Prompt_Configure_Broadcasts_Import(), | |
| 266 | + new ConvertKit_MCP_Prompt_Audit(), | |
| 267 | + ); | |
| 268 | + | |
| 269 | + foreach ( $mcp_prompts as $prompt ) { | |
| 270 | + $prompts[ $prompt->get_name() ] = $prompt; | |
| 271 | + } | |
| 272 | + | |
| 273 | + return $prompts; | |
| 274 | + | |
| 275 | + } | |
| 276 | + | |
| 277 | + /** | |
| 207 | 278 | * Register the 'kit' ability category. |
| 208 | 279 | * |
| 209 | 280 | * @since 3.4.0 |
| 210 | 281 | */ |
| @@ -249,8 +320,66 @@ | ||
| 249 | 320 | |
| 250 | 321 | } |
| 251 | 322 | |
| 252 | 323 | /** |
| 324 | + * Register MCP resources with the WordPress Abilities API. | |
| 325 | + * | |
| 326 | + * @since 3.4.2 | |
| 327 | + */ | |
| 328 | + public function register_resources() { | |
| 329 | + | |
| 330 | + // Get resources. | |
| 331 | + $resources = convertkit_get_resources(); | |
| 332 | + | |
| 333 | + // Bail if no resources are available. | |
| 334 | + if ( ! count( $resources ) ) { | |
| 335 | + return; | |
| 336 | + } | |
| 337 | + | |
| 338 | + // Iterate through resources, registering each as an ability. | |
| 339 | + foreach ( $resources as $resource ) { | |
| 340 | + | |
| 341 | + // Skip if this resource is not an instance of ConvertKit_MCP_Resource. | |
| 342 | + if ( ! ( $resource instanceof ConvertKit_MCP_Resource ) ) { | |
| 343 | + continue; | |
| 344 | + } | |
| 345 | + | |
| 346 | + // Register resource. | |
| 347 | + wp_register_ability( $resource->get_name(), $resource->get_ability_args() ); | |
| 348 | + } | |
| 349 | + | |
| 350 | + } | |
| 351 | + | |
| 352 | + /** | |
| 353 | + * Register MCP prompts with the WordPress Abilities API. | |
| 354 | + * | |
| 355 | + * @since 3.4.2 | |
| 356 | + */ | |
| 357 | + public function register_prompts() { | |
| 358 | + | |
| 359 | + // Get prompts. | |
| 360 | + $prompts = convertkit_get_prompts(); | |
| 361 | + | |
| 362 | + // Bail if no prompts are available. | |
| 363 | + if ( ! count( $prompts ) ) { | |
| 364 | + return; | |
| 365 | + } | |
| 366 | + | |
| 367 | + // Iterate through prompts, registering each as an ability. | |
| 368 | + foreach ( $prompts as $prompt ) { | |
| 369 | + | |
| 370 | + // Skip if this prompt is not an instance of ConvertKit_MCP_Prompt. | |
| 371 | + if ( ! ( $prompt instanceof ConvertKit_MCP_Prompt ) ) { | |
| 372 | + continue; | |
| 373 | + } | |
| 374 | + | |
| 375 | + // Register prompt. | |
| 376 | + wp_register_ability( $prompt->get_name(), $prompt->get_ability_args() ); | |
| 377 | + } | |
| 378 | + | |
| 379 | + } | |
| 380 | + | |
| 381 | + /** | |
| 253 | 382 | * Register an MCP server that exposes Kit abilities as MCP tools. |
| 254 | 383 | * |
| 255 | 384 | * @since 3.4.0 |
| 256 | 385 | * |
| @@ -274,8 +403,20 @@ | ||
| 274 | 403 | foreach ( $abilities as $ability ) { |
| 275 | 404 | $ability_names[] = $ability->get_name(); |
| 276 | 405 | } |
| 277 | 406 | |
| 407 | + // Build array of resource names. | |
| 408 | + $resource_names = array(); | |
| 409 | + foreach ( convertkit_get_resources() as $resource ) { | |
| 410 | + $resource_names[] = $resource->get_name(); | |
| 411 | + } | |
| 412 | + | |
| 413 | + // Build array of prompt names. | |
| 414 | + $prompt_names = array(); | |
| 415 | + foreach ( convertkit_get_prompts() as $prompt ) { | |
| 416 | + $prompt_names[] = $prompt->get_name(); | |
| 417 | + } | |
| 418 | + | |
| 278 | 419 | // Create the MCP server. |
| 279 | 420 | $result = $adapter->create_server( |
| 280 | 421 | self::SERVER_ID, |
| 281 | 422 | self::SERVER_NAMESPACE, |
| @@ -286,10 +427,10 @@ | ||
| 286 | 427 | array( 'WP\\MCP\\Transport\\HttpTransport' ), |
| 287 | 428 | 'WP\\MCP\\Infrastructure\\ErrorHandling\\ErrorLogMcpErrorHandler', |
| 288 | 429 | 'WP\\MCP\\Infrastructure\\Observability\\NullMcpObservabilityHandler', |
| 289 | 430 | $ability_names, // Abilities (Tools). |
| 290 | - array(), // Resources. | |
| 291 | - array() // Prompts. | |
| 431 | + $resource_names, // Resources. | |
| 432 | + $prompt_names // Prompts. | |
| 292 | 433 | ); |
| 293 | 434 | |
| 294 | 435 | // If an error occured when creating the server, log it. |
| 295 | 436 | if ( is_wp_error( $result ) && $settings->debug_enabled() ) { |