-
Notifications
You must be signed in to change notification settings - Fork 80
Fix/improve tools validation and linting #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/improve tools validation and linting #78
Conversation
- Introduced `wp mcp validate-tools` command to validate registered MCP tools with options for specific tool validation, validation levels, and output formats. - Added comprehensive documentation for command usage, options, and examples in `wp-cli-commands.md`. - Implemented validation logic in `ValidateToolsCommand.php`, including error handling and detailed output for validation results.
- Introduced `SchemaValidator` class for loading and validating JSON schemas, including caching mechanisms and error handling. - Added `ValidateTool` class for comprehensive validation of MCP tools with support for different validation levels (strict, extended, permissive). - Created JSON schema files for MCP tools and WordPress-specific extensions, ensuring compliance with the Model Context Protocol. - Included README documentation for schema usage, validation levels, and caching strategies.
- Improved validation for the properties field to ensure it can be either an array or an object. - Added checks for property name format to comply with MCP requirements. - Ensured that required fields are non-empty strings and validated their existence against the properties field. - Introduced error handling for cases where required fields are defined without a corresponding properties definition.
- Simplified the input schema by removing unnecessary properties definitions.
- Introduced a new 'context' property in the input schema with type 'string' and an enum value of 'edit'.
- Simplified the method signature by removing the unused parameters.
- Removed the unused parameter from the list_resource_templates method to simplify its signature. - Updated the corresponding call in McpTransportBase to reflect the change.
- Modified the status assignment to use strict comparison in the PluginsInfo class.
- Added translator comments for clarity on tool status messages. - Updated the handling of the 'tool_enabled' input to ensure proper sanitization before validation.
- Removed the unused parameter from the list_all_tools method to simplify its signature. - Updated the corresponding call in McpTransportBase to reflect the change.
- Added periods to the end of comments .
- Added a PHPCS ignore comment for the use of base64_decode to clarify its intentional use despite being flagged.
- Removed the unused parameter from the list_tokens method to simplify its signature. - Updated error logging to use McpErrorHandler for improved error handling.
- Added a PHPCS ignore comment to the error_log call to suppress warnings related to its usage, clarifying its intentional use in the error handling process.
- Added a PHPCS ignore comment to suppress warnings, clarifying its intentional use in the InputSchema file.
- Removed the optional parameters from the get_user_info method.
- Removed optional parameters from the get_theme_info method.
- Changed the parameter name from $callable to $callback.
- Removed optional parameters from the get_plugin_info method to simplify its signature and return all plugin information without filtering.
- Renamed the parameter from $array to $data.
- Removed optional parameters from the get_site_settings method.
- Changed the parameter name from $resource to $resource_id.
- Added periods to the end of comments for consistency and improved readability.
- Added a PHPCS ignore comment to suppress warnings for the use of file_get_contents, clarifying its intentional use in loading schema files.
- Added a new parameter for the resource content callback and improved the exception documentation.
- Changed PHP compatibility test version from 5.6 to 8.0 in .phpcs.xml.dist. - Updated global prefixes and text domain for WordPress standards. - Added PHP linting commands to package.json for improved code quality checks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves tools validation and linting infrastructure for the WordPress MCP plugin by introducing comprehensive validation utilities, fixing PHP linting violations, and adding WP-CLI commands for tool validation.
- Replaces legacy validation with enhanced ValidateTool utility supporting multiple validation levels (strict, extended, permissive)
- Adds JSON Schema-based validation with MCP specification compliance and WordPress-specific extensions
- Introduces WP-CLI
validate-tools
command for comprehensive tool validation and debugging
Reviewed Changes
Copilot reviewed 36 out of 38 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
includes/Utils/ValidateTool.php | New comprehensive validation utility with multi-level validation support |
includes/Utils/SchemaValidator.php | JSON Schema validation utility for MCP tools |
includes/Cli/ValidateToolsCommand.php | WP-CLI command for validating MCP tools |
wordpress-mcp.php | Adds CLI command registration and renames init function |
package.json | Adds PHP linting scripts |
includes/schemas/ | New JSON schemas for MCP and WordPress extensions |
Comments suppressed due to low confidence (2)
wordpress-mcp.php:55
- [nitpick] The function name change from 'init_wordpress_mcp' to 'wordpress_mcp_init' improves consistency with WordPress naming conventions where the prefix comes first.
function wordpress_mcp_init() {
includes/Utils/ValidateTool.php:348
- The pattern validation is incorrectly escaping the regex pattern with preg_quote, which will treat regex special characters as literals. For JSON Schema pattern validation, the pattern should be used directly without escaping.
if ( isset( $property['minItems'] ) && ( ! is_int( $property['minItems'] ) || $property['minItems'] < 0 ) ) {
// Initialize the plugin on plugins_loaded to ensure all dependencies are available. | ||
add_action( 'plugins_loaded', 'init_wordpress_mcp' ); | ||
// Initialize the plugin. | ||
add_action( 'init', 'wordpress_mcp_init' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing from 'plugins_loaded' to 'init' hook may cause timing issues if the plugin needs to run before other plugins or if dependencies aren't loaded yet. Consider if this timing change is intentional and necessary.
add_action( 'init', 'wordpress_mcp_init' ); | |
add_action( 'plugins_loaded', 'wordpress_mcp_init' ); |
Copilot uses AI. Check for mistakes.
// translators: %s: Property name. | ||
throw new InvalidArgumentException( sprintf( esc_html__( "Property '%s' must have a type field.", 'wordpress-mcp' ), esc_html( $property_name ) ) ); | ||
// Validate properties field if present (it's optional according to MCP spec). | ||
if ( isset( $this->args['inputSchema']['properties'] ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic checks for both array and object types for properties but the foreach loop assumes array structure. This could cause issues if properties is an object.
Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.