SQL Generative MCP

SQL Generative MCP

Enables natural language querying of PostgreSQL databases under read-only mode, returning results as structured XML.

Category
Visit Server

README

SQL Generative MCP

An interactive Model Context Protocol (MCP) server that translates plain English queries into SQLAlchemy operations, queries a PostgreSQL database under strict read-only execution modes, and returns the query results formatted as structured XML.


🌟 Key Features

  • Natural Language DB Querying: Translate user queries in plain English to corresponding database results dynamically.
  • SQLAlchemy Table Reflection: Reflects database schemas dynamically across multiple namespaces using standard ORM capabilities (no direct pg_dump client tools needed).
  • Enforced Read-Only Transactions: Database URL connections are injected with query options (?options=-c%20default_transaction_read_only%3Don) to natively block any modifications (CREATE, UPDATE, DELETE, DROP) at the database engine level.
  • Dynamic XML Response Formatting: Converts database records into a clean, well-formed XML structure automatically compiled by Claude.
  • FastMCP Protocol Integration: Built on top of the standard fastmcp SDK to run as a local stdio MCP server.

🏗️ Architecture

Architecture Diagram


🛠️ Setup & Installation

Prerequisites

  • Python 3.13+
  • uv (fast Python package installer and resolver)
  • PostgreSQL Server with an active database

1. Project Initialization & Dependencies

Initialize the project environment and install dependencies:

uv sync

2. Environment Configuration

Create a .env file in the root directory and configure the database URL along with your Anthropic API key:

# Database connection for local development (enforced read-only mode via query options)
DATABASE_URL=postgresql://postgres:admin@localhost:5432/expence_db?options=-c%20default_transaction_read_only%3Don

# Anthropic API Key
ANTHROPIC_API_KEY="your-anthropic-api-key-here"

🚀 Running the Server

Start the stdio-based MCP server locally:

uv run python main.py

🔌 Integration with Claude Desktop

To configure Claude Desktop to use this database query tool on Windows, configure your claude_desktop_config.json file.

  1. Press Win + R, type %APPDATA%\Claude and press Enter.
  2. Open claude_desktop_config.json and insert the following server config:
{
  "mcpServers": {
    "db-query-server": {
      "command": "uv",
      "args": [
        "--directory",
        "c:/Projects/generative-tool",
        "run",
        "python",
        "main.py"
      ]
    }
  }
}
  1. Restart Claude Desktop. You will see the tools icon 🔌 in the chat input area.

📈 Usage Examples

Once connected, you can ask Claude queries like:

  • "Show a list of all tables in the database"
  • "How many expense entries are recorded for AWS?"
  • "Show a list of all rows in table exp_expence_core_t"

The server returns results formatted as well-formed XML:

<data>
  <item>
    <exp_expence_core_id>26</exp_expence_core_id>
    <title>AWS Bill</title>
    <amount>100.00</amount>
  </item>
</data>

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured