Postgres Schema MCP
MCP server that gives AI agents only the relevant slice of a wide Postgres schema
Postgres Schema MCP is an open-source MCP server for databases. It runs locally on your machine and is started by your AI client.
- Pricing
- Open source
- Platforms
- CLI, Self-hosted, API
- Runs
- Locally
- What it can do
- Can change data (1 tool)
- Version
- 0.1.2
Similar MCP servers
Install
Add with the CLI
Run in a terminal
claude mcp add postgres-schema-mcp -- uvx postgres-schema-mcpAdd --scope user to use it in every project, or --scope project to share it in .mcp.json.
Or share it with your project
Add to .mcp.json
{
"mcpServers": {
"postgres-schema-mcp": {
"command": "uvx",
"args": [
"postgres-schema-mcp"
]
}
}
}Add to claude_desktop_config.json
{
"mcpServers": {
"postgres-schema-mcp": {
"command": "uvx",
"args": [
"postgres-schema-mcp"
]
}
}
}Settings → Developer → Edit Config, then quit and reopen Claude Desktop.
Add to ~/.cursor/mcp.json
{
"mcpServers": {
"postgres-schema-mcp": {
"command": "uvx",
"args": [
"postgres-schema-mcp"
]
}
}
}Use .cursor/mcp.json in a project to share it with the project.
Add to ~/.copilot/mcp-config.json
{
"mcpServers": {
"postgres-schema-mcp": {
"type": "stdio",
"command": "uvx",
"args": [
"postgres-schema-mcp"
]
}
}
}Or put the same entry in .mcp.json at your workspace root to share it.
Add with the CLI
Run in a terminal
codex mcp add postgres-schema-mcp -- uvx postgres-schema-mcpOr add to config.toml
Add to ~/.codex/config.toml
[mcp_servers.postgres-schema-mcp]
command = "uvx"
args = ["postgres-schema-mcp"]Add to your client's MCP settings (most use this shape)
{
"mcpServers": {
"postgres-schema-mcp": {
"command": "uvx",
"args": [
"postgres-schema-mcp"
]
}
}
}Gemini CLI and Antigravity
Gemini CLI
Add to ~/.gemini/settings.json
{ "mcpServers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }Or run: gemini mcp add -s user postgres-schema-mcp uvx -- postgres-schema-mcp
Antigravity
Add to ~/.gemini/config/mcp_config.json
{ "mcpServers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }Use .agents/mcp_config.json to add it to one workspace only.
Devin Desktop (formerly Windsurf)
Add to ~/.config/devin/mcp_config.json
{ "mcpServers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }On Windows the file is %APPDATA%\devin\mcp_config.json. Use .devin/mcp_config.json to share it with a project.
Cline
Add to cline_mcp_settings.json
{ "mcpServers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }Open it from the MCP Servers icon → Configure → Configure MCP Servers.
Zed
Add to Zed settings.json
{ "context_servers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }Open it with zed: open settings file. Merge context_servers into the settings you already have.
JetBrains AI Assistant and Junie
AI Assistant
Add to Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add
{ "mcpServers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }Junie
Add to ~/.junie/mcp/mcp.json
{ "mcpServers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }Use .junie/mcp/mcp.json to share it with a project.
Kiro
Add to ~/.kiro/settings/mcp.json
{ "mcpServers": { "postgres-schema-mcp": { "command": "uvx", "args": [ "postgres-schema-mcp" ] } } }Use .kiro/settings/mcp.json to add it to one workspace only.
Using several servers? Build one config file with the MCP config generator.
About Postgres Schema MCP
Rather than handing an agent a full schema dump that can be truncated or overflow the context window, this server ranks tables against the question being asked and returns the subset most likely needed, along with the foreign-key neighbours that make joins possible. A separate describe_table tool fetches any table by name when ranking misses it.
Queries are gated in three layers: a SQL parser that accepts only a single read-only SELECT, and a database role limited to SELECT with session and resource limits. The tool annotations are treated as documentation rather than enforcement, which the README states explicitly.
The project suits developers connecting coding or analytics agents to a large Postgres database who want fewer schema tokens per request and a guarded read path. Its published measurements come from the AdventureWorks sample schema, so results on other schemas will differ.
Tools this server provides (4)
Taken from the project documentation; the running server may differ.
From the tool list in its README, going by the names, 1 of 4 tools changes data.
From the server's own tool labels and tool names; not verified by us.
- search_schemaName suggests: reads
- Ranks schema tables against a natural-language question and returns a slice.
- describe_tableName suggests: reads
- Returns detail for a table by name.
- explain_queryName suggests: reads
- Returns the query plan for a SQL statement.
- run_queryName suggests: changes
- Runs a read-only SQL query with a row limit.
What it does
- Relevant schema retrieval
- Ranks tables against the question with BM25 and adds a damped boost from foreign-key neighbours so joinable tables appear together.
- Direct table lookup
- A describe_table tool returns any table by name, bypassing ranking when a needed table falls below the cutoff.
- Layered read-only enforcement
- Combines an AST-based SQL guard, a SELECT-only database role and transaction settings that force read-only access.
- Query plan inspection
- An explain_query tool returns the execution plan for a SQL statement without running it.
- Bounded result sets
- Row count, per-cell and total size caps apply to query results, and the model is told when a cut occurs.
- Local or HTTP transport
- Runs over stdio by default and can serve Streamable HTTP instead.
Good for
- Letting a coding agent write SQL against a large production-style schema without loading every table definition
- Giving an analytics assistant read-only access to a Postgres database
- Reducing schema context tokens on each request for wide databases
- Exploring unfamiliar tables by name and inspecting their structure before querying
Pricing
Open source
Free and open source under the MIT licence.
More servers for the same service
Postgres Schema MCP FAQ
Can the server modify data?
The server is built to be read-only. Queries pass an AST check that rejects anything other than a single SELECT, and the database role used holds only SELECT privileges.
How is Postgres Schema MCP installed?
It is available on PyPI and can be run with uvx using the postgres-schema-mcp command, with PGSS_DSN set to a database connection string for a role that can only SELECT.
What tools does Postgres Schema MCP expose?
Four tools: search_schema, describe_table, explain_query and run_query.
What is the token saving?
On the AdventureWorks benchmark with 68 tables, the mean retrieved slice was about 1,816 tokens against 10,927 for the full schema DDL, a reduction of roughly 83 percent for schema context only.
Is Postgres Schema MCP free?
Yes. Postgres Schema MCP is open source, so you can use and self-host it for free.
How do I add Postgres Schema MCP to Claude Code?
Run this command in your terminal: claude mcp add postgres-schema-mcp -- uvx postgres-schema-mcp
What are the best alternatives to Postgres Schema MCP?
The closest alternatives to Postgres Schema MCP are Postgres MCP, PostgreSQL MCP Server, Postgres MCP, Postgres MCP and Dbridge MCP.
Where this comes from
- Description: written from the project's README and its MCP Registry entry.
- Install steps: from the official MCP Registry entry.