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 production-ready Node.js package that provides an MCP (Model Context Protocol) server for converting natural language questions into SQL queries using AI-powered multi-agent systems.
Quick Start
# Install globally
npm install -g nlsql-mcp-server
# Start the server
nlsql-mcp-server start
# Or run directly with npx
npx nlsql-mcp-server startRelated MCP server: MySQL MCP Server
Features
AI-Powered: Converts natural language to SQL using OpenAI and CrewAI
Multi-Database: Supports SQLite, PostgreSQL, and MySQL
Smart Analysis: AI-powered database schema analysis
Easy Installation: One-command setup with automatic Python dependency management
MCP Protocol: Full JSON-RPC implementation compatible with Claude Desktop and other MCP clients
Safe Execution: Query validation and configurable limits
Sample Data: Built-in NBA database for testing
Production Ready: Comprehensive error handling and logging
Prerequisites
Node.js 14+: JavaScript runtime
Python 3.8+: For the underlying MCP server
OpenAI API Key: For natural language processing
Installation
Global Installation (Recommended)
npm install -g nlsql-mcp-serverLocal Installation
npm install nlsql-mcp-serverThe package will automatically:
Detect your Python installation
Install required Python dependencies
Set up the NLSQL MCP server
Verify the installation
Configuration
Environment Setup
# Set your OpenAI API key
export OPENAI_API_KEY="your_api_key_here"
# Or create a .env file
echo "OPENAI_API_KEY=your_api_key_here" > .envClaude Desktop Setup (Step-by-Step)
Step 1: Install the Package
npm install -g nlsql-mcp-serverStep 2: Get Your OpenAI API Key
Go to OpenAI API Keys
Create a new API key
Copy the key (starts with
sk-)
Step 3: Find Your Claude Desktop Config File
On Windows:
Press
Windows + RType
%APPDATA%\ClaudeLook for
claude_desktop_config.json
On Mac:
Open Finder
Press
Cmd + Shift + GType
~/Library/Application Support/ClaudeLook for
claude_desktop_config.json
On Linux:
Open file manager
Go to
~/.config/ClaudeLook for
claude_desktop_config.json
Step 4: Edit the Config File
If the file exists: Open it and add the nlsql configuration to the existing mcpServers section.
If the file doesn't exist: Create a new file called claude_desktop_config.json with this content:
{
"mcpServers": {
"nlsql": {
"command": "npx",
"args": ["nlsql-mcp-server", "start"],
"env": {
"OPENAI_API_KEY": "sk-your-actual-api-key-here"
}
}
}
}Important: Replace sk-your-actual-api-key-here with your real OpenAI API key!
Step 5: Restart Claude Desktop
Completely close Claude Desktop
Open Claude Desktop again
The nlsql server should now be available
Step 6: Test It Works
In Claude Desktop, try asking:
"Connect to the sample database and show me what tables are available"If it works, you'll see Claude connect to the NBA sample database!
Usage
Command Line Interface
# Start the MCP server
nlsql-mcp-server start
# Start with debug mode
nlsql-mcp-server start --debug
# Test the installation
nlsql-mcp-server test
# Install/reinstall Python dependencies
nlsql-mcp-server install-deps
# Generate Claude Desktop config
nlsql-mcp-server config
# Show help
nlsql-mcp-server --helpProgrammatic Usage
const NLSQLMCPServer = require('nlsql-mcp-server');
const server = new NLSQLMCPServer({
debug: true,
pythonExecutable: 'python3',
env: {
OPENAI_API_KEY: 'your_key_here'
}
});
await server.start();Available Tools
When running, the server provides these MCP tools:
Tool | Description |
| Connect to SQLite, PostgreSQL, or MySQL |
| Connect to built-in NBA sample database |
| Convert questions to SQL using AI |
| Execute SQL queries safely |
| AI-powered database schema analysis |
| Get table and column information |
| Validate SQL syntax |
| Get sample data from tables |
| Check database connection status |
| Disconnect from database |
Examples
Claude Desktop Usage
After setting up Claude Desktop integration, you can use natural language to interact with your databases:
Connect to my sample database and show me the schemaConvert this to SQL: "How many teams are in the NBA?"Show me sample data from the team tableAnalyze my database structure and suggest useful queriesSample Database
Test with the built-in NBA database (30 teams, 15 tables with players, games, stats):
Use the connect_sample_database toolThen ask questions like:
"How many teams are in the NBA?" → Returns: 30 teams
"Show me sample data from the team table"
"List teams from California"
"Validate this SQL: SELECT COUNT(*) FROM team"
Testing
# Test the Node.js wrapper
npm test
# Test the underlying Python server
nlsql-mcp-server test
# Test with sample database
nlsql-mcp-server start --debug
# Then use with Claude DesktopTroubleshooting
Common Issues
"Python not found"
# Install Python 3.8+
# On Ubuntu/Debian:
sudo apt update && sudo apt install python3 python3-pip
# On macOS:
brew install python3
# On Windows:
# Download from python.org"Failed to install Python dependencies"
# Manual installation
nlsql-mcp-server install-deps
# Or install manually
pip3 install mcp crewai sqlalchemy pandas openai python-dotenv psycopg2-binary pymysql cryptography"OpenAI API key not found"
# Set environment variable
export OPENAI_API_KEY="your_key_here"
# Or use .env file
echo "OPENAI_API_KEY=your_key_here" > .env"Server won't start"
# Debug mode for detailed logs
nlsql-mcp-server start --debug
# Test installation
nlsql-mcp-server testDebug Mode
Run with debug mode for detailed logging:
nlsql-mcp-server start --debugLog Files
Logs are written to:
Linux/macOS:
~/.config/nlsql-mcp-server/logs/Windows:
%APPDATA%\nlsql-mcp-server\logs\
Integration Examples
VS Code with Continue.dev
Add to your Continue.dev configuration:
{
"mcpServers": {
"nlsql": {
"command": "npx",
"args": ["nlsql-mcp-server", "start"]
}
}
}Custom Applications
const { spawn } = require('child_process');
const mcpServer = spawn('npx', ['nlsql-mcp-server', 'start'], {
stdio: ['pipe', 'pipe', 'pipe'],
env: {
...process.env,
OPENAI_API_KEY: 'your_key_here'
}
});
// Handle MCP protocol communication
mcpServer.stdout.on('data', handleMCPMessage);
mcpServer.stdin.write(JSON.stringify(mcpRequest));Performance
Startup Time: ~2-3 seconds
Database Operations: <1 second (connect, query, validate)
AI Processing: 5-15 seconds (natural language to SQL, schema analysis)
Memory Usage: ~100-200MB
Database Support: SQLite, PostgreSQL, MySQL
Contributing
Fork the repository
Create a feature branch
Make your changes
Run tests:
npm testSubmit a pull request
License
MIT License - see LICENSE file for details.
Credits
Original Python Server: NLSQL MCP Server
Underlying Application: nl2sql
Built with: Model Context Protocol (MCP), CrewAI, OpenAI
Support
Issues: GitHub Issues
Documentation: GitHub Repository
Discussions: GitHub Discussions
Made by