
sql-steward
io.github.Pawansingh3889Published by GitHub account Pawansingh3889v0.4.0Updated Oct 24, 2026
The agent never writes SQL: queries compile from a semantic layer you control, PII refused first.
Overview
A local MCP server that gives an AI assistant governed, read-only access to SQL Server, Postgres or SQLite through a semantic layer you write.
- What you can do
- Browse the semantic layer: list entities and metrics, and describe an entity's fields, types and PII tags, including blocked ones flagged as such. Read rows from a single defined entity with filters, ordering and a row limit. Compute pre-approved aggregates by choosing only the dimensions and filters the metric allows. Run pgvector nearest-neighbour search over an entity's embedding column, with query text embedded locally. Verify the tamper-evident, hash-chained audit log of calls, refusals and errors.
- When to use it
- Use it when an assistant should answer questions over a real database without ever writing SQL, and you want blocked PII refused before any query runs. Suited to on-prem or air-gapped setups across SQL Server, Postgres and SQLite where a hand-reviewed semantic layer is acceptable.
- Requirements
- A local Python install of the sql-steward package, plus the matching database driver extra for Postgres or SQL Server. A SQLAlchemy connection URL in SQL_STEWARD_DB_URL, ideally a least-privilege read-only account, and a path to the semantic layer YAML in SQL_STEWARD_LAYER. Optional extras add role policy, masking, audit and a local embedding endpoint.
Installation
In SourceWeft
- Open sql-steward in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
[!IMPORTANT] This repository has moved into the Governed Agent Stack monorepo.
Active development is now at
packages/sql-steward/. This repo is archived and read-only. Its full commit history is preserved here; new work, issues and releases happen in the monorepo.
sql-steward
Part of the Governed Agent Stack: free, on-prem building blocks for an AI agent you can point at a real database and audit.
A governed SQL gateway for AI agents, exposed over the Model Context Protocol. The agent never gets a connection string and never writes SQL. It calls typed tools; sql-steward compiles every query from a semantic layer you control, refuses blocked PII before the query runs, and returns rows. Same tools across SQL Server, Postgres and SQLite.
Most SQL MCP servers hand the model a run_sql tool and try to catch the bad queries on the way out. sql-steward removes the tool. There is no path from a prompt to raw SQL at your database, because the only thing the agent can do is name an entity or a metric and pick from allow-lists you wrote.
See it defend a database live. The governed vs ungoverned demo runs the same request through a naive run_sql agent, which leaks customer PII and empties a table, and through sql-steward, which refuses it at compile time.
Three guarantees
- Read-only by construction. There is no
run_sql,query, orexecutetool. The compiler can only ever build aSELECT, so a write isn't blocked, it's unrepresentable. - PII refused before retrieval. Every field can carry a PII tag. If a request touches a category your policy blocks, sql-steward refuses with a structured reason before any SQL is compiled or run.
- Auditable. Every call, refusal and error can be recorded in a tamper-evident, hash-chained log via agent-blackbox, with
audit-verifyto prove nothing was rewritten.
See it in 10 seconds
The semantic layer
This YAML is the entire contract between the agent and your database. Review it like code.
Ask for a join that isn't defined and you get unreachable_entity, not an invented relationship. Ask to group a metric by a dimension that isn't listed and you get dimension_not_allowed. Misspell a metric or field and the error lists what does exist, with the closest spellings, so an agent corrects itself in one turn instead of making a second discovery call.
Tools exposed to the agent
Filters are {field, op, value}; operators are =, !=, <, <=, >, >=, like, in, not in, is null, is not null. Values are always bound parameters, never inlined.
Wire it into an MCP client
The semantic layer YAML lives wherever you point SQL_STEWARD_LAYER. Claude Desktop (claude_desktop_config.json):
SQL_STEWARD_DB_URL is a SQLAlchemy URL, so the same server reads SQL Server (mssql+pyodbc://...), Postgres (postgresql+psycopg://...) or SQLite (sqlite:///path.db). Install the matching driver with the extras: pip install "sql-steward[postgres]" or "[mssql]".
Optional: the rest of the stack
The semantic layer is the primary control. These are extra layers, all opt-in, and no-ops if the library isn't installed:
Semantic search (pgvector)
Give an entity a search block pointing at a pgvector column and the agent gets a semantic_search tool, governed exactly like everything else (PII refused, results masked, calls audited):
The query text is embedded locally (set SQL_STEWARD_EMBED_URL to a local Ollama endpoint, so nothing leaves the building), and matched with pgvector's <=> operator. PostgreSQL only. The embedding column is never returned.
- query-warden re-checks the compiled SQL against a role policy.
- pii-veil masks any PII that survives into result rows.
- agent-blackbox records every call in a hash-chained ledger;
sql-steward audit-verifychecks it.
Security model
sql-steward governs the path from the model to your database. It assumes the process that calls its tools is trusted. That boundary is the difference between deploying it safely and exposing it, so it is worth stating plainly.
What it enforces, whatever the model asks. Every call runs the same gate: read-only by construction, blocked PII refused before retrieval, an optional role check via query-warden, results masked by pii-veil, and a hash-chained audit of the call. A jailbroken model still cannot write, cannot read a blocked column, and cannot reach an entity the layer does not define. These hold by construction, not by trusting the model to behave.
What it does not do. sql-steward is an enforcement plane, not a front door.
- It does not authenticate the caller.
SQL_STEWARD_ROLEis configuration, not a verified identity; sql-steward trusts that the role it is handed is the correct one. - It does not resolve per-user permissions. If different users should see different data, the caller maps the user to a role and sets it before invoking. The role check enforces a policy, it does not decide who you are.
- It does not secure transport. Run it over stdio to a local host, or place it behind something that terminates TLS.
- It does not manage secrets.
SQL_STEWARD_DB_URLand the audit keyAGENT_BLACKBOX_KEYare read from the environment; supply them from a secret store, not a checked-in file.
What you provide. sql-steward is built to sit behind a trusted caller, whether that is an MCP host on the same machine or a gateway that has already authenticated the user.
- Invoke it from a trusted process: a subprocess of an MCP host you control (stdio), or a service behind a gateway that authenticates the request and maps the verified identity to a role before the call.
- Give it a least-privilege, read-only database account. Writes are unrepresentable in the compiler, but a read-only grant is defense in depth and the right blast radius if a dependency is ever wrong.
- Keep the database and any local embedding endpoint on a private network. Do not expose the server to untrusted callers.
- Treat the connection string and the audit key as secrets.
The threat it is built for. The design assumes a capable, possibly compromised model and a trusted operator. It bounds what the agent can do with your database. It does not replace your identity provider and is not meant to face an untrusted network alone. Point it at a real database from behind a host or gateway you trust, and the three guarantees are what the model is left with.
How this is different
A typical SQL MCP validates arbitrary SQL the model wrote (a blocklist: catch what's bad). sql-steward compiles SQL from definitions you wrote (an allow-list: only what's described exists). The read-only and PII guarantees hold by construction rather than by inspection, and the query surface is the same across three engines.
Versus a semantic layer (Cube, dbt Semantic Layer, Cortex Analyst, Genie)
The nearest tools are not other MCP servers, they are semantic layers. Cube and the dbt Semantic Layer already expose compiled, metric-only access, and Snowflake Cortex Analyst and Databricks Genie both answer natural-language questions over a governed model. If you run on their platform, use them. This project exists for the case they do not cover:
- On-prem and air-gappable. sql-steward is a pip install that talks to SQL Server, Postgres or SQLite with no account, no warehouse, and no data leaving the building. Cortex Analyst is Snowflake, Genie is Databricks, and Cube's cloud features assume their service. For a factory or a hospital that cannot send data to a vendor, that difference is the whole decision.
- PII refused before retrieval, at the same chokepoint. A blocked field is refused at compile time for every caller, so the model cannot read what policy forbids even to reason over. Semantic layers govern which metrics you can query; they are not built to guarantee a tagged column never reaches the model.
- One tamper-evident audit for the whole agent, not just SQL. The same gate pattern wraps KQL, document retrieval and agent memory in the composed stack, under one hash-chained ledger. A warehouse semantic layer governs the warehouse; it does not govern the agent's other tools.
Short version: a semantic layer makes queries safe on its platform. sql-steward makes an agent safe on your infrastructure, across every surface it can reach.
That difference does not mean living on an island. The industry is converging on Apache Ossie (the Open Semantic Interchange format, incubating at the ASF, started by the Snowflake, dbt and Salesforce working group) as the neutral way to move semantic models between tools, and sql-steward speaks it:
Entities, joins and metrics map to OSI datasets, relationships and metrics.
OSI has no governance vocabulary yet, so the parts that make the layer a
contract rather than a catalog, the PII tags, the policy block, metric
allow-lists and checks, travel in custom_extensions under
vendor_name: SQL_STEWARD; anything that cannot be represented is reported
as a note on stderr instead of dropped silently. The output passes Ossie's
own validator, so a layer written for sql-steward can be handed to anything
that reads the standard.
Scaling to a real schema
The semantic layer is authored by hand on purpose, so it reads and reviews like code. That is the right default for tens of tables and the wrong one for thousands: nobody hand-writes a layer for a 10,000-table ERP, and returning the whole layer in one list_entities call would not fit an agent's context anyway. How that scales:
-
Bootstrap, then review.
sql-steward init --from-db <url>reflects a live schema, maps column types, proposes PII tags from column-name heuristics (biased toward over-tagging, so a leak is a review edit rather than a default), and infers joins from foreign keys. It emits a draft layer that loads and validates as-is, with a header that tells you what to narrow. The point is not to auto-expose everything; it is to remove the blank-page problem so a large schema starts as a reviewable file, not a hand-typed one. -
Scope beats size. A governed layer should expose the handful of entities an agent actually needs, not the whole database. A 10,000-table schema still becomes a 20-entity contract; the discipline is deciding what belongs (use
--include/--excludeto draft only a slice), which is a feature of the model, not a limit of the tool. -
Discovery grows with the layer.
list_entities/describe_entityare browsed as the layer grows; search and paging on those responses is the next edge to close before this points at a very large single layer.
Develop
License
MIT
Source: README.md at commit 18926b0
Tools
0Version history
1- v0.4.0LatestSep 16, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts