Labsco
MCP SERVER

ChatQL MCP Server

by SyedRazaHasnain

Asks a SQL Server database questions in English — seven tools, schema-aware generation, and a switch that keeps it read-only.

Relational SQL Databases
Summary
The read-only switch is the decision.

Whether this is safe to point at a real database comes down to one setting: SELECT-only mode is a tool the model can toggle, and `get_security_mode_status` is how you check what is in force before asking for anything. Two other things shape the fit — the questions are answered by an OpenAI model, so schema and generated queries leave the machine, and the database side is SQL Server only today.

What it is

An MCP server that turns English questions into SQL against Microsoft SQL Server. It reads your schema first, generates the query with an OpenAI model, validates it, and returns results with the SQL it ran — so the query is reviewable rather than hidden.

What you get
  • A question in English turned into SQL and executed — `execute_natural_language_query`
  • Direct SQL when you already know what you want, with the same validation applied — `execute_direct_sql_query`
  • Schema exploration: every table in the database, one table's details, and a sample of its rows — `list_database_tables`, `get_table_information`, `get_table_sample_data`
  • A read-only switch you can flip from the conversation, and a way to check which mode you are in — `toggle_select_only_mode`, `get_security_mode_status`
  • Result limiting and query validation on every path, so a generated query cannot run unbounded
Requirements

Python 3.8+, a reachable SQL Server (2017+, Express and Azure SQL Database both listed) and the ODBC Driver 17 for SQL Server. Configuration goes in `.env`: `DB_SERVER`, `DB_DATABASE`, `DB_DRIVER`, and `DB_USERNAME` with `DB_PASSWORD` — both left empty for Windows Authentication. Natural-language generation needs an `OPENAI_API_KEY`, with `OPENAI_MODEL` and `OPENAI_MAX_TOKENS` available to tune it. You do not start the server by hand; the AI client launches it. Support is SQL Server only — PostgreSQL, MySQL, SQLite and Oracle are listed as planned.