nlp-database
Connect your LLMs to SQL databases safely and intuitively using the Model Context Protocol (MCP).
claude mcp add --transport stdio lisito11-nlp-database-mcp python C:/path/to/nlp_database.py \ --env DATABASE_URL="postgresql://user:pass@localhost:5432/dbname"
How to use
NLP Database MCP Server provides a read-only bridge that lets AI agents explore database schemas and execute safe queries via the Model Context Protocol (MCP). It exposes two primary tools: get_schema, which returns a list of tables, columns, and data types, and execute_query, which runs a restricted SELECT (and WITH) query with an automatic LIMIT 500 to prevent overuse. To use it, configure your MCP client to point to this server (for example, via the Python script that powers the MCP server) and supply a DATABASE_URL that connects to your target database. Once connected, the agent can first call get_schema to understand table structures, then generate a sanitized SELECT query and call execute_query to obtain results in JSON. The responses are crafted to be understandable by humans, with descriptions in plain English or Spanish as needed.
How to install
Prerequisites:
- Python 3.8+ installed on your system
- Access to the target database with a valid connection string
- Network access from the MCP client to the database host
Step-by-step installation:
- Clone or download the repository containing the NLP Database MCP server.
- Create and activate a virtual environment (recommended):
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
- Install dependencies from requirements.txt:
pip install -r requirements.txt
- Install necessary database drivers (choose only the ones you need):
- PostgreSQL:
pip install psycopg2-binary - MySQL:
pip install pymysql - SQL Server:
pip install pyodbc - SQLite is included with Python
5) Prepare the environment variable for the database URL when running the server, for example:
```bash
export DATABASE_URL="postgresql://user:pass@localhost:5432/dbname"
# or on Windows:
set DATABASE_URL=postgresql://user:pass@localhost:5432/dbname
- Run the MCP server using the configured command (example):
python C:/path/to/nlp_database.py
Notes:
- Ensure the database user has read-only privileges on the required schema.
- The server enforces safe query patterns (only SELECT and WITH) and applies LIMIT 500 automatically.
Additional notes
Tips and common issues:
- Always use a restricted read-only database user to improve security.
- Set DATABASE_URL to the correct driver for your database (PostgreSQL, MySQL, SQL Server, or SQLite).
- If you encounter connection errors, verify network access and that the database host/port are reachable from the MCP client environment.
- You can adjust runtime behavior via environment variables like MAX_RESULT_ROWS (default 500) and QUERY_TIMEOUT (seconds).
- The server caches schemas for up to 5 minutes to reduce overhead; ensure your schema changes are reflected after a cache refresh interval if needed.
Related MCP Servers
mcp-redis
The official Redis MCP Server is a natural language interface designed for agentic applications to manage and search data in Redis efficiently
mcp-aktools
📈 提供股票、加密货币的数据查询和分析功能MCP服务器
turbular
A MCP server allowing LLM agents to easily connect and retrieve data from any database
packt-netops-ai-workshop
🔧 Build Intelligent Networks with AI
lmstudio-toolpack
A MCP stdio toolpack for local LLMs
alris
Alris is an AI automation tool that transforms natural language commands into task execution.