Schema Sentinel
Analyzes the paired Git repository to track schema churn and migration history, identifying how often and how recently each table's migrations have changed.
Provides read-only tools for inspecting a PostgreSQL schema, including tables, columns, primary and foreign keys, missing indexes, circular foreign keys, table complexity, and ERD generation. Also parses migration files to flag risky database operations without executing them.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Schema SentinelGenerate a schema health report for the last 30 days"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Read-only MCP server that lets an AI agent look at a Postgres db + its paired git repo and just... know what's going on. Schema, ERD, missing indexes, circular FKs, migration risk, git-churn hotspots, all the stuff you'd normally dig up by hand with psql and git log.
Works against any Postgres + repo pair via .env config (connection string + repo path). Not hardcoded to one project.
Why I built this
Two reasons: it's a portfolio piece, and it was my hands-on way of actually learning MCP, schema introspection, static SQL parsing, git analysis, and wiring all of it up as agent-callable tools.
Related MCP server: tusk-mcp
Tools
Tool | Args | What it does |
| — | Tables, columns, PKs, FKs for the connected db |
| — | Flags FK columns with no covering index |
| — | Catches FK cycles across tables, and shows one concrete cycle per group |
| — | Per table: column count, FK fan-in/fan-out, whether it's tangled in a cycle |
| — | Spits out a Mermaid |
|
| Statically parses one migration file and flags risky stuff. Never runs it |
|
| How often, and how recently, each table's migrations changed |
|
| Rolls all of the above into one health report |
What counts as migration risk
check_migration_risk parses the file and flags six patterns:
Pattern | Severity | Why |
| high | irreversible data loss |
| high | rewrites the table, holds a long lock, can silently truncate |
| high | breaks in-flight app code still using the old name mid-deploy |
| high | same, but takes out every FK pointing at the table too |
| medium | fails outright once the table has rows |
| medium | blocks writes for however long the build takes |
Setup
pip install -e .(orpip install -e ".[dev]"to also getpytest).Copy
.env.exampleto.envand fill inSCHEMA_SENTINEL_DB_URL,SCHEMA_SENTINEL_REPO_PATH,SCHEMA_SENTINEL_MIGRATIONS_PATH. The db role has to be read-only, runscripts/setup_readonly_role.sqlagainst your database first if you don't already have one.Run it:
schema-sentinel(installed as a console script), orpython -m schema_sentinel.server. Either way it speaks MCP over stdio.
To wire it into an MCP client, point the client at the console script and hand it the three env vars:
{
"mcpServers": {
"schema-sentinel": {
"command": "schema-sentinel",
"env": {
"SCHEMA_SENTINEL_DB_URL": "postgresql://schema_sentinel_ro@localhost:5432/your_database",
"SCHEMA_SENTINEL_REPO_PATH": "/path/to/your/repo",
"SCHEMA_SENTINEL_MIGRATIONS_PATH": "/path/to/your/repo/migrations"
}
}
}
}Decisions I've locked in
Python +
psycopgv3 (psycopg[binary]) for Postgres.The
mcpSDK's bundled FastMCP (mcp.server.fastmcp) for the server, not the standalonefastmcppackage. Pinned tomcp<2deliberately, see the rough edges below.Mermaid
erDiagramtext for the ERD, no Graphviz, no rendering lib. GitHub and Notion already render Mermaid natively, so why bother.pglast(wrapslibpg_query, Postgres's own C parser) to statically parse migrations.check_migration_riskonly ever parses, never runs, a migration. Non-negotiable.Worth saying why it's
pglastand not a generic multi-dialect parser: I started on one and found it silently gave up on multi-item DDL.ALTER TABLE x DROP COLUMN a, ALTER COLUMN b TYPE intcame back as an unparsed blob, which meant a genuinely dangerous migration would sail through reporting zero risks, andDROP TABLE a, b;raised outright. Both are ordinary SQL.pglastdoesn't approximate the grammar, it is the grammar, so neither is a problem.GitPython for the churn/file-history stuff.
Introspection goes through
pg_catalog, notinformation_schema. Not a style preference:information_schema.table_constraintsand friends gate visibility behind write-ish privileges, so a strictly read-only role sees zero rows there. Which is exactly the role this thing is designed to run as.psycopg3 param binding: list filters use
= ANY(%s), notIN %s. psycopg3 doesn't auto-expand a Python list into a SQLIN (...)the way psycopg2 did. Bit me once, not doing it again.Churn and complexity stay separate. Churn is a pure git signal, complexity is a pure schema signal, neither reaches into the other's half.
generate_reporthands you both.
Security posture (read-only, belt and suspenders)
Enforced in src/schema_sentinel/db/connection.py:
Session-level lock,
SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLYright after connecting, before anything else runs.Startup privilege check, checks
pg_rolesforrolsuper/rolcreatedb/rolcreaterole, andinformation_schema.role_table_grantsfor any non-SELECTgrant on the connecting role. Either one fails, the connection gets closed and it raisesWritableConnectionError, no usable connection handed back, period.scripts/setup_readonly_role.sqlsets up a correctly-scoped read-only role in one step, instead of doing it by hand.
The migration checker never touches the database at all, it only reads files off disk.
Project layout
src/schema_sentinel/
├── config.py env config -> Settings
├── schema.py get_schema_overview, find_missing_indexes,
│ find_circular_foreign_keys, find_table_complexity
├── erd.py generate_erd
├── migrations.py check_migration_risk
├── report.py generate_report
├── server.py MCP entrypoint, registers all 8 tools
├── db/connection.py the read-only gatekeeper
└── git_ops/churn.py find_schema_churn
tests/ mirrors src/, plus tests/test_db/ and tests/test_git_ops/
scripts/ setup_readonly_role.sql, setup_test_db.sqlRunning the tests
Most of the suite is DB-free, but the schema/connection/report tests run against a real local Postgres, since the whole point of the connection tests is proving actual grant enforcement and you can't meaningfully mock that.
createdb schema_sentinel_test
psql -d schema_sentinel_test -f scripts/setup_test_db.sql
pytestsetup_test_db.sql builds the fixture tables (simple and composite PKs, simple and composite FKs, one FK deliberately left unindexed) plus the three roles the connection tests need. Point the SCHEMA_SENTINEL_TEST_* URLs in .env at them. CI does exactly this against a throwaway Postgres container on every push.
Known rough edges
Schema-qualified names get flattened. Churn keys everything by bare table name, so
public.ordersandanalytics.orderswould land in the same bucket. Fine for the single-schema case, wrong for anything fancier.The risk checker knows six patterns. Plenty of other things worth flagging aren't in there yet:
ADD CONSTRAINTwithoutNOT VALID,SET NOT NULLon an existing column, volatileDEFAULTs,VACUUM FULL,CLUSTER.generate_reportre-queries more than it needs to. Several tools callget_schema_overviewor the constraint fetch independently, so a full report hitspg_constrainta handful of times over. Each tool being self-contained was the deliberate tradeoff, but on a big schema it's wasteful.Pinned to
mcp1.x. 2.0 removedmcp.server.fastmcp, which is whatserver.pyis written against, so upgrading means porting the tool registration to whatever replaced it. Pinned rather than rushed.Complexity is a raw count, not a score. Fan-in, fan-out and column count get sorted, not weighted, and nothing multiplies churn against complexity to give you a single "hotspot" number. You get both halves and draw your own conclusions.
License
AGPL-3.0-or-later, full text in LICENSE.
Short version: read it, run it, fork it, learn from it, all fine. But if you distribute a modified version, or run one as a service other people can reach, you have to publish your source too.
Copyright (C) 2026 Ramón Iglesias
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityDmaintenanceA Model Context Protocol server that provides AI assistants with secure, read-only access to PostgreSQL databases while offering comprehensive tools for schema exploration, query validation, and performance optimization.Last updatedMIT
- Alicense-qualityCmaintenanceA read-only PostgreSQL MCP server that enables AI agents to perform schema introspection and execute SELECT-only queries. It supports secure database connections through SSL and SSH tunnels while offering a structure-only mode to restrict query access.Last updated170MIT
- Flicense-qualityFmaintenanceA read-only MCP server that enables AI agents to explore database schemas and execute safe queries on PostgreSQL and MySQL.Last updated
- Alicense-qualityCmaintenanceA zero-config, read-only PostgreSQL MCP server that enforces read-only access at the database level using READ ONLY transactions, allowing AI agents to safely explore schemas and run SELECT queries without risk of mutation.Last updatedMIT
Related MCP Connectors
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
Monitor MCP servers, API contracts and AI outputs for schema drift. Alerts on breaking changes.
MCP server for managing Prisma Postgres.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/ramoniglesias98/schema-sentinel'
If you have feedback or need assistance with the MCP directory API, please join our Discord server