PHPackages                             momodemo333/php-mcp-mysql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. momodemo333/php-mcp-mysql

ActiveLibrary[Database &amp; ORM](/categories/database)

momodemo333/php-mcp-mysql
=========================

MySQL MCP Server for Claude Code - Secure and configurable MySQL integration via Model Context Protocol

v1.1.1(8mo ago)14MITPHPPHP &gt;=8.1CI passing

Since Aug 5Pushed 7mo agoCompare

[ Source](https://github.com/momodemo333/php-mcp-mysql)[ Packagist](https://packagist.org/packages/momodemo333/php-mcp-mysql)[ Docs](https://github.com/momodemo333/php-mcp-mysql)[ RSS](/packages/momodemo333-php-mcp-mysql/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (0)

🗄️ PHP MCP MySQL Server
=======================

[](#️-php-mcp-mysql-server)

[![PHP](https://camo.githubusercontent.com/964517d2570399dcc692858a365295a6d0065689a0647b7074fb3c7ff25ffee2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d2533453d382e312d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![MCP](https://camo.githubusercontent.com/73a628e0630600a792875ec4638d167ba9e0338dd609f75814a1bd5ef0f9eb79/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d43502d332e332d707572706c652e737667)](https://github.com/php-mcp/server)[![Tests](https://github.com/momodemo333/php-mcp-mysql/workflows/Tests/badge.svg)](https://github.com/momodemo333/php-mcp-mysql/actions)[![Packagist](https://camo.githubusercontent.com/15dd42d5a6e21b5aa3894a48e78bacdaa911dc00544dfee6be60e2ed0b7a4079/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f6d6f64656d6f3333332f7068702d6d63702d6d7973716c2e737667)](https://packagist.org/packages/momodemo333/php-mcp-mysql)[![Downloads](https://camo.githubusercontent.com/810565819d2765854181c96117594b8505dd872552321726ad16f9a552edf870/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f6d6f64656d6f3333332f7068702d6d63702d6d7973716c2e737667)](https://packagist.org/packages/momodemo333/php-mcp-mysql)

MySQL MCP Server for Claude Code - Secure and configurable MySQL integration via Model Context Protocol.

🙏 Acknowledgments
-----------------

[](#-acknowledgments)

This project is built on top of the excellent [php-mcp/server](https://github.com/php-mcp/server) library. Special thanks to the MCP community for providing the foundation that makes this integration possible.

🚀 Quick Installation
--------------------

[](#-quick-installation)

### Via Composer (Recommended)

[](#via-composer-recommended)

```
composer require momodemo333/php-mcp-mysql
```

### Claude Code Configuration

[](#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

[](#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
----------

[](#-features)

### 🛠️ Available MCP Tools

[](#️-available-mcp-tools)

- **`mysql_list_databases`** - List all databases
- **`mysql_list_tables`** - List tables in a database
- **`mysql_describe_table`** - Describe table structure (columns, indexes, foreign keys)
- **`mysql_server_status`** - Get MySQL server status and health
- **`mysql_select`** - Execute secure SELECT queries
- **`mysql_insert`** - Insert data with validation
- **`mysql_update`** - Update data with mandatory conditions
- **`mysql_delete`** - Delete data with safety limits
- **`mysql_execute_query`** - Execute custom SQL queries

### 🔒 Security Features

[](#-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

[](#️-configuration-options)

**Environment Variables:**

- `MYSQL_HOST`, `MYSQL_PORT`, `MYSQL_USER`, `MYSQL_PASS`, `MYSQL_DB`
- `ALLOW_INSERT_OPERATION`, `ALLOW_UPDATE_OPERATION`, `ALLOW_DELETE_OPERATION`
- `ALLOW_DDL_OPERATIONS` ⭐ - **New!** Authorize CREATE, ALTER, DROP operations
- `ALLOW_ALL_OPERATIONS` ⭐ - **New!** Super admin mode (use with caution)
- `MAX_RESULTS`, `QUERY_TIMEOUT`, `LOG_LEVEL`
- `CONNECTION_POOL_SIZE`, `ENABLE_PREPARED_STATEMENTS`

**Configuration Methods:**

1. **Environment Variables** (via MCP config)
2. **`.env` Files** (per project)
3. **CLI Arguments** (for testing)

---

📖 Documentation
---------------

[](#-documentation)

### 📚 Complete Guides

[](#-complete-guides)

- **[Quick Start](docs/quick-start.md)** - Get running in 5 minutes
- **[MCP Configuration](docs/mcp-configuration.md)** - Understanding MCP transports (`stdio`, `http`, `websocket`)
- **[Installation Guide](docs/installation.md)** - Detailed setup instructions
- **[MCP Tools Reference](docs/mcp-tools.md)** - Complete tool documentation
- **[Usage Examples](docs/examples.md)** - Practical examples
- **[Multi-Project Setup](docs/multi-project-setup.md)** - Configure for multiple projects
- **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions

### 🔧 Configuration Examples

[](#-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](docs/mcp-configuration.md)** for complete details on `stdio`, `http`, and `websocket` transports.

**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 &amp; Best Practices
--------------------------------

[](#️-security--best-practices)

### 🔐 Security Recommendations

[](#-security-recommendations)

1. **Use Read-Only Users in Production**

    ```
    CREATE USER 'readonly_user'@'%' IDENTIFIED BY 'secure_password';
    GRANT SELECT ON production_db.* TO 'readonly_user'@'%';
    FLUSH PRIVILEGES;
    ```
2. **Limit Database Access**

    ```
    ALLOWED_SCHEMAS=myapp_prod,myapp_logs
    ```
3. **Set Result Limits**

    ```
    MAX_RESULTS=100
    QUERY_TIMEOUT=10
    ```
4. **Use Environment Variables for Passwords**

    ```
    export MYSQL_PASS_PROD="$(security find-generic-password -s 'mysql-prod' -w)"
    ```

### 🔒 DDL Permissions (v1.1.0+)

[](#-ddl-permissions-v110)

**Three-level permission system:**

1. **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
    ```
2. **Level 2 - Schema Operations (NEW!):**

    ```
    ALLOW_DDL_OPERATIONS=true      # CREATE, ALTER, DROP tables/indexes
    ```
3. **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

[](#-production-checklist)

- Use dedicated MySQL user with minimal permissions
- Set `ALLOW_*_OPERATION=false` for production (except SELECT)
- **Carefully consider `ALLOW_DDL_OPERATIONS=false`** in production ⚠️
- **Never use `ALLOW_ALL_OPERATIONS=true`** in production ❌
- Configure `MAX_RESULTS` and `QUERY_TIMEOUT`
- Use `LOG_LEVEL=ERROR` in production
- Restrict `ALLOWED_SCHEMAS` to necessary databases
- Store passwords securely (environment variables)
- Enable `BLOCK_DANGEROUS_KEYWORDS=true`

---

🧪 Development &amp; Testing
---------------------------

[](#-development--testing)

### 🚀 New Test Suite (v1.1.0+)

[](#-new-test-suite-v110)

**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)
- 🎯 **&gt;90% coverage** of critical services
- 🐳 **Automated Docker** MySQL environment
- 🔄 **CI/CD ready** with GitHub Actions

**Documentation:**

- 📖 [Complete Testing Guide](docs/TESTING.md)
- 🚀 [Quick Testing README](tests/README.md)

### Legacy Testing

[](#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

[](#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
------------------------

[](#-usage-with-claude-code)

### Natural Language Examples

[](#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
--------------

[](#-contributing)

Contributions are welcome! Please read our contributing guidelines and:

1. **Fork** the repository
2. **Create** your feature branch: `git checkout -b feature/amazing-feature`
3. **Commit** your changes: `git commit -m 'Add amazing feature'`
4. **Push** to branch: `git push origin feature/amazing-feature`
5. **Open** a Pull Request

### Development Guidelines

[](#development-guidelines)

- Follow PSR-12 coding standards
- Add tests for new features
- Update documentation
- Ensure security best practices

---

📄 License
---------

[](#-license)

This project is licensed under the **MIT License** - see the [LICENSE](LICENSE) file for details.

**MIT License Summary:**

- ✅ Commercial use
- ✅ Modification
- ✅ Distribution
- ✅ Private use
- ❌ Liability
- ❌ Warranty

---

🆘 Support
---------

[](#-support)

- **📖 Documentation**: [docs/](docs/)
- **🐛 Issues**: [GitHub Issues](https://github.com/momodemo333/php-mcp-mysql/issues)
- **💡 Feature Requests**: [GitHub Discussions](https://github.com/momodemo333/php-mcp-mysql/discussions)

---

🎯 Roadmap
---------

[](#-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](https://github.com/php-mcp/server)*

###  Health Score

33

—

LowBetter than 74% of packages

Maintenance65

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

5

Last Release

250d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/feba37b54dd366f8d54716c59d586a4af2408fcf5bd88d034a102149ae361e80?d=identicon)[momodemo333](/maintainers/momodemo333)

---

Top Contributors

[![momodemo333](https://avatars.githubusercontent.com/u/81758876?v=4)](https://github.com/momodemo333 "momodemo333 (34 commits)")

---

Tags

mcpdatabaseaimysqlclaude-codeModel Context Protocolphp mcp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/momodemo333-php-mcp-mysql/health.svg)

```
[![Health](https://phpackages.com/badges/momodemo333-php-mcp-mysql/health.svg)](https://phpackages.com/packages/momodemo333-php-mcp-mysql)
```

###  Alternatives

[rah/danpu

Zero-dependency MySQL dump library for easily exporting and importing databases

64401.8k10](/packages/rah-danpu)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
