simple-db-mcp
The server provides a read-only MCP interface for safely inspecting and querying PostgreSQL and MySQL databases. Key capabilities include:
Health & status:
healthchecks server health and non-sensitive config;versionreturns server name and version.Connectivity:
ping_databaseverifies the database connection.Schema discovery:
list_schemaslists schemas/databases;list_tableslists tables/views in a schema.Table details:
describe_tableshows column names, types, nullability, defaults, and keys.Read-only queries:
execute_queryruns SQL with a row limit, enforcing read-only mode.Query plans:
explain_queryreturns the execution plan for read-only queries.
All tools accept an optional database argument for multi-connection setups (configured via TOML). Safety is prioritized: read-only by default, mutation rejection, timeouts, row limits, and no credential exposure. The server supports stdio and HTTP transports, configurable via environment variables or TOML files.
Allows querying MySQL databases with read-only SQL execution, schema and table inspection, and query plan explanations.
Allows querying PostgreSQL databases with read-only SQL execution, schema and table inspection, and query plan explanations.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@simple-db-mcp describe the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
simple-db-mcp
A small Python MCP server for querying relational databases from MCP-compatible clients. The server is built with FastMCP and supports PostgreSQL and MySQL.
Goals
Provide a simple MCP interface for common database inspection and query tasks.
Support PostgreSQL and MySQL from the first working version.
Keep database access safe by default, with read-only query execution as the default operating mode.
Use clear configuration so the server can run locally through stdio or be deployed later over HTTP.
Keep the codebase small, typed, tested, and easy to extend.
Related MCP server: mcp-database
Non-goals
Replacing a database admin tool.
Providing migrations, backups, replication, or schema editing in the MVP.
Exposing unrestricted write access by default.
Implementing database-specific SQL parsing from scratch.
Tool Overview
The server exposes a small, predictable MCP tool surface:
Tool | Purpose |
| Return server health and non-sensitive configuration. |
| Verify that the configured database connection works. |
| List available schemas or databases, depending on backend. |
| List tables and views for a schema. |
| Return columns, types, nullability, defaults, and key metadata. |
| Run a read-only SQL query with a row limit. |
| Return the database query plan for a read-only query. |
| Return the server name and package version. |
Database Support
The project should use SQLAlchemy as the database abstraction layer while keeping backend-specific behavior isolated where needed.
Planned drivers:
PostgreSQL:
asyncpgMySQL:
asyncmy
The current connection layer validates SQLAlchemy async URLs that use
postgresql+asyncpg or mysql+asyncmy, creates async engines lazily, and
disposes them through an explicit async close method.
Current introspection defaults:
PostgreSQL table tools default to the
publicschema.MySQL table tools default to the database name in the connection URL.
A schema can be supplied explicitly for table listing and table description.
When multiple databases are configured, database tools require the
databaseargument.
Example connection URLs:
postgresql+asyncpg://user:password@localhost:5432/app
mysql+asyncmy://user:password@localhost:3306/appQuick Start
Install dependencies:
uv syncRun tests:
uv run pytestShow CLI options:
uv run simple-db-mcp --helpStart the server with the default stdio transport:
SIMPLE_DB_MCP_DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/app \
uv run simple-db-mcpRun through the FastMCP CLI:
uv run fastmcp run src/simple_db_mcp/server.py --project .For HTTP deployments, use FastMCP's streamable HTTP transport:
uv run simple-db-mcp --transport http --host 127.0.0.1 --port 8000Configuration
For one database, use environment variables:
SIMPLE_DB_MCP_DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/app
SIMPLE_DB_MCP_QUERY_TIMEOUT_SECONDS=30
SIMPLE_DB_MCP_MAX_ROWS=100
SIMPLE_DB_MCP_READ_ONLY=trueThe server automatically loads a .env file from the current working directory,
or the nearest parent directory, before reading environment variables. Values
already set in the process environment are not overwritten.
The current health tool reports whether a database URL is configured, but it does not expose the URL or credentials.
execute_query uses SIMPLE_DB_MCP_MAX_ROWS as a hard cap. Tool callers may
request a lower limit, but not a higher effective limit.
For multiple named connections, use a TOML file:
[[databases]]
name = "warehouse"
url = "postgresql+asyncpg://user:password@localhost:5432/warehouse"
query_timeout_seconds = 30
read_only = true
max_rows = 500
[[databases]]
name = "app"
url = "mysql+asyncmy://user:password@localhost:3306/app"
query_timeout_seconds = 30
read_only = true
max_rows = 100Then point the server at it:
SIMPLE_DB_MCP_CONFIG_FILE=examples/simple-db-mcp.toml uv run simple-db-mcpSee examples/simple-db-mcp.toml.
With a single configured database, tool calls do not need a database argument.
With multiple configured databases, pass the connection name:
{
"database": "warehouse",
"sql": "select * from orders limit 10"
}MCP Client Configuration
For stdio-based MCP clients, point the client at uv and run this package from
the repository directory. Use an absolute path for --directory:
{
"mcpServers": {
"simple-db-mcp": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/simple-db-mcp",
"run",
"simple-db-mcp"
]
}
}
}With that setup, place the SIMPLE_DB_MCP_* variables in
/absolute/path/to/simple-db-mcp/.env, or keep using the MCP client's env
object if you prefer all configuration to live in the client file.
For multiple databases, use SIMPLE_DB_MCP_CONFIG_FILE instead of
SIMPLE_DB_MCP_DATABASE_URL:
{
"mcpServers": {
"simple-db-mcp": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/simple-db-mcp",
"run",
"simple-db-mcp"
],
"env": {
"SIMPLE_DB_MCP_CONFIG_FILE": "/path/to/simple-db-mcp.toml"
}
}
}
}Tool Reference
All database tools accept an optional database argument. It is only required
when multiple named connections are configured.
ping_database(database = null)list_schemas(database = null)list_tables(schema = null, database = null)describe_table(table, schema = null, database = null)execute_query(sql, limit = null, database = null)explain_query(sql, database = null)
Development
Useful local commands:
uv sync
uv run pytest
uv run ruff check .
uv run mypy src
uv buildThe phased development plan lives in docs/development-plan.md.
Safety Model
Database MCP servers can expose sensitive data, so the default behavior should be conservative:
Read-only mode enabled by default.
Reject obvious mutation statements in
execute_query.Apply a row limit even if the query omits
LIMIT.Enforce query timeout settings.
Avoid logging credentials.
Return concise error messages to clients while keeping debug details in local logs.
Avoid returning raw database URLs or driver exception messages from connection failures.
Document that users should create least-privilege database accounts for this server.
The initial SQL safety checks do not need to be perfect SQL parsers, but the
server should rely on database permissions as the final safety boundary.
The current application check allows obvious read-only statements such as
SELECT, WITH, SHOW, DESCRIBE, and DESC, rejects multiple statements,
and blocks common mutation/control keywords before the query is sent.
explain_query applies the same read-only checks before wrapping the query in
backend-specific EXPLAIN syntax.
See docs/database-users.md for read-only PostgreSQL and MySQL grant examples.
Packaging
Packaging uses Hatchling through pyproject.toml.
Build local distributions:
uv buildRelease checklist and versioning notes live in docs/releasing.md.
Dependencies
Runtime:
fastmcpsqlalchemyasyncpgasyncmytomlion Python 3.10
Development:
pytestpytest-asyncioruffmypy
License
TBD.
Available Tools
8 toolsdescribe_tableB
Describe columns and primary key metadata for a table.
Inputs: table (required), schema, database. Returns: object
execute_queryB
Execute a read-only SQL query with a configured row limit.
Inputs: sql (required), limit, database. Returns: object
explain_queryB
Return the database query plan for a read-only SQL query.
Inputs: sql (required), database. Returns: object
healthA
Return basic server health and non-sensitive configuration.
Inputs: no named parameters. Returns: object
list_schemasC
List available database schemas.
Inputs: database. Returns: object
list_tablesA
List tables and views in a schema.
Inputs: schema, database. Returns: object
ping_databaseB
Verify that the configured database connection works.
Inputs: database. Returns: object
versionA
Return the server name and version.
Inputs: no named parameters. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
The tools are mostly distinct: list_schemas, list_tables, describe_table, execute_query, and explain_query each target a different aspect of database exploration. The health, version, and ping_database tools have overlapping purposes around server status, but their descriptions clarify the differences, so only minor confusion is possible.
Most tool names follow a clear verb_noun pattern (list_schemas, ping_database, execute_query). However, 'health' and 'version' are bare nouns, deviating from the otherwise consistent style. The underscore convention is uniform throughout, keeping the naming readable.
With 8 tools, the server is well-scoped for a simple database MCP. Each tool covers a necessary function—server diagnostics, schema/table introspection, and query execution/planning—without unnecessary bloat or skimping.
For a read-only database tool, the surface is complete: users can discover schemas, explore tables and columns, run queries, and inspect query plans. Health and version cover server metadata. No obvious gaps exist for the intended read-only scope.
Maintenance
Related MCP Connectors
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
An MCP server that provides read access to your cloud storage providers, bank accounts and more.
Hosted MCP server for PostgreSQL diagnostics: slow queries, missing indexes, connection pressure.
Related MCP Servers
- AlicenseBqualityDmaintenanceA lightweight Postgres MCP server for safe database exploration and query analysis, read-only by default, with multi-database support.416 PyPI4MIT
- AlicenseAqualityCmaintenanceMCP server for querying and managing multiple databases (SQLite, PostgreSQL, MySQL) with read-only mode and schema inspection.213MIT
- AlicenseNot gradedqualityCmaintenanceA cross-platform MCP server for querying and introspecting PostgreSQL databases with SSH tunnel support, featuring multi-layered query safety and read-only enforcement.26 npmMIT
- AlicenseNot gradedqualityCmaintenanceA Python MCP server for inspecting and querying MySQL databases, providing table discovery, schema inspection, read-only queries, and optional write/DDL tools.MIT