Skip to content

Commit 4cd2bfe

Browse files
committed
cleanup
1 parent a3b2338 commit 4cd2bfe

File tree

5 files changed

+8
-267
lines changed

5 files changed

+8
-267
lines changed

settings/rest-routes.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/AiCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ private function register_tools($server, $client) {
8787
]
8888
);
8989

90-
$map_rest_to_mcp = new MapRESTtoMCP(
91-
require __DIR__ . '/../settings/rest-routes.php'
92-
);
93-
90+
$map_rest_to_mcp = new MapRESTtoMCP();
9491
$map_rest_to_mcp->map_rest_to_mcp( $server );
9592

9693
$server->register_tool(

src/MapRESTtoMCP.php

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22

33
namespace WP_CLI\AiCommand;
44

5-
use WP_CLI\AiCommand\RouteInformation;
65
use WP_CLI;
76
use WP_CLI\AiCommand\MCP\Server;
87
use WP_REST_Request;
98

109

1110
class MapRESTtoMCP {
1211

13-
public function __construct(
14-
private array $rest_routes
15-
) {}
16-
1712
public function args_to_schema( $args = [] ) {
1813
$schema = [];
1914
$required = [];
@@ -80,27 +75,12 @@ protected function sanitize_type( $type) {
8075

8176
}
8277

83-
protected function is_route_allowed( $route ) {
84-
if(! \str_starts_with($route, '/wp/v2')) {
85-
return false; // Block all non wp/v2 routes for now.
86-
}
87-
88-
return ! in_array( $route, $this->rest_routes, true );
89-
}
90-
9178
public function map_rest_to_mcp( Server $mcp_server ) {
92-
/**
93-
* @var \WP_REST_Server $server
94-
*/
9579
$server = rest_get_server();
9680
$routes = $server->get_routes();
9781

9882
foreach ( $routes as $route => $endpoints ) {
9983
foreach ( $endpoints as $endpoint ) {
100-
if ( ! $this->is_route_allowed($route) ) {
101-
continue; // This route is the block list.
102-
}
103-
10484
foreach( $endpoint['methods'] as $method_name => $enabled ) {
10585
$information = new RouteInformation(
10686
$route,
@@ -123,22 +103,12 @@ public function map_rest_to_mcp( Server $mcp_server ) {
123103

124104
$mcp_server->register_tool($tool);
125105
}
126-
127106
}
128107
}
129-
130-
}
131-
132-
protected function generate_tool_name($route, $method_name) {
133-
$singular = '';
134-
if ( \str_contains( $route, '(?P<' ) ) {
135-
$singular = 'singular_';
136-
}
137-
return sanitize_title($route) . '_' . $singular . strtolower( $method_name );
138108
}
139109

140110
/**
141-
* Create desciptrion based on route and method.
111+
* Create description based on route and method.
142112
*
143113
*
144114
* Get a list of posts GET /wp/v2/posts

src/RESTControllerList.php

Lines changed: 0 additions & 225 deletions
This file was deleted.

src/RouteInformation.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function get_sanitized_route_name(): string
3030
$route = preg_replace('/(\(\?P<' . $match . '>.*\))/', 'p_' . $match, $route, 1);
3131
}
3232

33-
return $this->method . '_' . sanitize_title( $route );
33+
return $this->method . '_' . sanitize_title($route);
3434
}
3535

3636
public function get_method(): string
@@ -80,6 +80,11 @@ public function is_list(): bool
8080

8181
public function is_wp_rest_controller(): bool
8282
{
83+
// The callback form for a WP_REST_Controller is [ WP_REST_Controller, method ]
84+
if ( ! is_array( $this->callback ) ) {
85+
return false;
86+
}
87+
8388
$allowed = [
8489
WP_REST_Posts_Controller::class,
8590
WP_REST_Users_Controller::class,

0 commit comments

Comments
 (0)