diff --git a/composer.json b/composer.json index 21b8a86..7a66c00 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "authors": [], "require": { "php": "^8.2", - "logiscape/mcp-sdk-php": "^1.0", + "logiscape/mcp-sdk-php": "dev-main", "mcaskill/composer-exclude-files": "^4.0", "mcp-wp/mcp-server": "dev-main", "wp-cli/wp-cli": "^2.11" diff --git a/features/load-wp-cli.feature b/features/load-wp-cli.feature deleted file mode 100644 index 035b867..0000000 --- a/features/load-wp-cli.feature +++ /dev/null @@ -1,10 +0,0 @@ -Feature: Test that WP-CLI loads. - - Scenario: WP-CLI loads for your tests - Given a WP install - - When I run `wp eval 'echo "Hello world.";'` - Then STDOUT should contain: - """ - Hello world. - """ diff --git a/features/mcp-server.feature b/features/mcp-server.feature new file mode 100644 index 0000000..43676c1 --- /dev/null +++ b/features/mcp-server.feature @@ -0,0 +1,80 @@ +Feature: MCP server command + + Background: + Given an empty directory + And an empty {HOME} directory + + Scenario: CRUD + When I run `wp mcp server add foo "https://foo.example.com/mcp"` + Then STDOUT should contain: + """ + Server added. + """ + + When I run `wp mcp server add bar "https://bar.example.com/mcp"` + And I run `wp mcp server add baz "https://baz.example.com/mcp"` + And I run `wp mcp server list` + Then STDOUT should be a table containing rows: + | name | server | status | + | foo | https://foo.example.com/mcp | active | + | bar | https://bar.example.com/mcp | active | + | baz | https://baz.example.com/mcp | active | + + When I run `wp mcp server remove bar baz` + Then STDOUT should contain: + """ + Success: Removed 2 of 2 servers. + """ + + When I run `wp mcp server list` + Then STDOUT should contain: + """ + foo.example.com + """ + And STDOUT should not contain: + """ + bar.example.com + """ + And STDOUT should not contain: + """ + baz.example.com + """ + + When I try `wp mcp server add foo "https://foo.example.com/mcp"` + Then STDERR should contain: + """ + Server already exists. + """ + + When I run `wp mcp server add bar "https://bar.example.com/mcp"` + And I run `wp mcp server add baz "https://baz.example.com/mcp"` + And I run `wp mcp server update bar --status=inactive` + Then STDOUT should contain: + """ + Server updated. + """ + + When I run `wp mcp server list --status=inactive` + Then STDOUT should be a table containing rows: + | name | server | status | + | bar | https://bar.example.com/mcp | inactive | + + And STDOUT should not contain: + """ + foo.example.com + """ + And STDOUT should not contain: + """ + baz.example.com + """ + + When I run `wp mcp server update foo --name=fabulous` + Then STDOUT should contain: + """ + Server updated. + """ + + When I run `wp mcp server list` + Then STDOUT should be a table containing rows: + | name | server | status | + | fabulous | https://foo.example.com/mcp | active | diff --git a/src/McpServerCommand.php b/src/McpServerCommand.php index 59114ea..bd24181 100644 --- a/src/McpServerCommand.php +++ b/src/McpServerCommand.php @@ -19,6 +19,9 @@ class McpServerCommand extends WP_CLI_Command { * * ## OPTIONS * + * [--=] + * : Filter results by key=value pairs. + * * [--format=] * : Render output in a particular format. * --- @@ -42,6 +45,8 @@ class McpServerCommand extends WP_CLI_Command { * * @subcommand list * + * @when before_wp_load + * * @param array $args Indexed array of positional arguments. * @param array $assoc_args Associative array of associative arguments. */ @@ -51,6 +56,13 @@ public function list_( $args, $assoc_args ): void { $servers = []; foreach ( $config as $name => $server ) { + // Support features like --status=active. + foreach ( array_keys( $server ) as $field ) { + if ( isset( $assoc_args[ $field ] ) && ! in_array( $server[ $field ], array_map( 'trim', explode( ',', $assoc_args[ $field ] ) ), true ) ) { + continue 2; + } + } + $servers[] = [ 'name' => $name, 'server' => $server['server'], @@ -83,6 +95,8 @@ public function list_( $args, $assoc_args ): void { * $ wp mcp server add "server-filesystem" "npx -y @modelcontextprotocol/server-filesystem /my/allowed/folder/" * Success: Server added. * + * @when before_wp_load + * * @param array $args Indexed array of positional arguments. */ public function add( $args ): void { @@ -93,7 +107,7 @@ public function add( $args ): void { } else { $config[ $args[0] ] = [ 'server' => $args[1], - 'status' => 'enabled', + 'status' => 'active', ]; $result = $this->get_config()->update_config( $config ); @@ -123,6 +137,8 @@ public function add( $args ): void { * $ wp mcp server remove "server-filesystem" * Success: Server removed. * + * @when before_wp_load + * * @param array $args Indexed array of positional arguments. */ public function remove( $args, $assoc_args ): void { @@ -143,7 +159,7 @@ public function remove( $args, $assoc_args ): void { WP_CLI::warning( "Server '$server' not found." ); ++$errors; } else { - unset( $config[ $args[0] ] ); + unset( $config[ $server ] ); ++$successes; } } @@ -172,9 +188,11 @@ public function remove( $args, $assoc_args ): void { * ## EXAMPLES * * # Remove server. - * $ wp mcp server update "server-filesystem" --status=disabled + * $ wp mcp server update "server-filesystem" --status=inactive * Success: Server updated. * + * @when before_wp_load + * * @param array $args Indexed array of positional arguments. */ public function update( $args, $assoc_args ): void { @@ -187,12 +205,18 @@ public function update( $args, $assoc_args ): void { foreach ( $config[ $args[0] ] as $key => $value ) { if ( isset( $assoc_args[ $key ] ) ) { if ( 'status' === $key ) { - $value = 'disabled' === $value ? 'enabled' : 'disabled'; + $value = 'inactive' === $value ? 'active' : 'inactive'; } $config[ $args[0] ][ $key ] = $value; } } + // Special case for renaming an entry. + if ( isset( $assoc_args['name'] ) ) { + $config[ $assoc_args['name'] ] = $config[ $args[0] ]; + unset( $config[ $args[0] ] ); + } + $result = $this->get_config()->update_config( $config ); if ( ! $result ) {