Provides comprehensive database operations including reading, writing, and managing MySQL databases with security features like SQL injection prevention, connection pooling, and transaction support.
KatCoder MySQL MCP Server
A secure and feature-rich MySQL Model Context Protocol (MCP) server that enables AI agents and applications to interact with MySQL databases through a standardized interface.
Features
🔒 Security First
SQL Injection Prevention: Comprehensive input validation and sanitization
Identifier Validation: Strict validation of table and column names
Query Whitelisting: Read-only operations by default, write operations require explicit permission
Connection Pooling: Secure connection management with timeout controls
Error Handling: Secure error messages that don't expose sensitive information
🛠️ Database Operations
List: Browse tables and view table structures
Read: Query data with filtering, pagination, and sorting
Create: Insert new records with validation
Update: Modify existing records safely
Delete: Remove records with mandatory WHERE clauses
Execute: Run custom SQL queries with security restrictions
DDL: Execute Data Definition Language statements
Transaction: Execute multiple operations atomically
Utility: Database health checks and metadata operations
🔧 Configuration Options
Connection String: Standard MySQL connection format
Tool Selection: Enable only the tools you need
Connection Pooling: Configurable pool settings
Timeout Controls: Connection and query timeouts
Installation
Note: This package is currently in development and not yet published to npm. Use the development installation method below.
Development Installation (Recommended)
Future npm Installation (Coming Soon)
Once published to npm, you will be able to install globally:
Local npm Installation (Coming Soon)
Usage
Command Line Interface
Current Development Usage
Future npm Usage (After Publication)
Configuration for AI Agents
Current Development Configuration
Claude Desktop Configuration: Add this configuration to your Claude Desktop configuration file:
Cursor IDE Configuration: For Cursor IDE, add to your settings:
Future npm Configuration (After Publication)
Claude Desktop Configuration:
Cursor IDE Configuration:
Connection String Format
Basic Examples:
mysql://root@localhost:3306/mydb- Local database without passwordmysql://user:password@localhost:3306/mydb- Local database with passwordmysql://user:password@192.168.1.100:3306/mydb- Remote database
Advanced Examples:
mysql://user:password@db.example.com:3306/production?ssl=true- Remote database with SSLmysql://root:password@mysql-container:3306/docker_db- Docker databasemysql://user:password@localhost:3307/alternative_port- Different port
Available Tools
1. List Tool
Browse database structure and table information.
Parameters:
table(optional): Specific table name to get column information
Examples:
Practical Usage Scenarios:
Database Discovery: When connecting to a new database, use the list tool without parameters to see all available tables
Schema Exploration: Use with a table name to understand the structure before writing queries
Data Modeling: Examine relationships between tables by checking foreign key constraints
Migration Planning: Understand existing schema before making changes
2. Read Tool
Query data from tables with filtering and pagination.
Parameters:
table(required): Table name to querycolumns(optional): Array of specific columns to selectwhere(optional): Object with filter conditionslimit(optional): Maximum number of rows (max: 10,000)offset(optional): Number of rows to skiporderBy(optional): Order by clause
Basic Examples:
Advanced Filtering Examples:
3. Create Tool
Insert new records into tables.
Parameters:
table(required): Target table namedata(required): Object with column-value pairs
Examples:
4. Update Tool
Modify existing records safely.
Parameters:
table(required): Target table namedata(required): Object with column-value pairs to updatewhere(required): Object with filter conditions
Examples:
5. Delete Tool
Remove records with mandatory WHERE clauses.
Parameters:
table(required): Target table namewhere(required): Object with filter conditions
Examples:
6. Execute Tool
Run custom SQL queries with security restrictions.
Parameters:
query(required): SQL query stringparams(optional): Array of query parametersallowWrite(optional): Boolean to allow write operations
Basic Examples:
Complex Query Examples:
7. DDL Tool
Execute Data Definition Language statements.
Parameters:
statement(required): DDL statement
Examples:
8. Transaction Tool
Execute multiple operations atomically.
Parameters:
operations(required): Array of operations to execute
Basic Examples:
Advanced Transaction Examples:
9. Utility Tool
Database health checks and metadata operations.
Parameters:
action(required): Utility action (ping, version, stats, describe_table)table(optional): Table name (required for describe_table)
Examples:
Security Features
SQL Injection Prevention
Input Sanitization: All table and column names are sanitized
Parameter Binding: All queries use parameterized statements
Query Validation: Dangerous SQL patterns are blocked
Write Operation Protection: Write operations require explicit permission
Identifier Validation
Table Names: Only alphanumeric characters and underscores allowed
Column Names: Validated against SQL injection patterns
Where Conditions: Values are checked for dangerous content
Connection Security
Connection Pooling: Secure connection management
Timeout Controls: Prevents hanging connections
Error Handling: Secure error messages without sensitive data
Security Best Practices
1. Use Dedicated Database User
Create a specific MySQL user with limited permissions:
2. Enable Only Required Tools
3. Use Environment Variables
Error Handling
The server provides detailed error messages while maintaining security:
Development
Building the Project
Running in Development Mode
Testing
Environment Variables
LOG_LEVEL: Set logging level (debug, info, warn, error)NODE_ENV: Set environment (development, production)
Troubleshooting
Connection Issues
Verify MySQL server is running
Check connection string format
Ensure database exists
Verify user permissions
Test Connection
Check Database Version
Permission Errors
Check MySQL user privileges
Ensure database access is granted
Verify table-level permissions
Performance Issues
Monitor connection pool usage
Check query execution times
Optimize database indexes
Monitor Performance
Advanced Configuration
Custom Connection Pool Settings
Logging Configuration
Contributing
Fork the repository
Create a feature branch
Make your changes
Add tests
Submit a pull request
License
MIT License - see LICENSE file for details.
Support
For issues and questions:
GitHub Issues: https://github.com/katkoder/katcoder-mysql-mcp/issues
Documentation: https://github.com/katkoder/katcoder-mysql-mcp/wiki
Changelog
v1.0.0
Initial release
All database operations implemented
Comprehensive security features
Full documentation
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A secure MySQL Model Context Protocol server that enables AI agents to interact with MySQL databases through standardized operations. Features comprehensive security with SQL injection prevention, connection pooling, and configurable tool access for database operations.