@webkult/phpstan-mcp-server
v1.0.0
Published
MCP server for PHPStan analysis - enables Claude to run static analysis directly
Downloads
16
Maintainers
Readme
PHPStan MCP Server
🤖 Model Context Protocol server for PHPStan - enables Claude to run static analysis directly.
Uses phpstan-ai-formatter for AI-optimized, token-efficient output.
What is this?
This MCP server allows Claude (via Claude Desktop or API) to:
- Run PHPStan analysis on your PHP code
- Get AI-optimized error reports (80% fewer tokens)
- Iterate on fixes automatically
- Verify code quality without leaving the conversation
Prerequisites
- Node.js 18 or higher
- A PHP project with Composer
- PHPStan and phpstan-ai-formatter installed in your project
Installation
Global Installation (Recommended)
npm install -g @webkult/phpstan-mcp-serverProject-Local Installation
npm install @webkult/phpstan-mcp-serverSetup with Claude Desktop
Install the server globally (see above)
Edit your Claude Desktop configuration:
macOS/Linux:
code ~/.config/claude/config.jsonWindows:
code %APPDATA%\Claude\config.json- Add the server to your config:
{
"mcpServers": {
"phpstan": {
"command": "phpstan-mcp-server"
}
}
}- Restart Claude Desktop
Setup Your PHP Project
In your PHP project, install PHPStan with the AI formatter:
composer require --dev phpstan/phpstan hackbard/phpstan-ai-formatterCreate a phpstan.neon config (optional):
parameters:
level: max
paths:
- srcUsage in Claude
Once configured, you can ask Claude to analyze your code:
You: "Analyze src/UserService.php with PHPStan"
Claude: [uses phpstan tool automatically]
"I found 3 issues in UserService.php:
1. Line 23: Method param $user: User|null ≠ User
Fix: Add null check or update type hint
2. Line 45: getUser() → User|null (expected User)
Fix: Update return type or handle null case
3. Line 67: Undefined property: $email
Fix: Add property declaration
Would you like me to generate the fixes?"Interactive Workflow
You: "Fix these issues and verify"
Claude: [generates fixes]
[runs PHPStan again to verify]
"✅ All issues resolved! Code now passes PHPStan level max."Available Tools
The server provides these tools to Claude:
analyze_php
Run PHPStan analysis on files or directories.
Parameters:
path(required): File or directory to analyzelevel(optional): Analysis level 0-9 or "max" (default: "max")format(optional): Output format "ai" or "ai-json" (default: "ai-json")
Example:
{
"path": "src/UserService.php",
"level": "max",
"format": "ai-json"
}check_phpstan
Check if PHPStan is installed and configured.
No parameters required.
Output Formats
ai-json (Default)
Structured JSON output optimized for AI parsing:
{
"totals": {
"errors": 2,
"warnings": 0
},
"files": {
"src/UserService.php": [
{
"line": 23,
"message": "Method param $user: User|null ≠ User",
"ignorable": true
}
]
}
}ai (Text)
Human-readable compact text format:
PHPStan Analysis
Found: 2 errors, 0 warnings
Errors
------
src/UserService.php:23 | Method param $user: User|null ≠ User
src/UserService.php:45 | getUser() → User|null (expected User)Troubleshooting
"PHPStan not found"
Install PHPStan in your project:
composer require --dev phpstan/phpstan hackbard/phpstan-ai-formatter"No composer.json found"
Make sure you're running this in a PHP project with Composer. Navigate to your project root:
cd /path/to/your/php/project"Path not found"
Use paths relative to your project root:
✅ analyze_php("src/Services/UserService.php")
❌ analyze_php("/absolute/path/to/file.php")Server not appearing in Claude Desktop
- Check config file location is correct
- Ensure JSON is valid (use a validator)
- Restart Claude Desktop completely
- Check Claude Desktop logs for errors
Development
Local Testing
# Clone the repo
git clone https://github.com/webkult/phpstan-mcp-server.git
cd phpstan-mcp-server
# Install dependencies
npm install
# Run locally
node index.jsTesting with Claude Desktop
Point to your local version in config:
{
"mcpServers": {
"phpstan": {
"command": "node",
"args": ["/path/to/phpstan-mcp-server/index.js"]
}
}
}Related Projects
- phpstan-ai-formatter - The Composer package that provides AI-optimized output
- PHPStan - PHP Static Analysis Tool
- Model Context Protocol - Open protocol for AI/LLM tool integration
License
MIT License - see LICENSE file for details.
Support
Made with 🤖 for Claude Desktop users
Part of the PHPStan AI ecosystem ⭐
