SQL Safe MCP

io.github.proprock由 GitHub 帳號 proprock 發布v1.5.2更新於 Oct 24, 2026

Minimal, read-only, PII-safe MCP server for SQL databases.

發布方自己的服務:Google Analytics (unofficial)

概覽

AI 產生的概覽

唯讀的 MCP 伺服器,讓編碼助理了解 SQL Server、MySQL 與 MariaDB 的結構,並在受保護的 PII 欄位以權杖回傳的前提下執行受限 SELECT 查詢。

可以做什麼
  • 列出已設定的伺服器別名以及憑證可見的資料庫
  • 依結構描述或名稱瀏覽基底資料表,並讀取單一資料表的欄位、鍵、條件約束與索引
  • 列出預存程序並讀取單一預存程序的定義(需 meta_and_code 或 all_pii_safe 權限)
  • 在 all_pii_safe 別名上執行一筆受限且經驗證的 SELECT,受保護欄位以綁定別名的權杖回傳,可用於 = 與 IN 篩選
適用情境
適合編碼助理需要理解既有 SQL Server、MySQL 或 MariaDB 結構以撰寫正確程式碼,或需要查看真實資料列但不想暴露個人資料的情境。也適合希望資料庫存取不含任何寫入工具、並使用最小權限帳號的團隊。
執行需求
透過 uvx 或 pip 以 stdio 方式在本機執行(Python 3.12–3.14);連線 SQL Server 需 Microsoft ODBC Driver 18,MySQL 與 MariaDB 使用內附的 PyMySQL 驅動程式。需要由 SQL_SAFE_MCP_CONFIG(或 --config)指向的 YAML 設定檔,以及存放連線 URL 與 PII 金鑰的環境變數;還需資料庫憑證與到執行個體的網路存取。
安裝前請注意
連線 URL 與 PII 金鑰屬於機密:應放在主機環境變數中,不要寫入 YAML 檔或受版本控制的檔案。伺服器以資料庫帳號的權限運作,請使用專用的最小權限登入。保護只涵蓋你列出的欄位,未列出的個人資料仍可能以明文回傳。資料列查詢需要明確設定 all_pii_safe 別名及其專屬金鑰。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 SQL Safe MCP,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

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.

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

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 all_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 an all_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.
  • 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.
  • 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 database navigation and table structure; meta_and_code additionally exposes stored procedures; execute_sql needs an explicit all_pii_safe alias 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.
ToolAccessPurpose
list_servers🟢 readConfigured server aliases
list_databases🟢 readDatabases visible to the credentials
list_tables🟢 readBase tables, filtered by schema or name
get_table_definition🟢 readColumns, keys, constraints, and indexes of one table
list_stored_procedures🟢 readStored procedures, without definitions; requires meta_and_code or all_pii_safe
get_stored_procedure🟢 readThe definition of one stored procedure; requires meta_and_code or all_pii_safe
execute_sql🟢 readOne restricted SELECT on an all_pii_safe server; protected columns return tokens

[!NOTE] Status: SQL Server supports every tool. MySQL and MariaDB (engine: mysql or mariadb, mysql+pymysql URLs) support every tool too. schema is always null there because the database is the catalog, and execute_sql uses LIMIT instead of TOP. See architecture.md.

Quick start

Install

bash
uvx sql-safe-mcp

or

bash
pip install sql-safe-mcp

Pin a version when you want a fixed surface: uvx sql-safe-mcp==1.5.2.

Requires Python 3.12–3.14, 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).

Or you can even ask an agent to install it
text
Install sql-safe-mcp as a stdio MCP server.Ask whether to install it for this project/workspace or at user level. Then:detect and preserve the host's existing MCP config;configure the server to run via uvx sql-safe-mcp;create a YAML config template with env placeholders only;add SQL_SAFE_MCP_CONFIG;report the env variables the user must set.Do not store secrets or connection data in tracked files or output. Validate withsql-safe-mcp --check-config once variables are available.

Configure server

Copy sql-safe-mcp.example-simple.yaml to sql-safe-mcp.yaml. This smallest configuration exposes schema metadata from one SQL Server instance and does not allow row queries. Keep the complete connection URL in an environment variable:

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

Here reporting is the value an agent passes as server. A missing variable, or an engine that does not match the URL dialect, stops the MCP server at startup. For multiple servers, local PII rules, shared PII rule sets, logging, and runtime limits, use the commented examples in the configuration reference.

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:

bash
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
bash
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:

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
bash
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:

json
{  "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 server alias. If FirstName is protected, SELECT FirstName FROM Users WHERE FirstName = 'Alice' is rejected before it reaches the database. Filter protected columns only with authentic pii:v1:... tokens returned by execute_sql for the same alias; a matching prefix alone is not enough. Each token is authenticated and alias-bound, then validated and converted to a bound database value. 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.

來源:README.md,提交 9dd2a69

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

6
  1. v1.5.2最新Oct 6, 2026
  2. v1.5.1Sep 23, 2026
  3. v1.5.0Sep 23, 2026
  4. v1.4.0Sep 22, 2026
  5. v1.3.1Sep 21, 2026
  6. v1.2.0Sep 21, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

其他 Safe-Mcp 整合