PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.6
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.6
3.4.6 3.4.5 3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 All 199 releases
← All changes | includes/mcp/class-convertkit-mcp.php +164 -2 3.4.1 → 3.4.6 View file →
@@ -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 *
@@ -271,11 +400,44 @@
271 400
272 401 // Build array of ability names.
273 402 $ability_names = array();
274 403 foreach ( $abilities as $ability ) {
404 +
405 + // Skip if this ability is not an instance of ConvertKit_MCP_Ability.
406 + if ( ! ( $ability instanceof ConvertKit_MCP_Ability ) ) {
407 + continue;
408 + }
409 +
410 + // Add ability name.
275 411 $ability_names[] = $ability->get_name();
276 412 }
277 413
414 + // Build array of resource names.
415 + $resource_names = array();
416 + foreach ( convertkit_get_resources() as $resource ) {
417 +
418 + // Skip if this resource is not an instance of ConvertKit_MCP_Resource.
419 + if ( ! ( $resource instanceof ConvertKit_MCP_Resource ) ) {
420 + continue;
421 + }
422 +
423 + // Add resource name.
424 + $resource_names[] = $resource->get_name();
425 + }
426 +
427 + // Build array of prompt names.
428 + $prompt_names = array();
429 + foreach ( convertkit_get_prompts() as $prompt ) {
430 +
431 + // Skip if this prompt is not an instance of ConvertKit_MCP_Prompt.
432 + if ( ! ( $prompt instanceof ConvertKit_MCP_Prompt ) ) {
433 + continue;
434 + }
435 +
436 + // Add prompt name.
437 + $prompt_names[] = $prompt->get_name();
438 + }
439 +
278 440 // Create the MCP server.
279 441 $result = $adapter->create_server(
280 442 self::SERVER_ID,
281 443 self::SERVER_NAMESPACE,
@@ -286,10 +448,10 @@
286 448 array( 'WP\\MCP\\Transport\\HttpTransport' ),
287 449 'WP\\MCP\\Infrastructure\\ErrorHandling\\ErrorLogMcpErrorHandler',
288 450 'WP\\MCP\\Infrastructure\\Observability\\NullMcpObservabilityHandler',
289 451 $ability_names, // Abilities (Tools).
290 - array(), // Resources.
291 - array() // Prompts.
452 + $resource_names, // Resources.
453 + $prompt_names // Prompts.
292 454 );
293 455
294 456 // If an error occured when creating the server, log it.
295 457 if ( is_wp_error( $result ) && $settings->debug_enabled() ) {