pg-semantic-mcp
pg-semantic-mcp is a read-only MCP server for AI coding agents that exposes database schema information for PostgreSQL or SQL Server without executing SQL. Core capabilities: list tables with comments, describe columns (names, types, nullability), fetch sample rows, and perform semantic schema search using natural language via any OpenAI-compatible LLM (optionally enhanced by a user-authored semantic layer document). The server requires no vector database and operates entirely read-only.
Can use local LLM models served by Ollama for semantic schema search.
Uses OpenAI-compatible LLM APIs, including GPT models, to power semantic search across the database schema.
Exposes PostgreSQL database schema (tables, columns, comments) and sample data as MCP tools, with semantic search over the schema.
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., "@pg-semantic-mcpShow me the schema for the orders table"
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.
db-semantic-mcp
A multi-backend MCP server for AI coding agents — supports both PostgreSQL and SQL Server.
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.
No SQL execution. Read-only. No vector database required.
Backends
Backend | Scheme | Driver | Required Extras |
PostgreSQL |
| asyncpg | (built-in) |
SQL Server |
| pymssql |
|
The backend is auto-detected from DATABASE_URL. Everything else works the same.
Related MCP server: dbecho
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 — semantic keyword search across tables and columns using LLM
Install
# PostgreSQL only
pip install db-semantic-mcp
# With SQL Server support
pip install "db-semantic-mcp[sqlserver]"Requires Python 3.11+.
Quick Start
# PostgreSQL
export DATABASE_URL="postgresql://user:pass@localhost:5432/mydb"
# SQL Server (Kingdee ERP or any MSSQL instance)
export DATABASE_URL="sqlserver://user:pass@host:1433?database=mydb&encrypt=disable"
export LLM_API_KEY="sk-..." # required only for search_schema
pg-semantic-mcpConfiguration
Variable | Required | Default | Description |
| yes | — | PostgreSQL or SQL Server connection string |
| no | — | Path to your semantic layer markdown |
| no |
| OpenAI-compatible endpoint |
| no | — | Required for |
| no |
| LLM model name |
| no |
| Background cache refresh interval |
| no | all | Comma-separated schema names to cache |
| no | — | Comma-separated table name prefixes to cache |
| no |
| Default row count for |
You can also use a .env file in the working directory.
Register with OpenCode
Add to your opencode.jsonc:
{
"mcp": {
"pg-data": {
"type": "local",
"command": "pg-semantic-mcp",
"environment": {
"DATABASE_URL": "postgresql://user:pass@host:5432/dbname",
"SEMANTIC_FILE": "/path/to/SCHEMA.md",
"LLM_API_KEY": "sk-..."
}
}
}
}Same config format works for Claude Code, Cursor, and any 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
Maintenance
Related MCP Servers
- 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.36MIT
- AlicenseAqualityAmaintenanceAn MCP server that gives AI agents direct read-only access to PostgreSQL databases, enabling natural language analytics through tools for schema exploration, querying, trend analysis, and data quality checks.115MIT
- Flicense-qualityFmaintenanceA read-only MCP server that enables AI agents to explore database schemas and execute safe queries on PostgreSQL and MySQL.
- AlicenseAqualityCmaintenanceA read-only MCP server that provides AI coding tools with database schema structure (tables, columns, keys, relationships) without exposing row data.3Apache 2.0
Related MCP Connectors
Analytical memory for AI agents: a real Postgres queried in plain English over MCP. One command.
GibsonAI MCP server: manage your databases with natural language
Reddit & X data for AI agents over MCP. Semantic search, hosted, no Reddit API.
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/chncaesar/db-semantic-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server