NLSQL MCP Server
Uses CrewAI for AI-powered multi-agent systems to convert natural language to SQL queries
Supports connecting to and querying MySQL databases with natural language, including schema analysis and query validation
Includes a built-in NBA sample database for testing with player, team, and game statistics
Leverages OpenAI's models for natural language processing and SQL generation
Supports connecting to and querying PostgreSQL databases with natural language, including schema analysis and query validation
Supports connecting to and querying SQLite databases with natural language, including schema analysis and query validation
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@NLSQL MCP Serverconnect to the sample database and show me the top 5 scorers"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
NLSQL MCP Server (Node.js)
A Node.js package that runs an MCP (Model Context Protocol) server for converting natural language questions into SQL using an AI multi-agent system. It works with SQLite, PostgreSQL, and MySQL, and plugs into any MCP client (Claude Desktop, etc.).
Requirements
Node.js 14+
Python 3.10, 3.11, 3.12, or 3.13 — not 3.14. The underlying CrewAI engine does not yet support Python 3.14. The installer auto-detects a compatible interpreter; if you only have 3.14 it will tell you exactly what to install.
OpenAI API key — only for the AI features (
natural_language_to_sql,analyze_schema). Connecting to a database and running/validating SQL needs no key.
Related MCP server: MySQL MCP Server
Install
npm install -g nlsql-mcp-serverThis is the recommended first step before wiring it into any MCP client
(see Claude Desktop). During install, a postinstall
step:
Probes for a compatible Python (
python3.13→3.12→3.11→3.10).Builds a dedicated virtualenv inside the package and installs the Python dependencies into it (a slim runtime set — a few minutes, one time). This is isolated; it does not touch your system Python and is not affected by PEP 668 ("externally-managed-environment").
On success: prints
Setup complete.
If no compatible Python is found, the install still completes but prints instructions, e.g.:
macOS: brew install python@3.13
Ubuntu: sudo apt install python3.13 python3.13-venv
Windows: winget install Python.Python.3.13Install one, then run:
npx nlsql-mcp-server install-deps # (re)builds the virtualenvVerify everything is ready:
nlsql-mcp-server testYou should see the virtualenv and Python dependency checks pass. (The OpenAI
key check will show ❌ until you set OPENAI_API_KEY; that only affects the AI
features.)
How to use it end-to-end
1. Install locally and build the environment
npm install -g nlsql-mcp-server
nlsql-mcp-server test # confirms the venv + deps are ready2. (Optional) Set an OpenAI key for the AI features
Only needed for natural-language → SQL and AI schema analysis:
export OPENAI_API_KEY="sk-your-key"3. Connect to a database
The server exposes tools to connect to your own database or a built-in sample:
Your database:
connect_databasewithdb_type=sqlite|postgresql|mysqlplus the relevant connection fields.Sample database:
connect_sample_databaseconnects to an NBA dataset (30 teams, 15 tables). The ~52 MB SQLite file is downloaded on first use (it is not bundled in the package), then cached locally.
Connecting, inspecting schema, sampling rows, validating and executing SQL all work without an API key.
4. Use it from Claude Desktop (MCP client)
Once installed and warmed up (steps 1–2), point Claude Desktop at it and interact in natural language. Setup below.
Use with Claude Desktop
Important ordering: install and warm the environment first (
npm install -g nlsql-mcp-serverandnlsql-mcp-server test), then add the config below. The first-time Python environment build takes a few minutes and cannot complete inside an MCP client's startup handshake — if you wire it in before the virtualenv exists, the server exits immediately with a message in the MCP client logs telling you to runnpx nlsql-mcp-server install-depsonce in a terminal.
1. Find your Claude Desktop config file
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
2. Add the server
{
"mcpServers": {
"nlsql": {
"command": "npx",
"args": ["nlsql-mcp-server", "start"],
"env": {
"OPENAI_API_KEY": "sk-your-key-here"
}
}
}
}The env block is optional — omit OPENAI_API_KEY if you only need
connect/inspect/validate/execute (no AI). Add it to enable
natural_language_to_sql.
3. Restart Claude Desktop
Fully quit and reopen. Then try:
Connect to the sample database and show me what tables are available.How many teams are in the NBA?Available tools
Tool | Needs OpenAI key? | Description |
| – | Connect to SQLite, PostgreSQL, or MySQL |
| – | Connect to the NBA sample DB (downloaded on first use) |
| – | Tables, columns, relationships |
| – | Sample rows from a table |
| – | Validate SQL syntax |
| – | Execute SQL safely |
| – | Current connection status |
| – | Disconnect |
| ✅ | Convert a question to SQL using AI |
| ✅ | AI-powered schema analysis |
CLI
nlsql-mcp-server start # start the MCP server (stdio)
nlsql-mcp-server start --debug # start with verbose logging
nlsql-mcp-server test # check venv + deps + key
nlsql-mcp-server install-deps # (re)build the Python virtualenv
nlsql-mcp-server config # print a Claude Desktop config snippet
nlsql-mcp-server --helpTroubleshooting
No CrewAI-compatible Python found (need 3.10–3.13)
Your default Python is 3.14 (or none in range). Install a compatible one
(brew install python@3.13, apt install python3.13 python3.13-venv, or
winget install Python.Python.3.13), then run
npx nlsql-mcp-server install-deps.
Claude Desktop shows the server failing immediately
Check the MCP client logs. If it says the Python environment is not built,
run npx nlsql-mcp-server install-deps once in a terminal, wait for it to
finish, then restart Claude Desktop. This happens when the server was wired
in before the one-time environment build completed.
natural_language_to_sql returns a credentials error
OPENAI_API_KEY is not set in the environment the server runs in. For Claude
Desktop, put it in the env block of the config. Other tools work without it.
Reinstall the Python environment from scratch
npx nlsql-mcp-server install-depsThis deletes and rebuilds the package virtualenv.
How it works
MCP client (Claude Desktop)
│ JSON-RPC over stdio
▼
Node wrapper (index.js) ──spawns──► Python MCP server (package virtualenv)
│
▼
nl2sql + CrewAI agents
SQLite / PostgreSQL / MySQLThe Node layer manages the isolated Python virtualenv and process; the Python layer runs the MCP protocol and the SQL/AI logic. The CrewAI engine is pinned to the 0.x line it was built against, and its console/telemetry output is kept off the protocol channel.
Testing
npm test # Node wrapper unit tests
nlsql-mcp-server test # installation / environment checksContributing
Fork the repository
Create a feature branch
Make your changes
Run tests:
npm testSubmit a pull request
License
MIT — see LICENSE.
Credits
Original Python server: NLSQL MCP Server
Underlying application: nl2sql
Built with: Model Context Protocol, CrewAI, OpenAI
Support
Issues: GitHub Issues
Repository: GitHub
Made by Tushar Badhwar
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/tushar-badhwar/nlsql-mcp-server-npm'
If you have feedback or need assistance with the MCP directory API, please join our Discord server