pg-semantic-mcp
A read-only PostgreSQL MCP server for AI coding agents that exposes database schema and sample data as tools, with LLM-powered semantic search enriched by a user-authored semantic layer.
README
pg-semantic-mcp
A PostgreSQL MCP server for AI coding agents.
Exposes your database schema — table names, column types, comments, and sample data — as MCP tools. Includes semantic search powered by any OpenAI-compatible LLM, enriched by a user-authored semantic layer document.
Features
- list_tables — discover all tables with comments
- describe_table — inspect column names, types, nullability, and comments
- sample_data — fetch example rows from any table
- search_schema — keyword search across tables and columns using LLM + your semantic context
No SQL execution. Read-only. No vector database required.
Install
pip install pg-semantic-mcp
Requires Python 3.11+ and a running PostgreSQL instance.
Quick Start
export DATABASE_URL="postgresql://user:pass@localhost:5432/mydb"
export LLM_API_KEY="sk-..." # required only for search_schema
pg-semantic-mcp
Configuration
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL |
yes | — | PostgreSQL connection string |
SEMANTIC_FILE |
no | — | Path to your semantic layer markdown |
LLM_BASE_URL |
no | https://api.openai.com/v1 |
OpenAI-compatible endpoint |
LLM_API_KEY |
no | — | Required for search_schema |
LLM_MODEL |
no | gpt-4o-mini |
LLM model name |
CACHE_REFRESH_MINUTES |
no | 30 |
Background cache refresh interval |
CACHE_SCHEMAS |
no | all | Comma-separated schema names to cache |
SAMPLE_DATA_LIMIT |
no | 5 |
Default row count for sample_data |
You can also use a .env file in the working directory.
Register with OpenCode
Add to your opencode.json:
{
"mcp": {
"pg-data": {
"type": "local",
"command": "pg-semantic-mcp",
"env": {
"DATABASE_URL": "postgresql://user:pass@host:5432/dbname",
"SEMANTIC_FILE": "/path/to/SCHEMA.md",
"LLM_API_KEY": "sk-..."
}
}
}
}
The same config works for Claude Code, Cursor, and any other MCP-compatible agent.
Semantic Layer
Create a SCHEMA.md file describing your database — naming conventions,
business term mappings, design decisions. See
SCHEMA.md.example for a template.
This document is loaded at startup and included in the search_schema LLM
prompt. It is the main way to teach the agent about your specific domain.
Compatible LLMs
search_schema calls any OpenAI-compatible endpoint:
- OpenAI (
gpt-4o-mini,gpt-4o, ...) - DeepSeek (
deepseek-v4, setLLM_BASE_URL=https://api.deepseek.com/v1) - Anthropic via proxy
- Local models via Ollama or LM Studio
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.