Get the FREE Ultimate OpenClaw Setup Guide →

nlp-database

Connect your LLMs to SQL databases safely and intuitively using the Model Context Protocol (MCP).

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Clone or download the repository containing the NLP Database MCP server.
  2. Create and activate a virtual environment (recommended):
python -m venv venv
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate
  1. Install dependencies from requirements.txt:
pip install -r requirements.txt
  1. 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
  1. 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

Sponsor this space

Reach thousands of developers