@@ -19,6 +19,9 @@ class McpServerCommand extends WP_CLI_Command {
19
19
*
20
20
* ## OPTIONS
21
21
*
22
+ * [--<field>=<value>]
23
+ * : Filter results by key=value pairs.
24
+ *
22
25
* [--format=<format>]
23
26
* : Render output in a particular format.
24
27
* ---
@@ -42,6 +45,8 @@ class McpServerCommand extends WP_CLI_Command {
42
45
*
43
46
* @subcommand list
44
47
*
48
+ * @when before_wp_load
49
+ *
45
50
* @param array $args Indexed array of positional arguments.
46
51
* @param array $assoc_args Associative array of associative arguments.
47
52
*/
@@ -51,6 +56,13 @@ public function list_( $args, $assoc_args ): void {
51
56
$ servers = [];
52
57
53
58
foreach ( $ config as $ name => $ server ) {
59
+ // Support features like --status=active.
60
+ foreach ( array_keys ( $ server ) as $ field ) {
61
+ if ( isset ( $ assoc_args [ $ field ] ) && ! in_array ( $ server [ $ field ], array_map ( 'trim ' , explode ( ', ' , $ assoc_args [ $ field ] ) ), true ) ) {
62
+ continue 2 ;
63
+ }
64
+ }
65
+
54
66
$ servers [] = [
55
67
'name ' => $ name ,
56
68
'server ' => $ server ['server ' ],
@@ -83,6 +95,8 @@ public function list_( $args, $assoc_args ): void {
83
95
* $ wp mcp server add "server-filesystem" "npx -y @modelcontextprotocol/server-filesystem /my/allowed/folder/"
84
96
* Success: Server added.
85
97
*
98
+ * @when before_wp_load
99
+ *
86
100
* @param array $args Indexed array of positional arguments.
87
101
*/
88
102
public function add ( $ args ): void {
@@ -93,7 +107,7 @@ public function add( $args ): void {
93
107
} else {
94
108
$ config [ $ args [0 ] ] = [
95
109
'server ' => $ args [1 ],
96
- 'status ' => 'enabled ' ,
110
+ 'status ' => 'active ' ,
97
111
];
98
112
99
113
$ result = $ this ->get_config ()->update_config ( $ config );
@@ -123,6 +137,8 @@ public function add( $args ): void {
123
137
* $ wp mcp server remove "server-filesystem"
124
138
* Success: Server removed.
125
139
*
140
+ * @when before_wp_load
141
+ *
126
142
* @param array $args Indexed array of positional arguments.
127
143
*/
128
144
public function remove ( $ args , $ assoc_args ): void {
@@ -143,7 +159,7 @@ public function remove( $args, $assoc_args ): void {
143
159
WP_CLI ::warning ( "Server ' $ server' not found. " );
144
160
++$ errors ;
145
161
} else {
146
- unset( $ config [ $ args [ 0 ] ] );
162
+ unset( $ config [ $ server ] );
147
163
++$ successes ;
148
164
}
149
165
}
@@ -172,9 +188,11 @@ public function remove( $args, $assoc_args ): void {
172
188
* ## EXAMPLES
173
189
*
174
190
* # Remove server.
175
- * $ wp mcp server update "server-filesystem" --status=disabled
191
+ * $ wp mcp server update "server-filesystem" --status=inactive
176
192
* Success: Server updated.
177
193
*
194
+ * @when before_wp_load
195
+ *
178
196
* @param array $args Indexed array of positional arguments.
179
197
*/
180
198
public function update ( $ args , $ assoc_args ): void {
@@ -187,12 +205,18 @@ public function update( $args, $assoc_args ): void {
187
205
foreach ( $ config [ $ args [0 ] ] as $ key => $ value ) {
188
206
if ( isset ( $ assoc_args [ $ key ] ) ) {
189
207
if ( 'status ' === $ key ) {
190
- $ value = 'disabled ' === $ value ? 'enabled ' : 'disabled ' ;
208
+ $ value = 'inactive ' === $ value ? 'active ' : 'inactive ' ;
191
209
}
192
210
$ config [ $ args [0 ] ][ $ key ] = $ value ;
193
211
}
194
212
}
195
213
214
+ // Special case for renaming an entry.
215
+ if ( isset ( $ assoc_args ['name ' ] ) ) {
216
+ $ config [ $ assoc_args ['name ' ] ] = $ config [ $ args [0 ] ];
217
+ unset( $ config [ $ args [0 ] ] );
218
+ }
219
+
196
220
$ result = $ this ->get_config ()->update_config ( $ config );
197
221
198
222
if ( ! $ result ) {
0 commit comments