Skip to main content

Standalone MCP server exposing a single sql_generator tool for MySQL-backed natural-language-to-SQL

Project description

mcp-sql-only

A standalone MCP server that exposes a single sql_generator tool.
Give it a natural-language question and your MySQL connection details — it introspects the schema at runtime, generates a validated SELECT query via Azure OpenAI, and optionally executes it.

How it works

question + MySQL creds
        │
        ▼
  schema introspection  ──►  Azure OpenAI  ──►  SQL validator  ──►  (execute)
  1. Connects to your MySQL database and reads the live schema.
  2. Sends the schema + question to Azure OpenAI to generate SQL.
  3. Validates the SQL (SELECT-only policy, table/column whitelist, no dangerous keywords).
  4. Returns the query — or executes it and returns rows.

Required environment variables

Set these before starting the server (in your shell or a .env file in the working directory):

AZURE_OPENAI_API_KEY=your-key
AZURE_OPENAI_ENDPOINT=https://<resource>.openai.azure.com/
AZURE_DEPLOYMENT=your-deployment-name
AZURE_OPENAI_API_VERSION=2024-02-15-preview

Quickstart — run without installing (recommended)

uvx mcp-sql-only

uvx downloads the package from PyPI into a temporary isolated environment and runs it immediately. No global install, no dependency conflicts.

Plug into any MCP-compatible agent

from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent

client = MultiServerMCPClient(
    {
        "sql": {
            "transport": "stdio",
            "command": "uvx",
            "args": ["mcp-sql-only"],
        }
    }
)

tools = await client.get_tools()

agent = create_agent(
    model=model,
    tools=tools,
)

Tool — sql_generator

Parameter Required Default Description
question Natural-language question
host MySQL host
username MySQL user
password MySQL password
database_name Target database
port 3306 MySQL port
table all Restrict query to a single table
max_retries 0 Retry attempts if SQL validation fails
debug false Include internal workflow logs in response

Security

  • SELECT-onlyDROP, DELETE, UPDATE, INSERT, TRUNCATE and other destructive statements are blocked before execution.
  • Schema whitelist — generated SQL is validated against the live schema; unknown tables and columns are rejected.
  • No credential logging — passwords are masked as *** in all server logs.
  • Credentials are never stored — connection details are passed per-call and held only for the duration of that request.

Project structure

server.py           ← MCP server entry point
sql_engine/
  generator.py      ← LLM prompt + SQL generation
  validator.py      ← SELECT-only + whitelist validation
  llm_providers.py  ← Azure OpenAI provider
  tool.py           ← orchestrates generate → validate → execute
  models.py         ← Pydantic input/output contracts
pyproject.toml      ← package metadata + entry point

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_sql_only-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_sql_only-0.1.0-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_sql_only-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_sql_only-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_sql_only-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2475f00e4f84374e68f124a5db6bb6732eb0cd25d5f0861dc5b4fc3351186fb4
MD5 8d580c7af00721081b3dd29d9014a69f
BLAKE2b-256 94aa1d4528ea09b30d0e5b565293f8d50e6cad423672e5f7d52625eb86eafc78

See more details on using hashes here.

File details

Details for the file mcp_sql_only-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_sql_only-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_sql_only-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 884618a62dc9cc2672e7ee21a07cf1e0339066f1583191af0bf9001704325e8f
MD5 64468befe55bd91f741e3a6021767084
BLAKE2b-256 f458f17e870d31979365a5f2cc0a43c48c7d93491b4b1ea546b19909449d9be1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page