MCP Databases Server

Provides safe relational database operations as MCP tools with multi-layer protection against SQL injection and malicious queries.
  • python

0

GitHub Stars

python

Language

7 months ago

First Indexed

3 months ago

Catalog Refreshed

Documentation & install

Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.

Installation

Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "fean-developer-mcp-databases": {
      "command": ".mcpenv/bin/python",
      "args": [
        "server.py"
      ]
    }
  }
}

You deploy a Python MCP Server that exposes relational database operations (SQL Server, MySQL, PostgreSQL) as safe MCP tools. It is designed to protect against SQL injection, validate all queries, and configure automatically from .env files to help you build secure AI-assisted data workflows.

How to use

You interact with the MCP server through an MCP client. Start by ensuring your environment is running the server, then configure your client to connect to the local stdio MCP endpoint or to a globally available MCP command. Use the available tools to perform safe data queries, define schema changes, and perform controlled data manipulation. Any destructive operation or potentially dangerous command requires explicit confirmation and default safety limits to be in effect.

Typical usage patterns include listing tables, reading data through read-only queries, and performing parameterized inserts or updates within defined safety limits. Always prefer parameterized inputs for all values and respect the built-in protections that block dangerous commands or injections. When you need to modify structure or delete data, you must provide explicit confirmation and stay within configured safety thresholds.

How to install

Prerequisites you need before installing the MCP server are: Python 3.10 or newer and an internet connection to install dependencies.

# Prerequisites
python3 --version
# If needed, install Python 3.10+

# 1) Create and activate a virtual environment for local setup
python3 -m venv .mcpenv
source .mcpenv/bin/activate

# 2) Install dependencies
pip install -r requirements.txt
pip install .
```,

Configuration and startup notes

The server automatically searches for environment configuration in a .env file at the project root, then in subdirectories (config/, db/, local/, etc.), and finally prompts you if needed. You must provide the following mandatory variables: DB_TYPE, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME. Without proper configuration, the system will not run.

Example of a .env file for different databases is shown below. Use the section that matches your database type and fill in your actual connection details.

# PostgreSQL
DB_TYPE=postgres
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USER=admin
DB_PASSWORD=your_password
DB_NAME=your_db

# MySQL
DB_TYPE=mysql
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASSWORD=your_password
DB_NAME=your_db

# SQL Server
DB_TYPE=mssql
DB_HOST=localhost
DB_PORT=1433
DB_USER=sa
DB_PASSWORD=your_password
DB_NAME=your_db

Generating the MCP configuration file mcp.json

Create a configuration file that registers the MCP server for your client tooling. You can configure a local stdio server that runs from a virtual environment and points to the server script, or a global stdio server that is installed system-wide.

{
  "servers": {
    "databases_local": {
      "type": "stdio",
      "command": ".mcpenv/bin/python",
      "args": ["server.py"]
    }
  }
}

If you install globally with a tool like pipx, you can register a second stdio server that uses the installed MCP package binary and lists the available tools. This example shows the structure you would use, and you may adapt the command and arguments to your environment.

{
  "servers": {
    "databases_global": {
      "transport": "stdio",
      "command": "/home/%USER%/.local/bin/mcp-databases",
      "tools": [
        "execute_query",
        "list_tables",
        "expose_schema",
        "insert_record",
        "create_table",
        "alter_table",
        "drop_table",
        "update_records",
        "delete_records",
        "bulk_insert",
        "security_check",
        "get_security_config",
        "safe_query_prompt"
      ]
    }
  }
}

Security and safety reminders

Commands that could compromise data integrity are blocked automatically. These include dangerous SQL statements and common attack vectors. All parameter values are sanitized, and destructive operations require exact confirmation. You must always provide the required configuration to run the server.

Key protections include mandatory parameters, multi-layer validation (tool → database → prompt → config), parameterized queries, and strict name validation for tables and columns.

Be aware of limits and confirmations for operations that alter data or database structure. For example, drop_table and delete_records require explicit confirmation patterns, and bulk_insert has a maximum row count per operation.

Troubleshooting and notes

If configuration is incomplete or you encounter startup issues, recheck your .env file for the required variables and ensure your Python environment is active. Reinstall dependencies if you update the codebase.

If you are using VS Code, you can connect to the MCP server via the MCP Servers extension and interact using the available tools.

Available tools

execute_query

Executes read-only SELECT queries with security validation

list_tables

Lists all tables in the connected database

expose_schema

Exposes the full database schema

create_table

Creates tables with strict name and type validation

alter_table

Alters table structures (ADD, MODIFY, DROP COLUMN)

drop_table

Removes tables but requires double confirmation

insert_record

Inserts a single record with safe parameters

bulk_insert

Inserts multiple records with safety limits

update_records

Updates records with parameters and configurable safety limits

delete_records

Deletes records and requires confirmation and safety checks

security_check

Checks a query for safety without executing it

get_security_config

Shows active security configurations

safe_query_prompt

Adds an extra validation step for dangerous queries

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational