sql-safe-mcp
A PII-safe, read-only MCP server for coding agents working with SQL Server, MySQL and MariaDB: schema knowledge and safe queries without write-capable tools or plaintext exposure of configured PII columns.
Read the data. Protect the identity.
Give a coding agent the schema knowledge it needs to write correct code - servers, databases,
tables, columns, keys, indexes, and stored procedures. On aliases you mark pii_safe, it can also
query real rows while configured personal data stays hidden behind authenticated tokens.
PII-safe by default. Read-only by design.
- PII-safe by default - on a
pii_safeserver, the columns you configure come back as alias-bound, authenticated tokens (pii:v1:...), never as plaintext. An agent can still project, count, and filter on them with=andINusing tokens it was given, so it can follow a record without reading it. Tokens do not work on another server alias or with another key. - Read-only by construction - seven tools, all annotated read-only. No tool writes data, and
the server never executes SQL an agent wrote: metadata comes from SQLAlchemy Inspector and fixed
catalog queries, and
execute_sqlruns only a validated, regeneratedSELECT. - Multiple servers, isolated policies - one MCP process can expose multiple named SQL Server, MySQL, and MariaDB instances. Each alias has its own connection, access level, and, when enabled, PII key and protection rules. Every database operation targets an explicit alias; there is no network discovery.
Operational safeguards
- Fails closed - SQL validation is an allowlist. Unknown syntax, unresolved lineage, and unsupported protected-value types are refused, not guessed at. The verification evidence is in the security model.
- Least access first -
access_level: metadata(the default) exposes schema only;execute_sqlneeds an explicitpii_safealias with its own key. Database permissions stay the primary control, so use a least-privilege login. - Secrets stay out of sight - connection URLs live in YAML with
${NAME}placeholders resolved from the environment. They never appear in logs or model-visible errors. - Compact, predictable output - object-rooted results with stable sorting, literal case-insensitive name filters, and stored procedure lists that do not expand definitions.
- Errors an agent can act on - an ambiguous name lists the candidate schemas. Errors never contain connection details, credentials, keys, tokens, or rows.
- Tested against attacks, not just examples - the SQL and PII boundary is checked with an adversarial corpus of hostile statements, property-based tests (token isolation, tamper resistance), a live attack run against a really writable login with before/after snapshots, and mutation testing. Results are in Verification of the SQL boundary.
- Diagnosable failures - a timeout or connection error carries a
Reference, and the stderr log records the connection stage, elapsed time, and driver error for the same reference, with credentials removed. See Logging.
| Tool | Access | Purpose |
|---|---|---|
list_servers |
🟢 read | Configured server aliases |
list_databases |
🟢 read | Databases visible to the credentials |
list_tables |
🟢 read | Base tables, filtered by schema or name |
get_table_definition |
🟢 read | Columns, keys, constraints, and indexes of one table |
list_stored_procedures |
🟢 read | Stored procedures, without definitions |
get_stored_procedure |
🟢 read | The definition of one stored procedure |
execute_sql |
🟢 read | One restricted SELECT on a pii_safe server; protected columns return tokens |
Quick start
Install
uvx sql-safe-mcp
or
pip install sql-safe-mcp
Pin a version when you want a fixed surface: uvx sql-safe-mcp==1.4.0.
Requires Python 3.12+, uv (or pip), and
Microsoft ODBC Driver 18 for SQL Server
when you connect to SQL Server. MySQL and MariaDB use the bundled PyMySQL driver and need nothing
else.
Verified against SQL Server 2022, MySQL 8.4, and MariaDB 11.4 (see CHECKS.md).
Configure multiple servers
Copy sql-safe-mcp.example.yaml to sql-safe-mcp.yaml. Add each
database server under a named alias and keep credentials in environment variables:
version: 1
servers:
reporting:
engine: sqlserver
access_level: metadata
connection_url: "${REPORTING_SQL_URL}"
billing:
engine: sqlserver
access_level: pii_safe
connection_url: "${BILLING_SQL_URL}"
pii_key_env: BILLING_PII_KEY
pii:
rules:
- database: Billing
schema: dbo
table: Customers
columns: [Email, FullName]
shop:
engine: mysql
access_level: metadata
connection_url: "mysql+pymysql://${SHOP_USER}:${SHOP_PASSWORD}@db.internal/shop"
Here reporting, billing, and shop are the values an agent passes as server. Their
credentials and access policies are independent. A missing variable, or an engine that does not
match the URL dialect, stops the MCP server at startup.
Ask an agent to install it
Give a coding agent the following prompt when you want it to perform the setup in its own MCP host:
Install and configure sql-safe-mcp as a stdio MCP server for this workspace. First inspect the
host's existing MCP configuration convention and preserve all unrelated server entries. Create or
update a non-secret YAML configuration using environment-variable placeholders only. Never put
connection URLs, passwords, PII keys, tokens, bind values, or query results in tracked files, chat
output, or logs. If the database aliases, engines, access levels, PII rules, configuration path,
or secret-storage mechanism are not specified, ask me before choosing them. Configure the host to
run `uvx sql-safe-mcp` with `SQL_SAFE_MCP_CONFIG` and the required variables supplied through the
host's secret or environment mechanism. Run `sql-safe-mcp --check-config` after the variables are
available, then report only the configured aliases and the validation result.
Check the configuration
After defining every environment variable referenced by the YAML file, point the server at it with
SQL_SAFE_MCP_CONFIG (or --config) and check it without connecting to any database:
SQL_SAFE_MCP_CONFIG=sql-safe-mcp.yaml uvx sql-safe-mcp --check-config
Configuration is validated at startup, and an error names the problem without printing a URL or secret. Keep credentials in the host's own configuration and never commit them. The server acts with the database account's permissions, so use a dedicated login with the least access the job needs.
Connect an MCP client
Every client configuration needs SQL_SAFE_MCP_CONFIG plus the environment variables referenced
by your YAML file. Keep connection URLs and PII keys in the MCP host's environment or
configuration, never in the YAML file or other tracked files.
Claude Code
claude mcp add --env SQL_SAFE_MCP_CONFIG=/path/to/sql-safe-mcp.yaml --env REPORTING_SQL_URL=mssql+pyodbc://... --transport stdio sql-safe -- uvx sql-safe-mcp
Put at least one other option between the last --env and the server name, as above. Otherwise,
the CLI reads the name as another KEY=value pair.
Claude Desktop
Add the server to claude_desktop_config.json:
{
"mcpServers": {
"sql-safe": {
"command": "uvx",
"args": ["sql-safe-mcp"],
"env": {
"SQL_SAFE_MCP_CONFIG": "/path/to/sql-safe-mcp.yaml",
"REPORTING_SQL_URL": "mssql+pyodbc://..."
}
}
}
}
Codex CLI
codex mcp add sql-safe --env SQL_SAFE_MCP_CONFIG=/path/to/sql-safe-mcp.yaml --env REPORTING_SQL_URL=mssql+pyodbc://... -- uvx sql-safe-mcp
Any other stdio host
Use command uvx, argument sql-safe-mcp, and set SQL_SAFE_MCP_CONFIG plus every environment
variable referenced by the configuration file. The server writes MCP messages to stdout and logs
only to stderr.
PII-safe queries
execute_sql on the billing alias allows one restricted SELECT. For example, these arguments:
{
"server": "billing",
"database": "Billing",
"sql": "SELECT CustomerId, Email FROM dbo.Customers"
}
can return a row such as [42, "pii:v1:..."]: the agent can follow the customer without reading
the email address. A token is accepted only in = and IN predicates on the same protected column
and server alias. Protection covers the columns you list, so list every column that holds personal
data.
Documentation
- Configuration reference - aliases, connection URLs, PII rules, runtime limits, and logging.
- Tool reference - arguments, responses, errors, and the accepted SQL subset.
- Security model - trust boundaries, guarantees, limitations, and verification.
- Checks - local, integration, and security verification commands.
Security
The MCP caller, SQL input, database metadata, rows, and tokens are untrusted. Database permissions remain the primary authorization control - this server never widens them. Read the full security model, including its limitations and verification evidence. To report a vulnerability, use the private channel in SECURITY.md.
Contributing
Setup, checks, the test commands, the branch and commit conventions, and the release model are in CONTRIBUTING.md. Changes that affect someone running the server are recorded in CHANGELOG.md.
License
MIT.
Metadata
Release files for sql-safe-mcp 1.4.0
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 | Actions |
|---|---|---|---|---|
| sql_safe_mcp-1.4.0.tar.gz | 35.3 kB | With provenance | Details for sql_safe_mcp-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sql_safe_mcp-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for sql_safe_mcp-1.4.0-py3-none-any.whl |
Total release size: 79.6 kB
Release files / sql_safe_mcp-1.4.0.tar.gz
| Download URL | sql_safe_mcp-1.4.0.tar.gz |
|---|---|
| Size | 35.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
226f46e3137b244b58114b5574134f9a856ba1373d10e5e0dff3d20fa97125c7
|
|
BLAKE2b-256 checksum How to use checksums |
cff623411d84a9501b56ee857a4c99aa61fe8ae6632c2e65d13d3682bd1225b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logRelease files / sql_safe_mcp-1.4.0-py3-none-any.whl
| Download URL | sql_safe_mcp-1.4.0-py3-none-any.whl |
|---|---|
| Size | 44.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d95fd733b625ab534d699e7757e25e7a819ac14ea1b5f3db7f6b0abaa7b36768
|
|
BLAKE2b-256 checksum How to use checksums |
30373720d0807834d4da1dfdc84bd157ee29bb6b678393028f56f753ac7492d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 22, 2026.
Transparency logSecurity for sql-safe-mcp 1.4.0
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
Both files in this release have been uploaded with provenance metadata.
Attestation for sql_safe_mcp-1.4.0.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 Sep 22, 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.