mcp-mysql-lens
MCP server to connect MySQL DB for read-only queries. It offers accurate query execution.
README
MCP MySQL Lens
A Model Context Protocol (MCP) server that enables Claude Desktop to interact with MySQL databases directly. This server allows Claude to query, analyze, and manage your MySQL databases through natural language.
Features
- 🔍 Query Execution: Run SQL queries directly from Claude Desktop
- 📊 Schema Inspection: Explore database structure, tables, and relationships
- 🔄 Data Analysis: Analyze and visualize data patterns
- 🛡️ Safe Operations: Built-in safeguards for database operations
- 🚀 Easy Setup: Simple configuration with environment variables
Prerequisites
- Claude Desktop installed
- Node.js (v16 or higher)
- MySQL Server (v5.7 or higher)
- install npm
- Valid MySQL credentials with appropriate permissions
NPM Link
Visit npm package mcp-mysql-lens
Installation
1. Install the MCP Server
npm install -g mcp-mysql-lens
2. Configure Claude Desktop
Add this configuration to your Claude Desktop config file:
{
"mcpServers": {
"mysql": {
"command": "npx",
"args": [
"mcp-mysql-lens"
],
"env": {
"MYSQL_HOST": "<YOUR_MYSQL_HOST>",
"MYSQL_PORT": "<YOUR_MYSQL_PORT>",
"MYSQL_USER": "<YOUR_MYSQL_USERNAME>",
"MYSQL_PASSWORD": "<YOUR_MYSQL_PASSWORD>",
"MYSQL_DATABASE": "<YOUR_MYSQL_DEFAULT_DB>"
}
}
}
}
Configuration File Location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
3. Restart Claude Desktop
After saving the configuration, restart Claude Desktop for the changes to take effect.
Configuration Parameters
| Parameter | Description | Default | Required |
|---|---|---|---|
MYSQL_HOST |
MySQL server hostname | - | Yes |
MYSQL_PORT |
MySQL server port | 3306 |
Yes |
MYSQL_USER |
Database username | - | Yes |
MYSQL_PASSWORD |
Database password | - | Yes |
MYSQL_DATABASE |
Default database to connect to | - | Yes |
Usage Examples
Once configured, you can interact with your MySQL database through Claude Desktop:
Query Data
"Show me all users from the users table"
"What are the top 10 products by sales?"
"Find all orders from the last 30 days"
Analyze Schema
"What tables are in my database?"
"Describe the structure of the customers table"
"Show me the relationships between tables"
Data Analysis
"Calculate the average order value by month"
"Find duplicate records in the products table"
"Show me user registration trends"
Security Best Practices
⚠️ Important Security Considerations:
-
Use Read-Only Credentials: Create a dedicated MySQL user with read-only permissions for data analysis tasks
-
Never Commit Credentials: Don't commit the
claude_desktop_config.jsonfile with actual credentials to version control -
Use Environment Variables: For production environments, consider using environment variable substitution
-
Limit Database Access: Only grant access to specific databases that Claude needs to work with
-
Use Strong Passwords: Ensure your MySQL password is strong and unique
-
Enable SSL/TLS: For remote connections, always use SSL/TLS encryption
-
Regular Auditing: Monitor database access logs regularly
Troubleshooting
Connection Issues
Problem: "Cannot connect to MySQL server"
- Verify MySQL server is running:
systemctl status mysql(Linux) or check Services (Windows) - Check host and port are correct
- Ensure firewall allows connections on MySQL port (default 3306)
- Verify credentials are correct
Problem: "Access denied for user"
- Confirm username and password are correct
- Check user has appropriate permissions:
SHOW GRANTS FOR 'your_user'@'localhost'; - Verify user can connect from the specified host
Configuration Issues
Problem: Claude Desktop doesn't show the MySQL server
- Ensure the config file is in the correct location
- Check JSON syntax is valid (use a JSON validator)
- Restart Claude Desktop after making changes
- Check Claude Desktop logs for errors
Performance Issues
Problem: Queries are slow
- Add appropriate indexes to frequently queried columns
- Optimize complex queries
- Consider increasing MySQL connection timeout
- Check database server resources (CPU, memory)
Limitations
- Query Timeout: Long-running queries may timeout (default: 30 seconds)
- Result Size: Large result sets may be truncated
- Write Operations: Currently not supported
- Concurrent Connections: Limited by MySQL server's max_connections setting
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built on the Model Context Protocol
- Powered by Claude by Anthropic
- MySQL connector by mysql2
- Inspired by dpflucas mysql server
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。