Skip to main content
Glama
miniOrangeDev

WordPress Code Review MCP Server

validate_code

Validate PHP, JavaScript, CSS, or HTML code against WordPress coding standards to ensure compliance and maintain code quality in development projects.

Instructions

Validate code against configured coding standards

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe code to validate
languageYesThe programming language of the code

Implementation Reference

  • Primary MCP tool handler for 'validate_code': delegates to guidelineSource.validateCode and formats the response with issues and suggestions.
    private async validateCode(code: string, language: string) { try { const result = await this.guidelineSource.validateCode(code, language); const response = []; if (result.issues.length > 0) { response.push(`❌ **Issues Found:**\n${result.issues.map(issue => `- ${issue}`).join('\n')}`); } if (result.suggestions.length > 0) { response.push(`💡 **Suggestions:**\n${result.suggestions.map(suggestion => `- ${suggestion}`).join('\n')}`); } if (response.length === 0) { response.push('✅ Code validation passed. No issues detected.'); } return { content: [ { type: 'text', text: response.join('\n\n'), }, ], }; } catch (error) { throw new Error(`Code validation failed: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
  • Registration of the 'validate_code' tool in getTools(), including name, description, and input schema.
    { name: 'validate_code', description: 'Validate code against configured coding standards', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'The code to validate', }, language: { type: 'string', enum: ['php', 'javascript', 'css', 'html'], description: 'The programming language of the code', }, }, required: ['code', 'language'], }, },
  • Core validation handler: extracts rules from guidelines markdown and applies them to the provided code.
    private parseValidationRules(guidelines: string, code: string, language: string): { issues: string[]; suggestions: string[] } { const issues: string[] = []; const suggestions: string[] = []; // Parse markdown format guidelines and apply to code const rules = this.extractRules(guidelines, 'VALIDATION_RULES'); for (const rule of rules) { const result = this.applyRule(rule, code, language); if (result.violation) { issues.push(result.message); } else if (result.suggestion) { suggestions.push(result.message); } } return { issues, suggestions }; }
  • GuidelineSource.validateCode implementation: loads validation rules and invokes parsing logic.
    async validateCode(code: string, language: string): Promise<{ issues: string[]; suggestions: string[] }> { const guidelines = await this.fetchGuidelines('validation-rules'); return this.parseValidationRules(guidelines, code, language); }
  • Helper function to extract validation rules from the fetched guidelines markdown content.
    private extractRules(content: string, section: string): Array<{ pattern: string; message: string; level?: string; language?: string }> { const rules: Array<{ pattern: string; message: string; level?: string; language?: string }> = []; // Look for rules in markdown format - simplified approach const sectionRegex = new RegExp(`## ${section}([\\s\\S]*)`, 'i'); const sectionMatch = content.match(sectionRegex); if (sectionMatch) { // Split by lines and process each line that looks like a rule const lines = sectionMatch[1].split('\n'); for (const line of lines) { // Look for lines that start with - **Pattern**: if (line.trim().startsWith('- **Pattern**:')) { // Extract pattern const patternMatch = line.match(/`([^`]+)`/); if (!patternMatch) continue; const pattern = patternMatch[1]; // Extract message (everything between **Message**: and **Level**: or **Language**:) const messageMatch = line.match(/\*\*Message\*\*:\s*([^*]+?)(?:\s*\*\*(?:Level|Language)\*\*|$)/); const message = messageMatch ? messageMatch[1].trim() : 'No message'; // Extract level const levelMatch = line.match(/\*\*Level\*\*:\s*(\w+)/); const level = levelMatch ? levelMatch[1] : 'INFO'; // Extract language const languageMatch = line.match(/\*\*Language\*\*:\s*(\w+)/); const language = languageMatch ? languageMatch[1] : 'all'; rules.push({ pattern, message, level, language }); } } } return rules; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/miniOrangeDev/wp-code-review-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server