tai42-mcp-dynamic-postgres
Schema-driven generator for safe, scoped PostgreSQL DML tools in FastMCP agent systems.
Point it at a PostgreSQL database and it introspects the schema and generates one
typed MCP tool per DML operation per table — insert, select, update,
delete, plus optional select_joined. The agent gets exactly those tools and
nothing else: no raw SQL, no schema changes, no access to tables you didn't
expose.
Why
Giving an agent database access usually means choosing between read-only access or risking that the agent runs arbitrary SQL and changes data or settings you never intended. This project gives you a controlled middle ground: a fixed set of generated, validated, parameterized tools scoped to the tables and operations you choose.
What it does
- Introspects your schema (tables, columns, types, foreign keys,
pgvector). - Generates a FastMCP tool per DML operation per table, each with a dedicated Pydantic input model derived from the table.
- Supports rich, injection-safe filtering (
WhereFilter) and ordering, including vector KNN search. - Excludes chosen columns from generated tool inputs (e.g.
id,created_at). - Exposes only the generated tools — never raw SQL or DDL.
Security model
[!IMPORTANT] The generated tool layer controls which operations exist; the PostgreSQL role you connect as controls what those operations can physically do. Connect as a dedicated least-privilege role, never a superuser. Read SECURITY.md before deploying.
Highlights, in full detail in SECURITY.md:
- Filter/order field names are validated against real columns and emitted only as quoted identifiers; values are always bound parameters. There is no path for SQL injection through field names.
update/deleterequire aWHEREfilter unless the server is started with--allow-unfiltered.- The tool layer does not provide row-level scoping. Use PostgreSQL
Row-Level Security and
GRANT/REVOKEfor that.
Installation
Requires Python 3.13+. Install from PyPI into the environment that runs the server, or run it without installing:
uv add tai42-mcp-dynamic-postgres
uvx tai42-mcp-dynamic-postgres # run it without installing
Or from source — clone this repo and add it as an editable dependency, or run
the clone with uvx:
git clone https://github.com/tai42ai/tai42-mcp-dynamic-postgres # next to your app checkout
cd /path/to/your/app
uv add --editable ../tai42-mcp-dynamic-postgres
uvx --from ../tai42-mcp-dynamic-postgres tai42-mcp-dynamic-postgres
Documentation
Full reference — every connection and pooling variable, the CLI scoping flags,
stdio and HTTP transport wiring, the generated-tool surface, WhereFilter
filtering, and pgvector search — lives on the plugin's documentation page. See
also SECURITY.md before deploying.
Development
See CONTRIBUTING.md.
uv venv --python 3.13
uv pip install --no-sources --editable ".[dev,test-integration]"
uv run --no-sync ruff check .
uv run --no-sync ruff format --check .
uv run --no-sync pyright
uv run --no-sync pytest --cov --cov-report=term-missing # unit tests
uv run --no-sync pytest -m integration # CRUD tests against real Postgres (needs Docker)
License
Apache-2.0. See LICENSE and NOTICE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tai42_mcp_dynamic_postgres-0.5.0.tar.gz.
File metadata
- Download URL: tai42_mcp_dynamic_postgres-0.5.0.tar.gz
- Upload date:
- Size: 36.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2cfdab99cab15615a773bceef193ebd899a9de7bf4f2cf1470da9c22ab8ceb2e
|
|
| MD5 |
d0543f054981ab5d47b13fea5ff0a346
|
|
| BLAKE2b-256 |
95d00fd5782c25bd33bbc0806bd4c9d6225347e0e4b11a4e00c9a7924f3b07ba
|
File details
Details for the file tai42_mcp_dynamic_postgres-0.5.0-py3-none-any.whl.
File metadata
- Download URL: tai42_mcp_dynamic_postgres-0.5.0-py3-none-any.whl
- Upload date:
- Size: 49.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
804872fe2b7a47364e3cd88500acf07bc2adf78f68bb763c63d8e916173a9943
|
|
| MD5 |
66f87263faf870bb3e7af096ec6f3b3a
|
|
| BLAKE2b-256 |
9794ff5b5992d616802f4653dc3d84fdf6434a2a5c46aba6ecc8402e6f0aaf69
|