Skip to content

Use sqlguardllm with the MCP server you already have

Español: es/PROXY.md

You already run a database MCP server (dbhub, Postgres MCP Pro, Supabase, a SQL Server server) and don't want to switch. sqlguardllm proxy sits between your MCP client and that server: it starts the server for you, checks the SQL of the tools you map and refuses everything else.

pip install "sqlguardllm[yaml]"
sqlguardllm proxy --policy policy.yaml --map proxy.yaml -- npx -y @bytebase/dbhub --dsn "postgres://reader@host/db"

Everything after -- is the upstream command, run directly (no shell). Register only the proxy in your MCP client, in place of the upstream server.

The map

# proxy.yaml
dialect: postgres            # optional; must match the policy's dialect
sql_tools:
  execute_sql: {sql_arg: sql}   # tool name -> argument that carries the SQL
passthrough: [search_objects]   # forwarded untouched
Tool What the proxy does
In sql_tools Runs Guard.check() on the sql_arg argument. If allowed, forwards the rewritten SQL (row filters, masks, LIMIT); if not, returns the violations as a tool error and the upstream never sees the call.
In passthrough Forwards the call unchanged.
Anything else Hidden from tools/list and refused on tools/call with tool_not_allowed. Default deny.

Startup fails (exit code 2) on unknown keys, a tool in both lists, an empty sql_arg, an empty map or a dialect different from the policy's. On the first tools/list the proxy prints to stderr the upstream tools it hides, and the mapped tools the upstream doesn't offer.

The policy, --role, --context, --language, --audit-log and --audit-sql work as in sqlguardllm mcp. The context is set by you at startup; no tool argument can change it.

Security notes

  • passthrough tools return metadata the policy does not filter. Schema-discovery tools (search_objects, list_schemas, get_object_details...) show every table and column the upstream credential can see, including tables and columns your policy hides. SQL against them is still refused, but names and types leak. Leave them out of passthrough unless the upstream credential can see only what the model may see.
  • With strict: true in the map (or Proxy(..., strict=True)), the proxy refuses to start when a passthrough tool has a string input named like SQL (sql, query, statement, command, script). Without it, it logs a warning.
  • passthrough tools must not accept SQL. The proxy cannot check that. A tool that takes SQL, a query name or any free-form command and sits in passthrough bypasses the guard. When unsure, leave it out. Some servers have a second SQL-taking tool (an explain_query, for example): map it in sql_tools.
  • Only one SQL argument is guarded, the one in sql_arg. Other arguments are forwarded as they are.
  • The client must not reach the upstream directly. Don't register the upstream server in the client as well.
  • Connect the upstream with a read-only database user. The proxy is a second layer, not a replacement.
  • Authorization comes from the map, never from what the upstream lists: a changed or compromised upstream can't add tools. Tool descriptions are the upstream's text and reach the model unchanged.
  • The upstream command line is never printed: it often holds a password. Prefer environment variables to put secrets in it.

Verified against real servers

Upstream server Version Result
dbhub 2.1.0 (npx -y @bytebase/dbhub --transport stdio, SQLite) Checked 2026-11-30 through sqlguardllm proxy with examples/proxy/dbhub.yaml (dialect changed to sqlite): tools/list shows execute_sql and search_objects; a row-filtered SUM returns only the user's branches; invoices.secret is refused as hidden_column, another table as table_not_allowed, DELETE as not_a_query; an unmapped tool is refused as tool_not_allowed.
Postgres MCP Pro 0.3.0 (uvx --python 3.13 --with mcp==1.25.0 postgres-mcp <url>, PostgreSQL 16) Checked in CI (proxy-upstreams job): its SQL tool is named query in this version; the same cases as above pass, and its other tools are hidden. It needs Python 3.13 and mcp 1.x today.
pymssql-mcp 0.4.2 (SQL Server 2022) Checked in CI: the guarded execute_query returns only the filtered rows and refuses a hidden column, another table and a DELETE; its other 20+ tools (delete_row, call_stored_proc, export_to_csv...) are hidden. microsoft-sql-server-mcp 0.1.0 could not be used: it passes an encrypt argument that current pymssql rejects.

What the proxy does not do (yet)

  • Only stdio. Streamable HTTP is planned as a follow-up.
  • Only tools: resources, prompts, sampling and progress notifications of the upstream are not forwarded, and the capabilities and instructions of the upstream's initialize are trimmed to the tools.
  • No cost guard (--max-cost): the proxy has no database connection, the upstream owns it.
  • Requests are handled one at a time.

Examples

Maps for common servers are in examples/proxy/: dbhub.yaml, postgres-mcp-pro.yaml and a sqlserver.yaml template. Tool names change between releases of these servers: list the tools of your version and adjust the map. The table above records the real-server checks for these maps. The unit tests also use a fake upstream.