Text-to-SQL

一个基于 FastMCP 框架的安全数据库查询 MCP 服务,用于数据库查询和分析。
  • python

14

GitHub Stars

python

Language

6 months ago

First Indexed

2 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "tmstack-text-to-sql-mcp-server": {
      "command": "python",
      "args": [
        "mcp_server.py"
      ],
      "env": {
        "DB_HOST": "localhost",
        "DB_NAME": "YOUR_DATABASE",
        "DB_PORT": "3306",
        "DB_USER": "YOUR_USERNAME",
        "MCP_HOST": "127.0.0.1",
        "MCP_PORT": "8000",
        "DB_PASSWORD": "YOUR_PASSWORD"
      }
    }
  }
}

You have a secure Text-to-SQL MCP Server that lets you query and analyze a MySQL database safely. It handles authentication, SQL safety checks, table discovery, and controlled SQL execution so you can build data insights without exposing your database to risky queries.

How to use

After you start the server, you can interact with it using an MCP client to run safe SQL queries, inspect tables, and analyze results. The server exposes tools for health checks, permission retrieval, table listing, table structure queries, SQL execution with safety limits, and natural language to SQL capabilities. Use your access token to authenticate and request the actions you need.

How to install

Prerequisites you need before installing: Python 3.10 or newer and a MySQL database you can connect to.

# 1) Install dependencies
pip install -r requirements.txt

# 2) Prepare environment
cp .env.example .env

Configure the database connection in the .env file to point at your MySQL instance. Then initialize sample data using the provided SQL file.

# 3) Edit environment variables in .env
# DB_HOST=localhost
# DB_PORT=3306
# DB_USER=your_username
# DB_PASSWORD=your_password
# DB_NAME=your_database
# Optional: MCP server binding
# MCP_HOST=127.0.0.1
# MCP_PORT=8000

# 4) Initialize sample data
mysql -u your_username -p your_database < dataset.sql

Finally, start the MCP server with Python.

python mcp_server.py

Additional sections

Configuration, security, and ongoing operation are covered here to help you run securely and reliably.

Available tools

health_check

Checks the health status of the MCP server and the database connection.

get_user_permissions

Retrieves the current user's permissions based on the provided access token.

get_database_tables

Lists all tables in the connected database.

get_table_structure

Fetches the structure of a specified table, including row count and sample data.

execute_sql_query

Executes a safe SQL query with optional result limit; prohibits modifying statements like DROP/DELETE/UPDATE/INSERT.

generate_sql_from_question

Converts natural language questions into SQL queries.

analyze_query_result

Analyzes and summarizes the results of a SQL query.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational