Skip to content

Conversation

dkotter
Copy link
Collaborator

@dkotter dkotter commented Sep 15, 2025

Description of the Change

Note

This is branched from #1003 as the WordPress MCP Adapter requires the Abilities API. And similar to that PR, this is an early test of adding MCP support to ClassifAI; opening this PR both for discussion and as an example of how we may want to implement this.

This PR brings in the WordPress MCP Adapter as a new composer dependency and creates a new MCP server with the Title Generation Feature as it's only tool for now. With this code in place, a new REST endpoint is registered (local.test/wp-json/classifai/mcp), that allows you to see all available tools and run individual tools.

Worth noting by default, the MCP server requires you to be logged in (this can be overridden but I've left that for now). And the Generate Titles Feature requires you to be logged in and have access, so there are two separate permission checks that you must pass here.

How to test the Change

  1. Ensure the Title Generation Feature is on and configured properly.
  2. Make a curl request to the MCP endpoint to list out tools, passing in proper credentials:
curl -X POST "https://local.test/wp-json/classifai/mcp/" \
--user "admin:password" \
-H "Content-Type: application/json" \
-d '{"method": "tools/list"}'
  1. Make a curl request to the MCP endpoint to run the generate titles tool, passing in proper credentials:
curl -X POST "https://local.test/wp-json/classifai/mcp/" \
--user "admin:password" \
-H "Content-Type: application/json" \
-d '{
    "method": "tools/call",
    "params": {
        "name": "classifai-generate-title",
        "arguments": {
            "id": 1
        }
    }
}'

Changelog Entry

Added - New feature
Changed - Existing functionality
Deprecated - Soon-to-be removed feature
Removed - Feature
Fixed - Bug fix
Security - Vulnerability
Developer - Non-functional update

Credits

Props @dkotter

Checklist:

@dkotter dkotter added this to the Future Release milestone Sep 15, 2025
@dkotter dkotter self-assigned this Sep 15, 2025
@dkotter dkotter requested review from jeffpaul and a team as code owners September 15, 2025 21:50
add_action( 'after_classifai_init', [ $this, 'load_action_scheduler' ] );

// Initialize the MCP adapter so the hooks are loaded.
$this->mcp_adapter = McpAdapter::instance();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing, this was needed to ensure the MCP code was loaded. Not ideal but I'm assuming this will get better as this package matures

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So looked at this a bit closer and the issue here is when loading the plugin via composer, composer will add the autoloaded files from the plugin to our autoloader but that doesn't include the main plugin file (as WordPress takes care of loading that). In our case, we aren't loading this as a normal plugin and so that main file never loads, which is what initializes everything.

If you look at that file, it does this:

// Load the plugin.
if ( class_exists( WP\MCP\Plugin::class ) ) {
	WP\MCP\Plugin::instance();
}

That ends up calling McpAdapter::instance(); which is what we are doing here. So we can either leave this as-is or we can swap this out for the above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant