MCP Database Server
A Model Context Protocol (MCP) server implementation in Python that provides strictly read-only access to databases. It allows Large Language Models (LLMs) to inspect schemas and query data safely without risking data modification.
Features
- 🛡️ Strict Read-Only: Enforced at the driver level (e.g., SQLite
?mode=ro) or session level (MySQLSET SESSION TRANSACTION READ ONLY). - 🏗️ Repository Pattern: Abstracted database access allows for easy extension to other backends (PostgreSQL, MySQL) via Dependency Injection.
- ⚡ FastMCP: Built efficiently using the official MCP Python SDK.
- 🔌 Connection Pooling: Automatic connection pooling for MySQL using
DBUtilsto ensure performance and reliability. - 🔧 Easy Configuration: Managed via environment variables and Makefiles.
Project Structure
mcp_db_server/: Main Python package for the MCP server.__init__.py: Entry point and server initialization.db/: Repository implementations (sqlite_repository.py,mysql_repository.py).
seed.py: Utility script to populate the database (write access).Makefile: Automation for common tasks.pyproject.toml: Package configuration and dependencies.
Quick Start
Prerequisites
- Python 3.12+ (managed via
venv) make(optional, but recommended)- MySQL Server (optional, if using MySQL backend)
1. Setup
Use the Makefile to create a virtual environment, install dependencies, and seed a test database:
make setup
This runs pip install -r requirements.txt and python seed.py.
2. Configuration
The project uses python-dotenv. Copy the example config and adjust as needed:
cp .env.example .env
Key Variables:
DB_ENGINE:sqlite(Default) ormysqlDB_ADDRESS: Path to db file (SQLite) or Host URL (MySQL).DB_PORT: Database port (Default: 3306 for MySQL).DB_USER/DB_PASSWORD: Database credentials (required for MySQL).DB_SCHEMA: Database name (required for MySQL).
3. Run the Server
Start the MCP server:
make run
(Or directly via venv/bin/python server.py)
Usage with LLMs
Once running, the server exposes the following tools to connected MCP clients:
list_tables()- Returns a list of all tables in the database.
describe_table(table_name: str)- Returns the schema (columns, types, primary keys) for the specified table.
read_query(query: str)- Executes a SQL
SELECTquery. - Note: Queries attempting to modify data will raise a
Security ErrororOperationalError.
- Executes a SQL
Development
Running Tests
Execute the unit test suite:
make test
Extending
To add support for a new database (e.g., Postgres):
- Create
db/postgres_repository.pyimplementation ofDatabaseRepository. - Update
server.pyto instantiate it whenDB_ENGINE=postgres.
Metadata
Release files for mcp-db-server 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcp_db_server-0.1.3.tar.gz | 5.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_db_server-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.2 kB
Release files / mcp_db_server-0.1.3.tar.gz
| Download URL | mcp_db_server-0.1.3.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3d50a62725c79cf46c4030ef4c434201940fc2b797fe9cdd3d5069d90454aff
|
|
BLAKE2b-256 checksum How to use checksums |
f4679c33cf7cbd4d74700da0e8a22691b373163ea083cb2a4e08803dcb49c6b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 6, 2026.
Transparency logRelease files / mcp_db_server-0.1.3-py3-none-any.whl
| Download URL | mcp_db_server-0.1.3-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49fd9cd9e293db21641e81d769864b632fd78f4e6b266c54483fe744d3cce9d3
|
|
BLAKE2b-256 checksum How to use checksums |
f17ab46f090875e7e8084a7f7e98aadcddf33e677a5d13e2c7c1f1b022076c6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 6, 2026.
Transparency logSecurity for mcp-db-server 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for mcp_db_server-0.1.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.