This MCP (Model Context Protocol) server provides secure database query services through a FastMCP framework. It connects to MySQL databases and offers authentication, permission management, and safe SQL query execution capabilities.
Before using the Text-to-SQL MCP server, you need to install the required dependencies:
pip install -r requirements.txt
The server requires Python 3.10 or higher and depends on the following packages:
1. Environment Variables Setup
Copy the example environment file and configure it with your database connection details:
cp .env.example .env
Edit the .env file with your specific settings:
# Database configuration
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=your_database
# Optional: Server configuration
MCP_HOST=127.0.0.1
MCP_PORT=8000
2. Database Initialization
Initialize your database with the example data:
mysql -u your_username -p your_database < dataset.sql
This will create a sample contracts table with contract information.
To start the MCP server, run:
python mcp_server.py
Upon successful startup, you'll see output similar to:
Authorization=Bearer ...
🚀 Starting MCP Data Query Server...
📍 Address: http://127.0.0.1:8000
📋 Available tools:
- health_check: Health check
- get_user_permissions: Get user permissions
- get_database_tables: Get database tables list
- get_table_structure: Get table structure
- execute_sql_query: Execute SQL query
- generate_sql_from_question: Generate SQL from natural language
- analyze_query_result: Analyze query results
health_checkget_user_permissionsget_database_tablesdata:read_tables permissionget_table_structuretable_name (string): Table namedata:read_tables permissionexecute_sql_querysql_query (string): SQL query statementlimit (int, optional): Maximum number of rows to return, default 100data:read_table_data permissiondata:read_tables: Permission to read table structuresdata:read_table_data: Permission to read table dataTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "text-to-sql-mysql" '{"command":"python","args":["mcp_server.py"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:
{
"mcpServers": {
"text-to-sql-mysql": {
"command": "python",
"args": [
"mcp_server.py"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json2. Add this to your configuration file:
{
"mcpServers": {
"text-to-sql-mysql": {
"command": "python",
"args": [
"mcp_server.py"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect