WPCS MCP Server
Integrates WordPress Coding Standards (WPCS) with Claude AI to automatically check and fix code quality issues in WordPress plugins and themes before commits.
README
WPCS MCP Server
A Model Context Protocol (MCP) server that integrates WordPress Coding Standards (WPCS) with Claude AI. This server enables automatic code quality checks and fixes for WordPress plugins and themes before commits.
Features
- Pre-commit WPCS validation - Automatically check staged PHP files against WordPress Coding Standards
- Auto-fix support - Automatically fix coding standard violations using phpcbf
- Block commits on errors - Prevent commits when WPCS errors are found
- Claude Code integration - Seamless integration with Claude Code CLI
- Multiple check modes - Check individual files, directories, or all staged files
Available Tools
| Tool | Description |
|---|---|
wpcs_check_staged |
Check all staged PHP files against WPCS |
wpcs_check_file |
Check a single PHP file |
wpcs_check_directory |
Check all PHP files in a directory |
wpcs_fix_file |
Auto-fix WPCS violations in a file |
wpcs_pre_commit |
Full pre-commit workflow: auto-fix, re-stage, and report |
Prerequisites
1. Install PHP CodeSniffer and WordPress Coding Standards
# Install globally via Composer
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require squizlabs/php_codesniffer wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer
# Add composer bin to PATH (add to ~/.zshrc or ~/.bashrc)
export PATH="$HOME/.composer/vendor/bin:$PATH"
# Verify installation
phpcs -i
# Should show: WordPress, WordPress-Core, WordPress-Docs, WordPress-Extra
2. Node.js 18+
Ensure you have Node.js version 18 or higher installed.
Installation
Option 1: Clone and Build
# Clone the repository
git clone https://github.com/vapvarun/wpcs-mcp-server.git ~/.mcp-servers/wpcs-mcp-server
# Install dependencies
cd ~/.mcp-servers/wpcs-mcp-server
npm install --include=dev
# Build
npm run build
Option 2: NPM Install (Coming Soon)
npm install -g wpcs-mcp-server
Configuration
For Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"wpcs": {
"command": "node",
"args": [
"/path/to/wpcs-mcp-server/build/index.js"
],
"env": {
"PATH": "/Users/YOUR_USERNAME/.composer/vendor/bin:/usr/local/bin:/usr/bin:/bin"
}
}
}
}
For Claude Code CLI
Add to ~/.claude/settings.json:
{
"permissions": {
"allow": [
"mcp__wpcs__wpcs_check_staged",
"mcp__wpcs__wpcs_check_file",
"mcp__wpcs__wpcs_check_directory",
"mcp__wpcs__wpcs_fix_file",
"mcp__wpcs__wpcs_pre_commit"
]
}
}
Pre-commit Hook (Optional)
Create ~/.claude/hooks/wpcs-pre-commit.sh:
#!/bin/bash
export PATH="$HOME/.composer/vendor/bin:$PATH"
# Get staged PHP files
STAGED_PHP=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.php$' || true)
if [ -z "$STAGED_PHP" ]; then
exit 0
fi
# Check each file
TOTAL_ERRORS=0
for file in $STAGED_PHP; do
if [ -f "$file" ]; then
RESULT=$(phpcs --standard=WordPress --report=json "$file" 2>/dev/null || true)
FILE_ERRORS=$(echo "$RESULT" | grep -o '"errors":[0-9]*' | head -1 | grep -o '[0-9]*' || echo "0")
if [ "$FILE_ERRORS" -gt 0 ] 2>/dev/null; then
TOTAL_ERRORS=$((TOTAL_ERRORS + FILE_ERRORS))
fi
fi
done
if [ "$TOTAL_ERRORS" -gt 0 ]; then
echo "WPCS ERROR: Found $TOTAL_ERRORS coding standard error(s)"
echo "Run: wpcs_pre_commit to fix"
exit 2
fi
exit 0
Then add to ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash(git commit*)",
"hooks": [
{
"type": "command",
"command": "bash \"$HOME/.claude/hooks/wpcs-pre-commit.sh\""
}
]
}
]
}
}
Usage
With Claude
Simply ask Claude to check your WordPress code:
"Check my staged files for WPCS violations"
"Run wpcs_pre_commit before I commit"
"Fix WPCS issues in includes/class-my-plugin.php"
"Check the entire src/ directory for coding standards"
Example Workflow
- Make changes to your WordPress plugin/theme
- Stage your changes:
git add . - Ask Claude: "Run wpcs_pre_commit"
- Claude will:
- Auto-fix what can be fixed
- Re-stage the fixed files
- Report any remaining issues
- If no errors, commit proceeds; otherwise, fix remaining issues
Tool Details
wpcs_pre_commit
The most commonly used tool. It performs a complete pre-commit workflow:
Input:
- working_dir (optional): Git repository root
- auto_stage (optional): Re-stage fixed files (default: true)
Output:
- PRE-COMMIT: PASSED or PRE-COMMIT: BLOCKED
- List of auto-fixed files
- Remaining issues with line numbers
wpcs_check_file
Check a single PHP file:
Input:
- file_path (required): Path to PHP file
- working_dir (optional): Working directory
Output:
- Errors and warnings with line/column numbers
- Source of each violation
- Whether each issue is auto-fixable
wpcs_fix_file
Auto-fix a single file:
Input:
- file_path (required): Path to PHP file
- working_dir (optional): Working directory
Output:
- Confirmation of fixes applied
- Remaining issues that couldn't be auto-fixed
WordPress Coding Standards
This server uses the WordPress ruleset which includes:
- WordPress-Core - Essential WordPress coding standards
- WordPress-Extra - Additional best practices
- WordPress-Docs - Documentation standards
Development
# Clone
git clone https://github.com/vapvarun/wpcs-mcp-server.git
cd wpcs-mcp-server
# Install dependencies
npm install --include=dev
# Build
npm run build
# Watch mode
npm run dev
Troubleshooting
phpcs not found
Ensure composer bin is in your PATH:
export PATH="$HOME/.composer/vendor/bin:$PATH"
Add this to your shell profile (~/.zshrc or ~/.bashrc).
WordPress standard not found
Reinstall WPCS:
composer global require wp-coding-standards/wpcs
phpcs -i # Verify WordPress is listed
MCP server not loading
- Check the path in your config is correct
- Ensure the server is built:
npm run build - Restart Claude Desktop or Claude Code
License
GPL-2.0-or-later
Author
Varun Dubey (@vapvarun)
- Website: wbcomdesigns.com
- Email: varun@wbcomdesigns.com
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Acknowledgments
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。