PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.3
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.3
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 2.2.9 2.3.0 2.3.1 All 196 releases
← All changes | includes/mcp/class-convertkit-mcp.php +153 -5 3.4.03.4.3 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 *
@@ -259,10 +388,11 @@
259 388 */
260 389 public function register_mcp_server( $adapter ) {
261 390
262 391 // Bail if the MCP server isn't enabled.
263 - $settings = new ConvertKit_Settings_MCP();
264 - if ( ! $settings->enabled() ) {
392 + $settings = new ConvertKit_Settings();
393 + $mcp_settings = new ConvertKit_Settings_MCP();
394 + if ( ! $mcp_settings->enabled() ) {
265 395 return;
266 396 }
267 397
268 398 // Get abilities.
@@ -273,10 +403,22 @@
273 403 foreach ( $abilities as $ability ) {
274 404 $ability_names[] = $ability->get_name();
275 405 }
276 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 +
277 419 // Create the MCP server.
278 - $adapter->create_server(
420 + $result = $adapter->create_server(
279 421 self::SERVER_ID,
280 422 self::SERVER_NAMESPACE,
281 423 self::SERVER_ROUTE,
282 424 __( 'Kit WordPress Plugin MCP', 'convertkit' ),
@@ -285,11 +427,17 @@
285 427 array( 'WP\\MCP\\Transport\\HttpTransport' ),
286 428 'WP\\MCP\\Infrastructure\\ErrorHandling\\ErrorLogMcpErrorHandler',
287 429 'WP\\MCP\\Infrastructure\\Observability\\NullMcpObservabilityHandler',
288 430 $ability_names, // Abilities (Tools).
289 - array(), // Resources.
290 - array() // Prompts.
431 + $resource_names, // Resources.
432 + $prompt_names // Prompts.
291 433 );
434 +
435 + // If an error occured when creating the server, log it.
436 + if ( is_wp_error( $result ) && $settings->debug_enabled() ) {
437 + $log = new ConvertKit_Log( CONVERTKIT_PLUGIN_PATH );
438 + $log->add( 'MCP: create_server(): Error: ' . $result->get_error_message() );
439 + }
292 440
293 441 }
294 442
295 443 }