QueryShield
QueryShield
AIエージェントとエンタープライズデータベース間のセキュアなSQLプロキシ。
エージェントは、プレーンな英語(または構造化されたSQL)で単一のエンドポイントを呼び出します。QueryShieldは以下の処理を行います:
プロンプトキャッシングを使用して、Claude経由で自然言語をSQLに変換します。
すべてのクエリをASTレベルで検証します。
SELECTのみが許可され、ステートメントの連結、禁止された関数、LIMIT句の欠如は許可されません。エージェントごとの行レベルセキュリティを適用します:スキーマ/テーブルのホワイトリストおよび
WHERE句のインジェクション。顧客のDBに対して実行し、行を返します。
すべての試行を追記専用の監査テーブルに記録します。メタデータのみを記録し、行の内容は決して記録しません。
エージェントが接続文字列を見ることはありません。
クイックスタート
pip install -r requirements.txt
cp .env.example .env
# Set ANTHROPIC_API_KEY, DATABASE_URL, VAULT_KEY (see below)
python -m queryshield.startVAULT_KEY用にFernetキーを一度生成し、紛失しないようにしてください:
python -c "from cryptography.fernet import Fernet; print(Fernet.generate_key().decode())"Related MCP server: Midplane
エンドツーエンドフロー (curl)
# 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:secret@db.acme.internal: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" }
}'
# 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統合
公式MCPレジストリに io.github.bch1212/queryshield として掲載されています。
クライアントをインストールします:
pip install queryshield-mcp次に、これをClaude Desktop / Cursor / エージェントの設定に記述します:
{
"queryshield": {
"command": "queryshield-mcp",
"env": { "QUERYSHIELD_API_KEY": "qs_..." }
}
}スタンドアロンのPyPIパッケージのソースは packages/queryshield-mcp/ にあります。
MCP統合 (レガシー)
MCP対応クライアント(Claude Desktop、Cursor、カスタムエージェント)に以下を記述します:
{
"queryshield": {
"command": "python",
"args": ["-m", "queryshield.mcp_server"],
"env": {
"QUERYSHIELD_API_KEY": "qs_...",
"QUERYSHIELD_BASE_URL": "https://api.queryshield.io"
}
}
}公開されているツール:
query_database(database_alias, question, max_rows)— 自然言語によるクエリquery_database_sql(database_alias, sql, max_rows)— 事前構築されたSELECTクエリget_audit_log(limit)— 呼び出し元エージェントの最近の試行履歴
セキュリティモデル
脅威 | 防御策 |
エージェントが | sqlglot ASTがSELECT以外を拒否 |
エージェントが | パーサーが |
エージェントが | ASTノードレベルで関数を拒否リスト化 |
エージェントがスコープ外のテーブルを読み取る | RLSスキーマ + テーブルホワイトリスト |
エージェントが他のテナントの行を読み取る | AST |
スタックトレース経由で接続文字列が漏洩する | Fernetで暗号化され、APIで返されることはない |
監査ログがデータ流出のベクトルになる | メタデータのみが保存され、行データは保存されない |
| 新しいキーで再暗号化(スクリプト駆動) |
safety.py は最も重要なモジュールです。ここに追加されるすべてのチェックは、tests/test_safety.py でのテストと共に出荷される必要があります。
料金
プラン | 月額 | データベース | クエリ数 / 月 | 備考 |
Starter | $500 | 3 | 1,000,000 | |
Pro | $1,500 | 10 | 10,000,000 | 監査エクスポート |
Enterprise | $3,500 | 無制限 | 無制限 | SSO, SIEM Webhook |
目標は $32.5K MRR @ 15顧客 (Pro 10 + Enterprise 5) です。
デプロイ
このリポジトリはRailwayに対応しています。python -m queryshield.start がエントリポイントです(Railwayはシェルなしで開始コマンドを実行するため、os.getenv 経由で PORT を読み取ります)。RailwayのマーケットプレイスからPostgres + (オプションで) Redisをプロビジョニングし、残りは環境変数で設定します。
railway up/health は生存確認用です。/ready はコントロールプレーンのDBに到達できない場合に503を返します。
テスト
pip install pytest
python -m pytest tests/42個のテストが以下をカバーしています:
ASTの安全性(24ケース — 直接的なDDL、コメント、エンコードされたキーワード、複数のステートメント、禁止された関数、LIMITの欠如)
RLSエンジン(6ケース — ホワイトリストの強制、WHERE句の注入、既存の述語との結合)
SQLite「顧客DB」に対するプロキシのエンドツーエンドテスト(5ケース — 正常系、ブロックされたDML、RLS行フィルタリング、テーブルホワイトリスト、キャッシュヒット)
FastAPI TestClient経由のHTTP統合(7ケース — 完全なプロビジョニング → クエリフロー、RLS付きスコープエージェント、認証失敗)
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnforces safety and governance for SQL queries executed by AI agents, providing read-only enforcement, cost estimation, and audit trails.Apache 2.0

Midplaneofficial
AlicenseNot gradedqualityBmaintenanceSQL guardrails for AI agents, sitting between the agent and Postgres to enforce policies, block destructive queries, and audit all access.5MIT- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query Postgres, BigQuery and DuckDB read-only through policy-checked SQL, with AST-based guards that refuse writes and dangerous functions, column masking on the way out, and an audit log of every query. Also exposes schema browsing and query-planning tools so agents can see allowed tables, columns and costs before running anything.MIT
- AlicenseAqualityBmaintenanceGuardrail proxy for AI agents on SQL Server. Each statement runs as the caller's own login, a T-SQL parser blocks dangerous statements, and every statement is audited. Local stdio mode or a central Docker service.11MIT