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 langchain.agents import create_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.1.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.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_sql_only-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 53f3f07826b22cd3ef76c49378f3a5241731d142f7724de79e480944b4fb8a54
MD5 d47afb4b9cd166724ff2a77eff76809f
BLAKE2b-256 45803b2f0cdd22cd201cdf955dafa8c3990f38b3429951e823c042fd49d16bf0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcp_sql_only-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32f5c897646384c6131b5b3bc891e8c2326cf2ba3a31ddd60d61cbfeefe0a93a
MD5 9aef5e227b04437d6b0f748cc4843746
BLAKE2b-256 56ab93f95dfe80bd684e9cc50ecab4e2b5b71e71e2ec182c5f7d49d99ea14aaf

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