General-Purpose Database MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add general-database-mcp -- docker run -p 8008:8008 -e DATABASE_URL=postgresql://user:password@host:5432/database -e MCP_TRANSPORT=http general-database-mcp
README.md

Provides LLMs with full PostgreSQL database access and schema management.

General-Purpose MCP Database Server (Python)

A Model Context Protocol (MCP) server that provides LLMs with generic database access capabilities for PostgreSQL databases. Built with Python and FastMCP.

Features

  • Query Tools: Execute SELECT queries, write operations (INSERT/UPDATE/DELETE), and export data
  • Schema Management: Create, alter, and drop tables, list tables, describe table schemas
  • Insights: Store and retrieve business insights in a dedicated memo table
  • Connection Pooling: Efficient database connection management
  • Docker Support: Easy containerized deployment
  • Flexible Configuration: Support for DATABASE_URL or individual connection parameters
  • Multiple Transport Modes: stdio (local) or SSE (HTTP for remote deployment)

Installation

Local Development

  1. Clone or navigate to the repository:
cd general-database-mcp-python
  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment variables:
cp .env.example .env
# Edit .env with your database credentials
  1. Run the server:
python main.py

Docker Deployment

  1. Build the Docker image:
docker build -t general-database-mcp .
  1. Run the container:
docker run -p 8008:8008 \
  -e DATABASE_URL="postgresql://user:password@host:5432/database" \
  -e MCP_TRANSPORT=http \
  general-database-mcp

Configuration

Environment Variables

Database Configuration (choose one option):

Option 1: DATABASE_URL (recommended)

DATABASE_URL=postgresql://user:password@host:5432/database

Option 2: Individual parameters

DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_database
DB_USER=your_username
DB_PASSWORD=your_password

Server Configuration:

PORT=8008
MCP_TRANSPORT=stdio  # Options: stdio (local) or http (remote)
API_KEY=your_secret_key  # Optional: for authentication

Available Tools

Query Tools

`read_query`

Execute SELECT queries to read data from the database.

  • Parameters: query (string) - SQL SELECT statement
  • Returns: Query results as JSON
`write_query`

Execute INSERT, UPDATE, or DELETE queries to modify data.

  • Parameters: query (string) - SQL modification statement
  • Returns: Number of affected rows
`export_query`

Execute a SELECT query and export results in CSV or JSON format.

  • Parameters:
    • query (string) - SQL SELECT statement
    • format (string) - "csv" or "json" (default: "json")
  • Returns: Formatted query results

Schema Management Tools

`create_table`

Create new tables in the database.

  • Parameters: query (string) - CREATE TABLE statement
  • Returns: Success status
`alter_table`

Modify existing table schema (add columns, rename, etc.).

  • Parameters: query (string) - ALTER TABLE statement
  • Returns: Success status
`drop_table`

Remove a table from the database with safety confirmation.

  • Parameters:
    • table_name (string) - Name of table to drop
    • confirm (boolean) - Must be True to proceed
  • Returns: Success status
`list_tables`

Get a list of all tables in the database.

  • Parameters: None
  • Returns: Array of table names
`describe_table`

View schema information for a specific table.

  • Parameters: table_name (string) - Name of table
  • Returns: Column definitions with types, constraints, etc.

Insights Tools

`append_insight`

Add a business insight to the memo table.

  • Parameters: insight (string) - Text of the insight
  • Returns: Success status
`list_insights`

List all business insights stored in the memo table.

  • Parameters: None
  • Returns: Array of insights with timestamps

Monitoring

`health_check`

Health check endpoint for monitoring and deployment verification.

  • Parameters: None
  • Returns: Server status and database connection info

Usage Examples

Using with Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "database": {
      "command": "python",
      "args": [
        "/absolute/path/to/general-database-mcp-python/main.py"
      ],
      "env": {
        "DATABASE_URL": "postgresql://user:password@localhost:5432/mydb"
      }
    }
  }
}

Example Prompts for Claude

Query data:

Show me all tables in the database.
Describe the structure of the users table.
Select all records from the products table where price > 100.

Modify data:

Insert a new user with name 'John Doe' and email 'john@example.com'.
Update all products in the 'Elect

Tools (11)

read_queryExecute SELECT queries to read data from the database.
write_queryExecute INSERT, UPDATE, or DELETE queries to modify data.
export_queryExecute a SELECT query and export results in CSV or JSON format.
create_tableCreate new tables in the database.
alter_tableModify existing table schema.
drop_tableRemove a table from the database with safety confirmation.
list_tablesGet a list of all tables in the database.
describe_tableView schema information for a specific table.
append_insightAdd a business insight to the memo table.
list_insightsList all business insights stored in the memo table.
health_checkHealth check endpoint for monitoring and deployment verification.

Environment Variables

DATABASE_URLPostgreSQL connection string
DB_HOSTDatabase host address
DB_PORTDatabase port
DB_NAMEDatabase name
DB_USERDatabase username
DB_PASSWORDDatabase password
PORTServer port
MCP_TRANSPORTTransport mode: stdio or http
API_KEYOptional authentication key

Configuration

claude_desktop_config.json
{"mcpServers": {"database": {"command": "python", "args": ["/absolute/path/to/general-database-mcp-python/main.py"], "env": {"DATABASE_URL": "postgresql://user:password@localhost:5432/mydb"}}}}

Try it

List all tables in the database to understand the schema.
Describe the structure of the users table.
Select all records from the products table where price is greater than 100.
Insert a new user with name 'John Doe' and email 'john@example.com'.
List all stored business insights.

Frequently Asked Questions

What are the key features of General-Purpose Database MCP?

Execute complex SQL SELECT, INSERT, UPDATE, and DELETE queries. Full schema management including creating, altering, and dropping tables. Dedicated insights system for storing and retrieving business memos. Supports both local stdio and remote HTTP transport modes. Built-in health check and connection pooling for reliable database access.

What can I use General-Purpose Database MCP for?

Allowing LLMs to perform data analysis directly on production or staging databases. Automating database schema updates and migrations via natural language. Maintaining a searchable knowledge base of business insights within a SQL table. Generating CSV or JSON reports from database queries for external use.

How do I install General-Purpose Database MCP?

Install General-Purpose Database MCP by running: python main.py

What MCP clients work with General-Purpose Database MCP?

General-Purpose Database MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep General-Purpose Database MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare