Skip to main content

sql-safe-mcp

A read-only, PII-safe SQL Server, MySQL and MariaDB MCP server for coding agents: schema knowledge and safe queries, with no way to change or leak data.

CI Release PyPI Version Python License: MIT

Model Context Protocol compatible MCP Registry: io.github.proprock/sql-safe-mcp

Read the data. Protect the identity.

Read the data. Protect the identity.

General-purpose database MCP servers hand the agent a raw SQL prompt and dozens of tools. This server gives a coding agent the schema knowledge it needs to write correct code - servers, databases, tables, columns, keys, indexes, stored procedures - and, on servers you mark pii_safe, a way to look at real rows without ever seeing the personal data in them.

Read-only by design. PII-safe by default

  • 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_sql runs only a validated, regenerated SELECT.
  • PII-safe by default - on a pii_safe server, 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 = and IN using 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.
  • 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_sql needs an explicit pii_safe alias with its own key. Database permissions stay the primary control, so use a least-privilege login.

Also

  • Your aliases, not your network - the agent sees only the server aliases you configure. There is no network discovery, and the catalog is not published as MCP resources.
  • 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.
  • On PyPI - uvx sql-safe-mcp, no repo clone required.
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

More detail lives in docs/: the configuration reference, what the tools return, and the security model.

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.3.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

Copy sql-safe-mcp.example.yaml to sql-safe-mcp.yaml, list your servers, and keep credentials in environment variables:

version: 1
servers:
  reporting:
    engine: sqlserver
    access_level: metadata
    connection_url: "${REPORTING_SQL_URL}"

connection_url is a SQLAlchemy URL whose dialect must match engine. It is a secret, so keep the credentials in environment variables and reference them with ${NAME}:

servers:
  # The whole URL comes from one variable (it may hold any valid URL).
  reporting:
    engine: sqlserver
    connection_url: "${REPORTING_SQL_URL}"

  # SQL Server (mssql+pyodbc), URL assembled from parts. Embedded placeholders are
  # URL-encoded, so a password containing @ or / is safe.
  billing:
    engine: sqlserver
    connection_url: >-
      mssql+pyodbc://${BILLING_USER}:${BILLING_PASSWORD}@${BILLING_HOST}/master
      ?driver=ODBC+Driver+18+for+SQL+Server&Encrypt=yes

  # MySQL or MariaDB (mysql+pymysql). Use engine: mariadb for MariaDB.
  shop:
    engine: mysql
    connection_url: "mysql+pymysql://${SHOP_USER}:${SHOP_PASSWORD}@db.internal/shop"

A missing variable, or an engine that does not match the URL dialect, stops the server at startup.

Point the server at the file 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. Every setting, including the runtime limits, is in configuration.md.

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 - the CLI otherwise reads the name as another KEY=value pair.

Claude Desktop

In 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

Command uvx, argument sql-safe-mcp, and the environment variables your configuration references, plus SQL_SAFE_MCP_CONFIG. The server speaks MCP over stdio and logs only to stderr.

PII-safe queries

Mark an alias access_level: pii_safe, give it its own key, and list the protected columns:

servers:
  legacy_prod:
    engine: sqlserver
    access_level: pii_safe
    connection_url: "${LEGACY_PROD_SQL_URL}"
    pii_key_env: LEGACY_PROD_PII_KEY
    pii:
      rules:
        - database: "*"
          schema: dbo
          table: Users
          columns: [Email, FirstName, LastName]

execute_sql then accepts one restricted SELECT. Protected cells come back as tokens, and a token is accepted only in = and IN predicates on the same alias. Protection covers the columns you list, so list every column that holds personal data. The rule format, key generation, and the accepted SQL are in configuration.md and tools.md.

Security

The MCP caller, SQL input, database metadata, rows, and tokens are untrusted; the operator, the process environment, and the database credentials are the trusted boundary. Database permissions remain the primary authorization control - this server never widens them. The full model and its verification are in SECURITY-MODEL.md. 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.

Release files for sql-safe-mcp 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sql-safe-mcp 1.3.0
File Size Uploaded
sql_safe_mcp-1.3.0.tar.gz 33.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sql-safe-mcp 1.3.0
File Interpreter ABI Platform
sql_safe_mcp-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 76.3 kB

Release files / sql_safe_mcp-1.3.0.tar.gz

Download URL sql_safe_mcp-1.3.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8f3dd307a8d2510bae5fdeed07573c2cdd9ecb335f9d373dc803e296b3d063f6
BLAKE2b-256 checksum
How to use checksums
46903b4dd518680b80a58d01189725478e949044dc5cc2c8abc24027ca7848f3
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 21, 2026.

Transparency log

Release files / sql_safe_mcp-1.3.0-py3-none-any.whl

Download URL sql_safe_mcp-1.3.0-py3-none-any.whl
Size 42.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7385036648d9c02e190d681a9b1d622bff4b55f4aa138de02ad0200aced0a81
BLAKE2b-256 checksum
How to use checksums
526f98c60ec64e52c0dc5e24c18e9e5b48ad9711eb3977dff70409460e32824f
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 21, 2026.

Transparency log

Release history Release notifications | RSS feed

1.3.1

2 release files

This release

1.3.0 This release

2 release files

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page