Skip to content

Commit ca652fc

Browse files
Copilotswissspidy
andcommitted
Remove AI Services backward compatibility, use only WP AI Client
Co-authored-by: swissspidy <[email protected]>
1 parent f807a05 commit ca652fc

File tree

4 files changed

+19
-83
lines changed

4 files changed

+19
-83
lines changed

README.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,11 @@ To install the latest development version of this package, use the following com
2121
wp package install mcp-wp/ai-command:dev-main
2222
```
2323

24-
This package supports two AI backends:
25-
26-
1. **WP AI Client** (recommended, available in WordPress 7.0+): The official WordPress AI client library, bundled with the AI plugin.
27-
2. **AI Services plugin** (fallback): A third-party plugin available from the WordPress plugin directory.
28-
29-
The command will automatically use WP AI Client if available, falling back to AI Services if not.
24+
This package uses the **WP AI Client** (available in WordPress 7.0+ or via the AI plugin) for AI functionality.
3025

3126
### Configuration
3227

33-
#### Using WP AI Client
34-
35-
If you're using WordPress 7.0+ or have the AI plugin installed:
28+
Configure credentials for AI providers:
3629

3730
```bash
3831
# Configure credentials for AI providers
@@ -44,15 +37,7 @@ wp ai credentials set google YOUR-GOOGLE-API-KEY
4437
wp ai credentials list
4538
```
4639

47-
#### Using AI Services Plugin
48-
49-
If WP AI Client is not available, install the [AI Services plugin](https://wordpress.org/plugins/ai-services):
50-
51-
```bash
52-
wp plugin install ai-services --activate
53-
```
54-
55-
Then configure your API keys through the WordPress admin or using environment variables.
40+
Credentials are stored in the WordPress database and can also be managed through the WordPress admin settings screen.
5641

5742
### Reporting a bug
5843

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"roave/security-advisories": "dev-latest",
2020
"wp-cli/extension-command": "^2.1",
2121
"wp-cli/wp-cli-tests": "^v4.3.9",
22-
"wpackagist-plugin/ai-services": "^0.6.0",
2322
"wordpress/wp-ai-client": "^0.2.1"
2423
},
2524
"repositories":[

features/ai.feature

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Feature: AI command
2-
Scenario: Missing AI Services plugin
2+
Scenario: Missing WP AI Client
33
When I try `wp ai "Hello World"`
44
Then STDERR should contain:
55
"""
@@ -16,12 +16,5 @@ Feature: AI command
1616
When I try `wp ai "Hello World"`
1717
Then STDERR should contain:
1818
"""
19-
This command requires the AI Services plugin for MCP tool integration.
20-
"""
21-
22-
When I run `wp plugin install ai-services --activate`
23-
When I try `wp ai "Hello World"`
24-
Then STDERR should contain:
25-
"""
26-
No service satisfying the given arguments is registered and available.
19+
This command requires the WP AI Client.
2720
"""

src/AiCommand.php

Lines changed: 14 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22

33
namespace McpWp\AiCommand;
44

5-
use Mcp\Client\ClientSession;
6-
use McpWp\AiCommand\AI\AiClient;
75
use McpWp\AiCommand\AI\WpAiClient;
8-
use McpWp\AiCommand\MCP\Client;
9-
use McpWp\AiCommand\Utils\CliLogger;
10-
use McpWp\AiCommand\Utils\McpConfig;
11-
use McpWp\MCP\Servers\WordPress\WordPress;
126
use WP_CLI;
137
use WP_CLI\Utils;
148
use WP_CLI_Command;
159

1610
/**
1711
* AI command class.
1812
*
19-
* Allows interacting with an LLM using MCP.
20-
*
21-
* @phpstan-import-type ToolDefinition from AiClient
13+
* Allows interacting with an LLM using the WP AI Client.
2214
*/
2315
class AiCommand extends WP_CLI_Command {
2416

@@ -30,38 +22,26 @@ class AiCommand extends WP_CLI_Command {
3022
* <prompt>
3123
* : AI prompt.
3224
*
33-
* [--skip-builtin-servers[=<server>]]
34-
* : Skip loading the built-in servers for WP-CLI and the current WordPress site.
35-
* Can be set to 'all' (skip both), 'cli' (skip the WP-CLI server),
36-
* or 'wp' (skip the WordPress server).
37-
*
3825
* [--skip-wordpress]
3926
* : Run command without loading WordPress. (Not implemented yet)
4027
*
41-
* [--approval-mode]
42-
* : Approve tool usage before running.
43-
*
4428
* [--service=<service>]
4529
* : Manually specify the AI service to use.
46-
* Depends on the available AI services.
4730
* Examples: 'google', 'anthropic', 'openai'.
4831
*
4932
* [--model=<model>]
5033
* : Manually specify the LLM model that should be used.
51-
* Depends on the available AI services.
52-
* Examples: 'gemini-2.0-flash', 'gpt-4o'.
34+
* Examples: 'gemini-2.0-flash', 'gpt-4o', 'claude-sonnet-4-5'.
5335
*
5436
* ## EXAMPLES
5537
*
56-
* # Get data from WordPress
57-
* $ wp ai "What are the titles of my last three posts?"
58-
* - Hello world
59-
* - My awesome post
60-
* - Another post
38+
* # Ask a simple question
39+
* $ wp ai "Explain WordPress in one sentence"
40+
* WordPress is a free and open-source content management system...
6141
*
62-
* # Interact with multiple MCP servers.
63-
* $ wp ai "Take file foo.txt and create a new blog post from it"
64-
* Success: Blog post created.
42+
* # Use a specific model
43+
* $ wp ai "Summarize the history of WordPress" --model=gpt-4o
44+
* WordPress was created in 2003...
6545
*
6646
* @when before_wp_load
6747
*
@@ -76,36 +56,15 @@ public function __invoke( array $args, array $assoc_args ): void {
7656
WP_CLI::error( 'Not implemented yet.' );
7757
}
7858

79-
$approval_mode = (bool) Utils\get_flag_value( $assoc_args, 'approval-mode', false );
80-
$service = Utils\get_flag_value( $assoc_args, 'service' );
81-
$model = Utils\get_flag_value( $assoc_args, 'model' );
82-
83-
// Check if WP AI Client is available (preferred for simple prompts).
84-
$use_wp_ai_client = class_exists( '\WordPress\AI_Client\AI_Client' );
85-
86-
// If using WP AI Client and no MCP tools/approval is needed, use simplified path.
87-
if ( $use_wp_ai_client && ! $approval_mode ) {
88-
$skip_builtin_servers = Utils\get_flag_value( $assoc_args, 'skip-builtin-servers' );
89-
// Only use WP AI Client if MCP servers are skipped.
90-
if ( $skip_builtin_servers ) {
91-
$ai_client = new WpAiClient( [], $approval_mode, $service, $model );
92-
$ai_client->call_ai_service_with_prompt( $args[0] );
93-
return;
94-
}
95-
}
96-
97-
// Otherwise, use the full MCP integration with AI Services (required for tools).
98-
if ( ! function_exists( '\ai_services' ) ) {
99-
WP_CLI::error( 'This command requires the AI Services plugin for MCP tool integration. You can install it with `wp plugin install ai-services --activate`. Alternatively, use `--skip-builtin-servers=all` to use WP AI Client without MCP tools.' );
59+
// Ensure WP AI Client is available.
60+
if ( ! class_exists( '\WordPress\AI_Client\AI_Client' ) ) {
61+
WP_CLI::error( 'This command requires the WP AI Client. Please ensure WordPress 7.0+ or the AI plugin is installed and activated.' );
10062
}
10163

102-
$skip_builtin_servers = Utils\get_flag_value( $assoc_args, 'skip-builtin-servers', 'all' );
103-
104-
$sessions = $this->get_sessions( $with_wordpress && 'cli' === $skip_builtin_servers, 'wp' === $skip_builtin_servers );
105-
$tools = $this->get_tools( $sessions );
106-
107-
$ai_client = new AiClient( $tools, $approval_mode, $service, $model );
64+
$service = Utils\get_flag_value( $assoc_args, 'service' );
65+
$model = Utils\get_flag_value( $assoc_args, 'model' );
10866

67+
$ai_client = new WpAiClient( [], false, $service, $model );
10968
$ai_client->call_ai_service_with_prompt( $args[0] );
11069
}
11170

0 commit comments

Comments
 (0)