feat: Add tool for updating single and multiple WordPress plugins #74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This Pull Request introduces a new tool,
update_plugins, to the WordPress MCP framework. This tool enables AI assistants to programmatically initiate updates for one or more specified WordPress plugins. It aims to enhance the MCP's capabilities by providing a robust and controlled mechanism for plugin management, directly leveraging WordPress core update functionalities.Motivation
Currently, the WordPress MCP provides resources to retrieve plugin information but lacks a direct mechanism for AI assistants to trigger plugin updates. This new tool addresses that gap, allowing for more comprehensive and automated management of WordPress installations through AI-driven interfaces. This feature is crucial for maintaining site security and performance by ensuring plugins are kept up-to-date.
Technical Implementation Details
New File
includes/Tools/McpPluginUpdateTools.php: This file contains theMcpPluginUpdateToolsclass, which implements the core logic for theupdate_pluginstool.Modifications
includes/Core/WpMcp.php: This file was modified to:McpPluginUpdateToolsclass via ausestatement.McpPluginUpdateToolswithin theinit_default_tools()method, ensuring the tool is registered with the MCP framework upon initialization.Tool Details
update_pluginsplugin_slugs(array|string, required): A single plugin slug (e.g.,'akismet') or an array of plugin slugs (e.g.,['akismet', 'woocommerce']) to be updated. Plugin slugs can be obtained from theplugin-inforesource.The tool returns a JSON array of objects, where each object contains the status of an update attempt for a specific plugin. For each plugin, the output includes:
plugin_slug(string): The slug of the plugin that was targeted for update.status(string): The result of the update operation. Possible values includesuccess,failed,not_found, orno_update_available.message(string): A human-readable message providing more details about the update status, including any error messages if the update failed.Error Handling
The tool handles the following error conditions:
plugin_slugsparameter is empty or not provided, the tool returns afailedstatus with an appropriate message.not_found.no_update_available.wp_update_pluginreturning aWP_Error), the status will befailed, and an appropriate error message will be provided.Testing Plan
✅ Live Testing Completed
This feature has been thoroughly tested in a live WordPress environment during development. The following tests were performed:
Successfully Updated Plugins with Version Tracking:
Plugins Already Up-to-Date:
Verified Response Format:
old_versionfield correctly populatednew_versionfield correctly populatedreactivatedstatus properly reportedTest Environment:
All tests confirmed the feature works as expected and provides valuable version tracking information that was previously missing.
Unit Testing
plugin_slugs(empty, single string, array of strings).wp_update_plugin()to ensure correct calls and error handling for success and failure cases.success,failed,not_found,no_update_available).Integration Testing
update_pluginstool registration with MCP.wp_update_plugin()through the MCP tool's output.Manual Testing
Future Considerations
Checklist: