Queryshield

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

Secure SQL proxy for AI agents — NL→SQL, AST safety, per-agent RLS, audit log.

已驗證STDIO僅桌面資料庫安全與監控

概覽

AI 產生的概覽

一個安全的 SQL 代理,讓助理用自然語言或預先建立的 SELECT 語句查詢企業資料庫。

可以做什麼
QueryShield 位於 AI 代理與客戶資料庫之間。代理呼叫 query_database 送出自然語言問題,或呼叫 query_database_sql 送出預先建立的 SELECT,由代理完成翻譯、驗證與執行。驗證以 AST 為基礎:只允許 SELECT,會拒絕堆疊語句與被禁用的函式,並要求帶 LIMIT。依代理的行級安全會套用結構描述與資料表白名單並注入 WHERE 篩選條件,get_audit_log 則回傳呼叫代理的近期的嘗試紀錄。
適用情境
當助理需要唯讀存取正式或內部 SQL 資料庫,但不應持有連線字串、也不該被信任執行寫入時適用。適合希望對代理的資料庫存取實施依代理範圍限制、資料列篩選與稽核追蹤的團隊。
執行需求
以本機 stdio 程序執行,從 PyPI 套件 queryshield-mcp 安裝。需要環境變數 QUERYSHIELD_API_KEY,也就是 QueryShield 簽發的代理 API 金鑰,可選用 QUERYSHIELD_BASE_URL 覆寫預設端點。QueryShield 服務本身需要另行部署,並設定 Anthropic 金鑰、資料庫 URL 與保存庫金鑰。
安裝前請注意
代理 API 金鑰是機密,透過 QUERYSHIELD_API_KEY 傳入,應限定給單一代理。查詢會送到 QueryShield 服務,由其轉送到所設定的資料庫,並使用外部模型進行自然語言翻譯,因此資料會離開本機。此服務為商業產品,採付費方案。稽核記錄只存中繼資料,不存資料列內容。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

QueryShield

[tests]

Agent security suite. QueryShield is the lead product: a secure SQL proxy and a named credential vault, one qs_ API key, one Stripe customer, and this docs site.

Agents call a single endpoint in plain English (or structured SQL). QueryShield:

  1. Translates natural language → SQL via Claude with prompt caching.
  2. Validates every query at the AST level — only SELECT is allowed, no stacked statements, no forbidden functions, LIMIT required.
  3. Applies per-agent row-level security: schema/table whitelists and WHERE clause injection.
  4. Executes against the customer DB and returns rows.
  5. Logs every attempt to an append-only audit table — metadata only, never row contents.

Agents never see connection strings.

The credential vault stores other secrets (API tokens the agent is allowed to use). It is the AgentVault product, folded into this service. Permission patterns decide which names an agent can read. Database connection strings stay in a separate encrypted store and are not readable through the vault.

Free tier / funnel: InjectShield scans untrusted text for prompt injection. It stays in its own repository (bch1212/injectshield) and its own API (api.injectshield.dev). Start there, then create one QueryShield workspace when an agent needs a database or a vault. Docs: injectshield.dev/docs. Suite page on this service: /suite.


Quickstart

bash
pip install -r requirements.txtcp .env.example .env# Set ANTHROPIC_API_KEY, DATABASE_URL, and VAULT_KEY in .env (see below).# Do not commit .env. QueryShield reads secrets from the environment only.
python -m queryshield.start

Generate a Fernet key for VAULT_KEY once and never lose it. Credential encryption and session signing both require VAULT_KEY (or SESSION_KEY for cookies). If it is unset, those operations fail instead of using a built-in key:

bash
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"

End-to-end flow (curl)

bash
# 1) Boot a tenant. Returns the admin API key — copy it.curl -X POST localhost:8000/v1/tenants?name=Acme
# 2) Register the customer DB. Connection string is encrypted at rest.curl -X POST localhost:8000/v1/databases \  -H 'X-Admin-Key: qs_...' \  -H 'Content-Type: application/json' \  -d '{    "alias": "prod",    "db_type": "postgresql",    "connection_string": "postgresql://READER:[email protected]:5432/app",    "allowed_tables": ["users", "orders"]  }'
# 3) Provision a scoped agent (different from admin) for your AI app.curl -X POST localhost:8000/v1/agents \  -H 'X-Admin-Key: qs_...' \  -H 'Content-Type: application/json' \  -d '{ "name": "reporting", "tenant_id": "<tenant>" }'
# 4) Set the agent's RLS policy.curl -X POST localhost:8000/v1/policies \  -H 'X-Admin-Key: qs_...' \  -H 'Content-Type: application/json' \  -d '{    "agent_id": "<agent>",    "database_alias": "prod",    "allowed_tables": ["users", "orders"],    "row_filters": { "users": "tenant_id = 42" }  }'
# 4b) Store a named credential and let one agent read it.#     The value is write-only on this call. Empty permissions grant nothing.curl -X POST localhost:8000/v1/credentials \  -H 'X-Admin-Key: qs_...' \  -H 'Content-Type: application/json' \  -d '{    "name": "openai_key",    "provider": "openai",    "value": "YOUR_SECRET"  }'
curl -X POST localhost:8000/v1/agents \  -H 'X-Admin-Key: qs_...' \  -H 'Content-Type: application/json' \  -d '{    "name": "writer",    "tenant_id": "<tenant>",    "credential_permissions": ["openai_*"],    "budget_daily": 5  }'
# The agent uses the same qs_ key it uses for /v1/query.curl -X POST localhost:8000/v1/vault/get/openai_key \  -H 'X-API-Key: qs_...'
# 5) The agent queries.curl -X POST localhost:8000/v1/query \  -H 'X-API-Key: qs_...' \  -H 'Content-Type: application/json' \  -d '{    "database_alias": "prod",    "query": "how many active users do we have?",    "mode": "nl",    "max_rows": 10  }'

MCP integration

Listed in the official MCP Registry as io.github.bch1212/queryshield.

Install the client:

bash
pip install queryshield-mcp

Then drop this into your Claude Desktop / Cursor / agent config:

json
{  "queryshield": {    "command": "queryshield-mcp",    "env": { "QUERYSHIELD_API_KEY": "qs_..." }  }}

Source for the standalone PyPI package lives in packages/queryshield-mcp/.

For MCP directory evaluators such as Glama, the repository root also includes a slim Dockerfile that launches the published queryshield-mcp stdio server for tool introspection. The container does not need QUERYSHIELD_API_KEY for MCP initialization/tool discovery; the key is only required when a discovered tool is actually invoked against a QueryShield API tenant.

MCP integration (legacy)

Drop this into any MCP-aware client (Claude Desktop, Cursor, custom agents):

json
{  "queryshield": {    "command": "python",    "args": ["-m", "queryshield.mcp_server"],    "env": {      "QUERYSHIELD_API_KEY": "qs_...",      "QUERYSHIELD_BASE_URL": "https://api.queryshield.io"    }  }}

Tools exposed:

  • query_database(database_alias, question, max_rows) — natural-language
  • query_database_sql(database_alias, sql, max_rows) — pre-built SELECT
  • list_credentials() — names this agent may read
  • get_credential(name, cost) — one permitted secret, same API key
  • get_audit_log(limit) — recent attempts for the calling agent

The PyPI package queryshield-mcp picks up the vault tools on its next release. Until then, python -m queryshield.mcp_server from this repo already exposes them.


Security model

ThreatDefense
Agent crafts a DROP TABLEsqlglot AST refuses non-SELECT
Agent sneaks ; and a second statementparser rejects len(statements) > 1
Agent uses pg_sleep, xp_cmdshell, ...function deny-list at the AST node level
Agent reads tables outside its scopeRLS schema + table whitelist
Agent reads other tenants' rowsrow_filters injected via AST .where()
Connection string leaks via stack tracesFernet-encrypted, never returned in any API
Agent reads a secret it was not grantedfnmatch permissions; empty list fails closed
Vault audit becomes the secretcredential access log stores metadata only
Audit log becomes the data exfil vectoronly metadata is stored — never rows
VAULT_KEY rotationre-encrypt rows under new key (script-driven)

safety.py is the single most important module. Every additional check that lands there should ship with a test in tests/test_safety.py.


Pricing

TierMonthlyDatabasesCredentialsQueries / monthNotes
InjectShieldfree———prompt-injection funnel, separate site
Starter$5003251,000,000
Pro$1,5001010010,000,000audit export
Enterprise$3,500unlimitedunlimitedunlimitedSSO, SIEM webhook

QueryShield tiers are one Stripe customer. InjectShield sign-up stays on injectshield.dev until that billing is folded in. Targets $32.5K MRR @ 15 customers (10 Pro + 5 Enterprise).


Deploy

The repo is Railway-ready. python -m queryshield.start is the entrypoint (reads PORT via os.getenv, since Railway exec's the start command without a shell). Provision Postgres + (optionally) Redis from Railway's marketplace and the rest is env vars.

railway up

/health is the liveness check. /ready returns 503 if the control-plane DB is unreachable.


Tests

bash
pip install pytestpython -m pytest tests/

102 tests cover the original safety, RLS, proxy, and HTTP suites plus the credential vault (encryption, qs_ key hashing, permission checks, budgets, tenant isolation, and the column migration for existing databases) and fail-closed VAULT_KEY / SESSION_KEY checks. The original cases:

  • AST safety (24 cases — direct DDL, comments, encoded keywords, multiple statements, forbidden functions, missing LIMIT)
  • RLS engine (6 cases — whitelist enforcement, WHERE injection, conjunction with existing predicates)
  • Proxy end-to-end against a SQLite "customer DB" (5 cases — happy path, blocked DML, RLS row filtering, table whitelist, cache hit)
  • HTTP integration via FastAPI TestClient (7 cases — full provisioning → query flow, scoped agent with RLS, auth failures)

來源:README.md,提交 462a237

工具

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

版本歷史

1
  1. v1.0.1最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

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

  • 近 30 天內可連通25 分

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

  • 已宣告認證方式10 分

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

  • 已列出工具15 分

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

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