Skip to content

Commit 89bb2ac

Browse files
Merge pull request #17 from Automattic/extra-tools
Extra MCP tools and improved HandleToolsCall
2 parents b8f0eb8 + b401985 commit 89bb2ac

File tree

9 files changed

+1076
-56
lines changed

9 files changed

+1076
-56
lines changed

includes/Core/McpProxyRoutes.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,15 +210,27 @@ public function call_tool( array $params ): WP_Error|WP_REST_Response {
210210
// Implement a tool calling logic here.
211211
$result = HandleToolsCall::run( $params );
212212

213-
return rest_ensure_response(
214-
array(
215-
'content' => array(
216-
array(
217-
'type' => 'text',
218-
'text' => wp_json_encode( $result ),
219-
),
213+
$response = array(
214+
'content' => array(
215+
array(
216+
'type' => 'text',
220217
),
221-
)
218+
),
219+
);
220+
221+
// @todo: add support for EmbeddedResource schema.ts:619.
222+
if ( isset( $result['type'] ) && 'image' === $result['type'] ) {
223+
$response['content'][0]['type'] = 'image';
224+
$response['content'][0]['data'] = base64_encode( $result['results'] ); //phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
225+
226+
// @todo: improve this ?!.
227+
$response['content'][0]['mimeType'] = $result['mimeType'] ?? 'image/png';
228+
} else {
229+
$response['content'][0]['text'] = wp_json_encode( $result );
230+
}
231+
232+
return rest_ensure_response(
233+
$response
222234
);
223235
}
224236

includes/Core/RegisterMcpTool.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ private function get_args_from_rest_api(): void {
5353

5454
// get a list of all registered rest routes.
5555
$routes = rest_get_server()->get_routes();
56-
// maybe use: rest_get_server()->get_route_options( $route ) );
56+
// maybe use: rest_get_server()->get_route_options( $route ) );.
5757
$rest_route = $routes[ $route ] ?? null;
5858
if ( ! $rest_route ) {
5959
// translators: %s: Route.
60-
throw new InvalidArgumentException( sprintf( esc_html__( 'The route %s does not exist.', 'wordpress-mcp' ), esc_html( $route ) ) );
60+
throw new InvalidArgumentException( sprintf( esc_html__( 'The route %1$s with method %2$s does not exist.', 'wordpress-mcp' ), $route, $method ) ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
6161
}
6262

6363
$rest_api = null;
@@ -124,6 +124,10 @@ private function get_args_from_rest_api(): void {
124124
}
125125
}
126126

127+
// Convert required array to object.
128+
$input_schema['properties'] = (object) $input_schema['properties'];
129+
$input_schema['required'] = (object) $input_schema['required'];
130+
127131
// Apply modifications if provided in rest_alias['modifications'] .
128132
if ( isset( $this->args['rest_alias']['inputSchemaReplacements'] ) ) {
129133
$modifications = $this->args['rest_alias']['inputSchemaReplacements'];

includes/Core/WpMcp.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33

44
namespace Automattic\WordpressMcp\Core;
55

6+
use Automattic\WordpressMcp\Tools\McpCustomPostTypesTools;
67
use Automattic\WordpressMcp\Tools\McpPostsTools;
78
use Automattic\WordpressMcp\Resources\McpGeneralSiteInfo;
89
use Automattic\WordpressMcp\Tools\McpSiteInfo;
910
use Automattic\WordpressMcp\Tools\McpUsersTools;
1011
use Automattic\WordpressMcp\Tools\McpWooOrders;
1112
use Automattic\WordpressMcp\Tools\McpWooProducts;
13+
use Automattic\WordpressMcp\Tools\McpPagesTools;
14+
use Automattic\WordpressMcp\Tools\McpSettingsTools;
15+
use Automattic\WordpressMcp\Tools\McpMediaTools;
1216
use Automattic\WordpressMcp\Prompts\McpGetSiteInfo as McpGetSiteInfoPrompt;
1317
use Automattic\WordpressMcp\Prompts\McpAnalyzeSales;
1418
use Automattic\WordpressMcp\Resources\McpPluginInfoResource;
@@ -136,6 +140,10 @@ private function init_default_tools(): void {
136140
new McpUsersTools();
137141
new McpWooProducts();
138142
new McpWooOrders();
143+
new McpPagesTools();
144+
new McpSettingsTools();
145+
new McpMediaTools();
146+
new McpCustomPostTypesTools();
139147
}
140148

141149
/**

0 commit comments

Comments
 (0)