Skip to main content
Glama
Denuwanhh

SQL Generative MCP

by Denuwanhh

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.


Related MCP server: PostgreSQL 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>

Available Tools

1 tool
query_databaseB

Run a plain-English natural language query against the connected database and return the result as structured XML.

ParametersJSON Schema
NameRequiredDescriptionDefault
user_queryYesThe database query request in plain English (e.g. 'Show a list of all expense items').

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

B3.4/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions returning structured XML but fails to disclose whether the query modifies data, requires authentication, or the database state. Behavioral traits like read-only nature or error handling are not addressed.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence that front-loads the purpose. Every word is necessary, and there is no redundancy or wasted text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and sibling tools, the description is insufficient. It does not address important context such as query timeout, security considerations, or the nature of the output schema. The presence of an output schema is noted but not explained.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with the parameter `user_query` fully described in the schema including an example. The description does not add significant semantic value beyond what the schema already provides, so a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool runs a plain-English natural language query against a database and returns structured XML. The verb 'run' and resource 'database query' are specific, and the output format is explicitly mentioned. Without siblings, no differentiation needed.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool versus alternatives. Since there are no sibling tools, the lack of alternatives is less critical, but there is no mention of prerequisites or limitations (e.g., database connection status). Usage is implied from the description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 1 tool updatev0.1.0
    • First observedquery_database

TDQS

A3.5/5.0
Disambiguation5/5

Only one tool exists, so there is no possibility of confusion with other tools.

Naming Consistency5/5

The single tool name, 'query_database', follows a clear verb_noun pattern, and consistency is trivially maintained with one tool.

Tool Count3/5

With only one tool, the server feels thin for a database interaction service, though it may suffice as a single natural language query endpoint.

Completeness2/5

The server only provides querying, lacking common database operations like schema inspection, data modification, or DDL, leaving significant gaps in typical database workflows.

Maintenance

ActivityStale
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    A
    maintenance
    Enables read-only interaction with PostgreSQL databases through natural language queries, supporting dynamic connections and secure query validation.
    3
    125
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables secure, read-only PostgreSQL database interaction through natural language, with automatic database discovery and connection management.
    2
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Converts natural language to safe SQL queries for PostgreSQL databases with read-only access and multi-layer security validation. Provides tools for running validated SELECT queries, retrieving schema, and sampling table data.
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables read-only interaction with PostgreSQL databases, allowing natural language queries for listing schemas, tables, describing columns, and executing SELECT/WITH statements.
    83
    MIT

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/Denuwanhh/sql-generative-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server