Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions includes/mcp/class-convertkit-mcp.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public function __construct() {
// so they're added here rather than via a per-class register_abilities().
add_filter( 'convertkit_abilities', array( $this, 'register_resource_abilities' ) );

// Register MCP resources (live-state lists, account, settings and reference docs).
add_filter( 'convertkit_resources', array( $this, 'register_mcp_resources' ) );

// Register settings get / update abilities for each Plugin settings
// These are owned by the Plugin (not by any single feature),
// so they're added here rather than via a per-class register_abilities().
Expand Down Expand Up @@ -207,6 +210,39 @@ public function register_resource_abilities( $abilities ) {

}

/**
* Appends the MCP resources (live-state lists, account, settings and
* reference docs) to the convertkit_resources filter, so they are
* registered with the Abilities API and exposed as MCP Resources.
*
* @since 3.5.0
*
* @param array $resources Resources to register.
* @return array
*/
public function register_mcp_resources( $resources ) {

$mcp_resources = array(
new ConvertKit_MCP_Resource_Forms(),
new ConvertKit_MCP_Resource_Tags(),
new ConvertKit_MCP_Resource_Landing_Pages(),
new ConvertKit_MCP_Resource_Products(),
new ConvertKit_MCP_Resource_Account(),
new ConvertKit_MCP_Resource_Settings(),
new ConvertKit_MCP_Resource_Overview(),
new ConvertKit_MCP_Resource_Forms_Reference(),
new ConvertKit_MCP_Resource_Restrict_Content_Reference(),
new ConvertKit_MCP_Resource_Settings_Reference(),
);

foreach ( $mcp_resources as $resource ) {
$resources[ $resource->get_name() ] = $resource;
}

return $resources;

}

/**
* Register the 'kit' ability category.
*
Expand Down
110 changes: 110 additions & 0 deletions includes/mcp/resources/class-convertkit-mcp-resource-account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Kit MCP Resource: Account.
*
* @package ConvertKit
* @author ConvertKit
*/

/**
* Exposes the connected Kit account (name, plan, primary email) as an MCP
* Resource (`kit://account`), read from the cached account data.
*
* @package ConvertKit
* @author ConvertKit
*/
class ConvertKit_MCP_Resource_Account extends ConvertKit_MCP_Resource {

/**
* Returns the resource name.
*
* @since 3.5.0
*
* @return string
*/
public function get_name() {

return 'kit/account';

}

/**
* Returns the resource URI.
*
* @since 3.5.0
*
* @return string
*/
public function get_uri() {

return 'kit://account';

}

/**
* Returns the resource label.
*
* @since 3.5.0
*
* @return string
*/
public function get_label() {

return __( 'Kit Account', 'convertkit' );

}

/**
* Returns the resource description.
*
* @since 3.5.0
*
* @return string
*/
public function get_description() {

return __( 'The connected Kit account (name, plan type, primary email address), as JSON. Read this to confirm which account the site is connected to before making changes. An empty object means no account is connected yet.', 'convertkit' );

}

/**
* Returns the resource content's MIME type.
*
* @since 3.5.0
*
* @return string
*/
public function get_mime_type() {

return 'application/json';

}

/**
* Executes the resource: return the cached account data as JSON.
*
* @since 3.5.0
*
* @param array $input Resource input (unused).
* @return string|WP_Error
*/
public function execute_callback( $input ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found

// Bail with an empty object if the account resource class isn't available.
if ( ! class_exists( 'ConvertKit_Resource_Account' ) ) {
return '{}';
}

$account = new ConvertKit_Resource_Account();
$data = $account->get();

// get() returns false when nothing is cached; normalise to an empty object.
if ( ! is_array( $data ) ) {
return '{}';
}

return (string) wp_json_encode( $data );

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Kit MCP Resource: Forms reference.
*
* @package ConvertKit
* @author ConvertKit
*/

/**
* A Markdown reference on how Kit Forms embed and display in WordPress
* (`kit://reference/forms`).
*
* @package ConvertKit
* @author ConvertKit
*/
class ConvertKit_MCP_Resource_Forms_Reference extends ConvertKit_MCP_Resource_Reference {

/**
* Returns the resource name.
*
* @since 3.5.0
*
* @return string
*/
public function get_name() {

return 'kit/reference-forms';

}

/**
* Returns the resource URI.
*
* @since 3.5.0
*
* @return string
*/
public function get_uri() {

return 'kit://reference/forms';

}

/**
* Returns the resource label.
*
* @since 3.5.0
*
* @return string
*/
public function get_label() {

return __( 'Kit Forms Reference', 'convertkit' );

}

/**
* Returns the resource description.
*
* @since 3.5.0
*
* @return string
*/
public function get_description() {

return __( 'How Kit Forms embed and display in WordPress: formats, where they appear, and how a default Form is overridden per post or category.', 'convertkit' );

}

/**
* Returns the Markdown content lines.
*
* @since 3.5.0
*
* @return array
*/
protected function get_content_lines() {

return array(
'# ' . __( 'Kit Forms in WordPress', 'convertkit' ),
'',
'## ' . __( 'Formats', 'convertkit' ),
'',
'- ' . __( '**Inline** forms render in the post content, where the Form is placed or auto-appended.', 'convertkit' ),
'- ' . __( '**Modal**, **slide in** and **sticky bar** forms are non-inline: Kit triggers them on the page, so their placement in content does not matter.', 'convertkit' ),
'',
__( 'The `kit://forms` resource and `kit/forms-list` tool return each Form\'s `format`, so you can tell inline from non-inline Forms.', 'convertkit' ),
'',
'## ' . __( 'How a Form is chosen for a post', 'convertkit' ),
'',
__( 'The Form shown on a given post is resolved in this order:', 'convertkit' ),
'',
'1. ' . __( 'The post\'s own Form setting (`kit/post-settings-update`), if set.', 'convertkit' ),
'2. ' . __( 'The Form set on one of the post\'s categories (`kit/category-settings-update`), if set.', 'convertkit' ),
'3. ' . __( 'The default Form for the post type, from General settings.', 'convertkit' ),
'',
__( 'A post can also be set to "None" to show no Form, overriding the defaults.', 'convertkit' ),
'',
'## ' . __( 'Placing a Form manually', 'convertkit' ),
'',
__( 'A specific Form can be inserted into content with the Kit Form block or the `[convertkit]` shortcode, rather than relying on the default. Use `kit/forms` to look up the Form ID first.', 'convertkit' ),
);

}

}
83 changes: 83 additions & 0 deletions includes/mcp/resources/class-convertkit-mcp-resource-forms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Kit MCP Resource: Forms.
*
* @package ConvertKit
* @author ConvertKit
*/

/**
* Exposes the Kit Forms on the connected account as an MCP Resource
* (`kit://forms`), mirroring the `kit/forms-list` tool.
*
* @package ConvertKit
* @author ConvertKit
*/
class ConvertKit_MCP_Resource_Forms extends ConvertKit_MCP_Resource_List {

/**
* Returns the resource name.
*
* @since 3.5.0
*
* @return string
*/
public function get_name() {

return 'kit/forms';

}

/**
* Returns the resource URI.
*
* @since 3.5.0
*
* @return string
*/
public function get_uri() {

return 'kit://forms';

}

/**
* Returns the resource label.
*
* @since 3.5.0
*
* @return string
*/
public function get_label() {

return __( 'Kit Forms', 'convertkit' );

}

/**
* Returns the resource description.
*
* @since 3.5.0
*
* @return string
*/
public function get_description() {

return __( 'The Kit Forms on the connected account, as JSON (id, name, format). Read this to map a Form name to its numeric ID before configuring form settings.', 'convertkit' );

}

/**
* Returns the backing ability class.
*
* @since 3.5.0
*
* @return string
*/
protected function get_ability_class() {

return 'ConvertKit_MCP_Ability_Resource_Forms';

}

}
Loading