Skip to content

Commit 8d77999

Browse files
committed
Add skip-built-in-servers flag for testing
1 parent 7d88ea6 commit 8d77999

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/AiCommand.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class AiCommand extends WP_CLI_Command {
2626
* <prompt>
2727
* : AI prompt.
2828
*
29+
* [--skip-built-in-servers]
30+
* : Skip loading the built-in servers.
31+
*
2932
* [--skip-wordpress]
3033
* : Run command without loading WordPress. (Not implemented yet)
3134
*
@@ -52,7 +55,9 @@ public function __invoke( $args, $assoc_args ) {
5255
\WP_CLI::get_runner()->load_wordpress();
5356
}
5457

55-
$sessions = $this->get_sessions( $with_wordpress );
58+
$with_builtin_servers = null === Utils\get_flag_value( $assoc_args, 'skip-built-in-servers' );
59+
60+
$sessions = $this->get_sessions( $with_wordpress && $with_builtin_servers, $with_builtin_servers );
5661
$tools = $this->get_tools( $sessions );
5762

5863
$ai_client = new AiClient(
@@ -121,21 +126,23 @@ protected function get_tools( array $sessions ): array {
121126
/**
122127
* Returns a list of MCP client sessions for each MCP server that is configured.
123128
*
124-
* @param bool $with_wordpress Whether a session for the built-in WordPress MCP server should be created.
129+
* @param bool $with_wp_server Whether a session for the built-in WordPress MCP server should be created.
130+
* @param bool $with_cli_server Whether a session for the built-in WP-CLI MCP server should be created.
125131
* @return ClientSession[]
126132
*/
127-
public function get_sessions( bool $with_wordpress ): array {
133+
public function get_sessions( bool $with_wp_server, bool $with_cli_server ): array {
128134
$sessions = [];
129135

130-
// The WP-CLI MCP server is always available.
131-
$sessions[] = ( new Client( new CliLogger() ) )->connect(
132-
MCP\Servers\WP_CLI\WP_CLI::class
133-
);
136+
if ( $with_cli_server ) {
137+
$sessions[] = ( new Client( new CliLogger() ) )->connect(
138+
MCP\Servers\WP_CLI\WP_CLI::class
139+
);
140+
}
134141

135-
if ( $with_wordpress ) {
136-
$sessions[] = ( new Client( new CliLogger() ) )->connect(
137-
WordPress::class
138-
);
142+
if ( $with_wp_server ) {
143+
$sessions[] = ( new Client( new CliLogger() ) )->connect(
144+
WordPress::class
145+
);
139146
}
140147

141148
$servers = array_values( ( new McpConfig() )->get_config() );

0 commit comments

Comments
 (0)