momodemo333/php-mcp-mysql
Composer 安装命令:
composer require momodemo333/php-mcp-mysql
包简介
MySQL MCP Server for Claude Code - Secure and configurable MySQL integration via Model Context Protocol
README 文档
README
MySQL MCP Server for Claude Code - Secure and configurable MySQL integration via Model Context Protocol.
🙏 Acknowledgments
This project is built on top of the excellent php-mcp/server library. Special thanks to the MCP community for providing the foundation that makes this integration possible.
🚀 Quick Installation
Via Composer (Recommended)
composer require momodemo333/php-mcp-mysql
Claude Code Configuration
Add to your .cursor/mcp.json:
{
"mcpServers": {
"mysql": {
"command": "php",
"args": ["vendor/momodemo333/php-mcp-mysql/bin/server.php"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_PORT": "3306",
"MYSQL_USER": "your_user",
"MYSQL_PASS": "your_password",
"MYSQL_DB": "your_database"
}
}
}
}
Quick Test
# Test connection php vendor/momodemo333/php-mcp-mysql/tests/test_connection.php # Test MCP server php vendor/momodemo333/php-mcp-mysql/tests/test_mcp_server.php
🎉 That's it! Your MySQL MCP Server is ready!
✨ Features
🛠️ Available MCP Tools
mysql_list_databases- List all databasesmysql_list_tables- List tables in a databasemysql_describe_table- Describe table structure (columns, indexes, foreign keys)mysql_server_status- Get MySQL server status and healthmysql_select- Execute secure SELECT queriesmysql_insert- Insert data with validationmysql_update- Update data with mandatory conditionsmysql_delete- Delete data with safety limitsmysql_execute_query- Execute custom SQL queries
🔒 Security Features
- SQL Injection Protection - All queries use prepared statements
- Operation Permissions - Granular control (INSERT, UPDATE, DELETE)
- Query Validation - Dangerous keyword blocking
- Connection Pooling - Efficient resource management
- Result Limiting - Configurable result set limits
- Schema Restrictions - Limit access to specific databases
⚙️ Configuration Options
Environment Variables:
MYSQL_HOST,MYSQL_PORT,MYSQL_USER,MYSQL_PASS,MYSQL_DBALLOW_INSERT_OPERATION,ALLOW_UPDATE_OPERATION,ALLOW_DELETE_OPERATIONALLOW_DDL_OPERATIONS⭐ - New! Authorize CREATE, ALTER, DROP operationsALLOW_ALL_OPERATIONS⭐ - New! Super admin mode (use with caution)MAX_RESULTS,QUERY_TIMEOUT,LOG_LEVELCONNECTION_POOL_SIZE,ENABLE_PREPARED_STATEMENTS
Configuration Methods:
- Environment Variables (via MCP config)
.envFiles (per project)- CLI Arguments (for testing)
📖 Documentation
📚 Complete Guides
- Quick Start - Get running in 5 minutes
- MCP Configuration - Understanding MCP transports (
stdio,http,websocket) - Installation Guide - Detailed setup instructions
- MCP Tools Reference - Complete tool documentation
- Usage Examples - Practical examples
- Multi-Project Setup - Configure for multiple projects
- Troubleshooting - Common issues and solutions
🔧 Configuration Examples
Simple Configuration:
{
"mcpServers": {
"mysql": {
"type": "stdio",
"command": "php",
"args": ["vendor/momodemo333/php-mcp-mysql/bin/server.php"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_USER": "myapp",
"MYSQL_PASS": "password",
"MYSQL_DB": "myapp_db"
}
}
}
}
💡 MCP Transport Types: The
"type": "stdio"parameter specifies the communication method between your MCP client and the server. See MCP Configuration Guide for complete details onstdio,http, andwebsockettransports.
Multi-Environment Configuration:
{
"mcpServers": {
"mysql-dev": {
"command": "php",
"args": ["vendor/momodemo333/php-mcp-mysql/bin/server.php"],
"env": {
"MYSQL_HOST": "127.0.0.1",
"MYSQL_USER": "dev_user",
"MYSQL_PASS": "dev_pass",
"MYSQL_DB": "myapp_dev",
"ALLOW_INSERT_OPERATION": "true",
"ALLOW_UPDATE_OPERATION": "true",
"ALLOW_DELETE_OPERATION": "true",
"LOG_LEVEL": "DEBUG"
}
},
"mysql-prod": {
"command": "php",
"args": ["vendor/momodemo333/php-mcp-mysql/bin/server.php"],
"env": {
"MYSQL_HOST": "prod.example.com",
"MYSQL_USER": "readonly_user",
"MYSQL_PASS": "prod_pass",
"MYSQL_DB": "myapp_prod",
"ALLOW_INSERT_OPERATION": "false",
"ALLOW_UPDATE_OPERATION": "false",
"ALLOW_DELETE_OPERATION": "false",
"MAX_RESULTS": "50",
"LOG_LEVEL": "ERROR"
}
}
}
}
🛡️ Security & Best Practices
🔐 Security Recommendations
-
Use Read-Only Users in Production
CREATE USER 'readonly_user'@'%' IDENTIFIED BY 'secure_password'; GRANT SELECT ON production_db.* TO 'readonly_user'@'%'; FLUSH PRIVILEGES;
-
Limit Database Access
ALLOWED_SCHEMAS=myapp_prod,myapp_logs
-
Set Result Limits
MAX_RESULTS=100 QUERY_TIMEOUT=10
-
Use Environment Variables for Passwords
export MYSQL_PASS_PROD="$(security find-generic-password -s 'mysql-prod' -w)"
🔒 DDL Permissions (v1.1.0+)
Three-level permission system:
-
Level 1 - CRUD Operations:
ALLOW_INSERT_OPERATION=true # INSERT statements ALLOW_UPDATE_OPERATION=true # UPDATE statements ALLOW_DELETE_OPERATION=true # DELETE statements ALLOW_TRUNCATE_OPERATION=false # TRUNCATE statements
-
Level 2 - Schema Operations (NEW!):
ALLOW_DDL_OPERATIONS=true # CREATE, ALTER, DROP tables/indexes -
Level 3 - Super Admin (NEW!):
ALLOW_ALL_OPERATIONS=true # All operations (use with extreme caution)
Example - Enable schema modifications:
# Fix "Mot-clé non autorisé détecté: ALTER" errors
ALLOW_DDL_OPERATIONS=true
✅ Production Checklist
- Use dedicated MySQL user with minimal permissions
- Set
ALLOW_*_OPERATION=falsefor production (except SELECT) - Carefully consider
ALLOW_DDL_OPERATIONS=falsein production ⚠️ - Never use
ALLOW_ALL_OPERATIONS=truein production ❌ - Configure
MAX_RESULTSandQUERY_TIMEOUT - Use
LOG_LEVEL=ERRORin production - Restrict
ALLOWED_SCHEMASto necessary databases - Store passwords securely (environment variables)
- Enable
BLOCK_DANGEROUS_KEYWORDS=true
🧪 Development & Testing
🚀 New Test Suite (v1.1.0+)
Professional testing infrastructure with Docker:
# Quick start - all tests with Docker MySQL make test # Development commands make test-unit # Fast unit tests (5s) make test-integration # Integration tests with MySQL make test-coverage # Generate HTML coverage report make clean # Clean Docker resources # Advanced testing ./tests/scripts/docker-test-complete.sh -v -c # Verbose + coverage
Test Coverage:
- 🧪 29+ tests (unit + integration)
- 🎯 >90% coverage of critical services
- 🐳 Automated Docker MySQL environment
- 🔄 CI/CD ready with GitHub Actions
Documentation:
Legacy Testing
# Copy environment template cp .env.example .env # Edit .env with your MySQL settings # Run connection test php tests/test_connection.php # Run full MCP server test php tests/test_mcp_server.php # Setup test data php scripts/setup_test_data.php
Development Setup
# Clone repository git clone https://github.com/momodemo333/php-mcp-mysql.git cd php-mcp-mysql # Install dependencies composer install # Copy configuration cp .env.example .env # Edit .env with your settings # Run tests composer test
📊 Usage with Claude Code
Natural Language Examples
Database Exploration:
"Show me all tables in the database"
"What's the structure of the users table?"
"How many orders are in the database?"
Data Analysis:
"Find all users created in the last 30 days"
"Show me the top 5 best-selling products"
"What's the average order value by month?"
Business Intelligence:
"Analyze customer behavior patterns"
"Show sales trends for the last quarter"
"Find inactive users who haven't ordered in 6 months"
Data Management:
"Add a new user with email john@example.com"
"Update the user's email address"
"Clean up old temporary data"
🤝 Contributing
Contributions are welcome! Please read our contributing guidelines and:
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
Development Guidelines
- Follow PSR-12 coding standards
- Add tests for new features
- Update documentation
- Ensure security best practices
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License Summary:
- ✅ Commercial use
- ✅ Modification
- ✅ Distribution
- ✅ Private use
- ❌ Liability
- ❌ Warranty
🆘 Support
- 📖 Documentation: docs/
- 🐛 Issues: GitHub Issues
- 💡 Feature Requests: GitHub Discussions
🎯 Roadmap
- PostgreSQL support
- Advanced query caching
- Connection encryption (SSL/TLS)
- Query performance analytics
- Multi-database connection management
- GraphQL-style query building
Made with ❤️ for the Claude Code community
Powered by php-mcp/server
momodemo333/php-mcp-mysql 适用场景与选型建议
momodemo333/php-mcp-mysql 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「mysql」 「ai」 「mcp」 「model-context-protocol」 「claude-code」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 momodemo333/php-mcp-mysql 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 momodemo333/php-mcp-mysql 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 momodemo333/php-mcp-mysql 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Secure HTTP transport wrapper for MCP servers with API key auth, IP/Origin allowlisting, and rate limiting
Standardized event classes for MCP (Model Context Protocol) tool execution lifecycle
JSON Schema builder and validator for MCP tool definitions
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 25
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-05