Skip to content

Commit 10efbe6

Browse files
Merge pull request #34 from Automattic/bugfix/list_all_tools_endpoint
Bugfix/list all tools endpoint
2 parents a0843b7 + 9b4f0ec commit 10efbe6

File tree

6 files changed

+36
-24
lines changed

6 files changed

+36
-24
lines changed

includes/Admin/Settings.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function __construct() {
2929
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
3030
add_action( 'wp_ajax_wordpress_mcp_save_settings', array( $this, 'ajax_save_settings' ) );
3131
add_action( 'wp_ajax_wordpress_mcp_toggle_tool', array( $this, 'ajax_toggle_tool' ) );
32-
add_action( 'wp_ajax_all_mcp_tools', array( $this, 'ajax_all_mcp_tools' ) );
3332
add_filter( 'plugin_action_links_' . plugin_basename( WORDPRESS_MCP_PATH . 'wordpress-mcp.php' ), array( $this, 'plugin_action_links' ) );
3433
}
3534

@@ -282,16 +281,4 @@ public function toggle_tool( string $tool_name, bool $enabled ): bool {
282281
}
283282
return true;
284283
}
285-
286-
/**
287-
* AJAX handler for getting all MCP tools.
288-
*/
289-
public function ajax_all_mcp_tools(): void {
290-
if ( ! current_user_can( 'manage_options' ) ) {
291-
wp_send_json_error( array( 'message' => __( 'You do not have permission to perform this action.', 'wordpress-mcp' ) ) );
292-
}
293-
294-
$tools = WpMcp::instance()->get_all_tools();
295-
wp_send_json_success( $tools );
296-
}
297284
}

includes/Core/McpProxyRoutes.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ public function handle_request( WP_REST_Request $request ): WP_Error|WP_REST_Res
106106
return match ( $method ) {
107107
'init' => $this->init( $params ),
108108
'tools/list' => $this->list_tools( $params ),
109+
'tools/list/all' => $this->list_all_tools( $params ),
109110
'tools/call' => $this->call_tool( $params ),
110111
'resources/list' => $this->list_resources( $params ),
111112
'resources/templates/list' => $this->list_resource_templates( $params ),
@@ -190,6 +191,21 @@ public function list_tools( array $params ): WP_Error|WP_REST_Response {
190191
);
191192
}
192193

194+
/**
195+
* List all tools
196+
*
197+
* @param array $params Request parameters.
198+
*
199+
* @return WP_REST_Response|WP_Error
200+
*/
201+
public function list_all_tools( array $params ): WP_Error|WP_REST_Response {
202+
$tools = $this->mcp->get_all_tools();
203+
204+
return rest_ensure_response(
205+
array( 'tools' => $tools )
206+
);
207+
}
208+
193209
/**
194210
* Call a tool
195211
*

includes/Core/WpMcp.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,16 @@ public function get_tools(): array {
348348
return $this->tools;
349349
}
350350

351+
/**
352+
* Get all tools with enabled state.
353+
*
354+
* @return array
355+
*/
351356
public function get_all_tools(): array {
352357
$tool_states = get_option( self::TOOL_STATES_OPTION, array() );
353358
$tools = $this->all_tools;
354359

355-
// Add enabled state to each tool
360+
// Add enabled state to each tool.
356361
foreach ( $tools as &$tool ) {
357362
$tool['enabled'] = ! isset( $tool_states[ $tool['name'] ] ) || $tool_states[ $tool['name'] ];
358363
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wordpress-mcp",
3-
"version": "0.1.16",
3+
"version": "0.1.17",
44
"description": "Wordpress MCP Settings",
55
"main": "src/index.js",
66
"private": true,
@@ -39,4 +39,4 @@
3939
"eslint-plugin-eslint-comments": "3.2.0",
4040
"prettier": "npm:wp-prettier@3.0.3"
4141
}
42-
}
42+
}

src/settings/ToolsTab.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ const ToolsTab = () => {
2525
const fetchTools = async () => {
2626
try {
2727
setLoading( true );
28-
const response = await fetch(
29-
ajaxurl + '?action=all_mcp_tools'
30-
).then( ( res ) => res.json() );
28+
const response = await apiFetch( {
29+
path: '/wp/v2/wpmcp',
30+
method: 'POST',
31+
data: {
32+
jsonrpc: '2.0',
33+
method: 'tools/list/all',
34+
params: {},
35+
},
36+
} );
3137

32-
console.log( 'response', response );
33-
34-
if ( response && response.data ) {
35-
setTools( response.data );
38+
if ( response && response.tools ) {
39+
setTools( response.tools );
3640
} else {
3741
setError(
3842
__( 'Failed to load tools data', 'wordpress-mcp' )

wordpress-mcp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Plugin name: WordPress MCP
44
* Description: A plugin to integrate WordPress with Model Context Protocol (MCP), providing AI-accessible interfaces to WordPress data and functionality through standardized tools, resources, and prompts. Enables AI assistants to interact with posts, users, site settings, and WooCommerce data.
5-
* Version: 0.1.16
5+
* Version: 0.1.17
66
* Author: Automattic AI, Ovidiu Galatan <ovidiu.galatan@a8c.com>
77
* Author URI: https://automattic.ai
88
* Text Domain: wordpress-mcp

0 commit comments

Comments
 (0)