Skip to main content
Glama
chncaesar

pg-semantic-mcp

by chncaesar

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.

Related MCP server: dbecho

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, set LLM_BASE_URL=https://api.deepseek.com/v1)

  • Anthropic via proxy

  • Local models via Ollama or LM Studio

License

MIT

Install Server
A
license - permissive license
A
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

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

  • A
    license
    -
    quality
    C
    maintenance
    A 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 updated
    170
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    An 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.
    Last updated
    11
    5
    MIT

View all related MCP servers

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

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/pg-semantic-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server