Semantic PostgreSQL MCP Server
A PostgreSQL MCP server with semantic search capabilities for AI chatbots
cpenniman12
README
Semantic PostgreSQL MCP Server
A Model Context Protocol (MCP) server that enables AI assistants like Claude to perform semantic search on PostgreSQL databases.
What is MCP?
Model Context Protocol (MCP) is an open standard developed by Anthropic that connects AI assistants to external systems where data lives, including databases, content repositories, and business tools. It provides a standardized way for AI models to interact with external systems through a client-server architecture.
What This MCP Server Does
This MCP server connects Claude (or any MCP-compatible AI assistant) to a PostgreSQL database with semantic search capabilities. It allows the AI assistant to:
- Understand your database structure semantically: The server uses vector embeddings to understand the meaning and purpose of tables and columns, not just their names.
- Execute natural language queries: Users can ask questions in plain English and get relevant SQL queries executed.
- Perform hybrid search: Combines keyword matching with semantic understanding for more accurate results.
- Provide context-aware responses: The AI has access to comprehensive metadata about your database schema.
Key Features
- Vector-based semantic search: Uses OpenAI's embeddings to understand semantic meaning.
- Metadata-driven: Stores rich descriptions of tables and columns in vector format.
- No schema modification needed: Your existing database tables remain unchanged; metadata is stored separately.
- Simple integration with Claude Desktop: Easy configuration with Claude Desktop.
Prerequisites
- PostgreSQL 13+ with pgvector extension
- Node.js 18+
- OpenAI API key (for generating embeddings)
- Claude Desktop (or any MCP-compatible client)
Installation
1. Database Setup
First, install PostgreSQL and the pgvector extension. Then run the schema.sql
script to create the necessary tables and sample data:
psql -U postgres -f schema.sql
2. MCP Server Setup
# Clone this repository
git clone https://github.com/cpenniman12/semantic-postgres-mcp.git
cd semantic-postgres-mcp
# Install dependencies
npm install
# Configure environment variables
cp .env.example .env
# Edit .env with your PostgreSQL and OpenAI credentials
# Start the server
npm start
3. Configure Claude Desktop
Add the following to your Claude Desktop configuration file (typically at ~/Library/Application Support/Claude/claude_desktop_config.json
):
{
"mcpServers": {
"semantic-postgres": {
"command": "node",
"args": ["/path/to/your/semantic-postgres-mcp/index.js"],
"env": {
"OPENAI_API_KEY": "your-openai-api-key"
}
}
}
}
Restart Claude Desktop to connect to the MCP server.
Usage Examples
Once set up, you can ask Claude questions like:
- "Show me all customer information"
- "What products are currently low in stock?"
- "Find orders with a total amount over $1000"
- "Show me the relationship between customers and orders"
Claude will use the semantic search capabilities to understand your request, find the relevant tables and columns, and execute the appropriate SQL query.
How It Works
- Metadata Storage: The system stores detailed descriptions of your database schema (tables, columns, relationships) with vector embeddings.
- Query Understanding: When you ask a question, the system converts it to an embedding and finds semantically similar columns/tables.
- SQL Generation: Based on the matched metadata, the system generates appropriate SQL queries.
- Result Presentation: The results are formatted and presented to the user in a readable format.
Project Structure
index.js
- Main MCP server implementationschema.sql
- Database schema with metadata tables and sample data.env.example
- Example environment configurationpackage.json
- Node.js dependencies
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
Recommended Servers
Crypto Price & Market Analysis MCP Server
A Model Context Protocol (MCP) server that provides comprehensive cryptocurrency analysis using the CoinCap API. This server offers real-time price data, market analysis, and historical trends through an easy-to-use interface.
MCP PubMed Search
Server to search PubMed (PubMed is a free, online database that allows users to search for biomedical and life sciences literature). I have created on a day MCP came out but was on vacation, I saw someone post similar server in your DB, but figured to post mine.
dbt Semantic Layer MCP Server
A server that enables querying the dbt Semantic Layer through natural language conversations with Claude Desktop and other AI assistants, allowing users to discover metrics, create queries, analyze data, and visualize results.
mixpanel
Connect to your Mixpanel data. Query events, retention, and funnel data from Mixpanel analytics.

Sequential Thinking MCP Server
This server facilitates structured problem-solving by breaking down complex issues into sequential steps, supporting revisions, and enabling multiple solution paths through full MCP integration.

Nefino MCP Server
Provides large language models with access to news and information about renewable energy projects in Germany, allowing filtering by location, topic (solar, wind, hydrogen), and date range.
Vectorize
Vectorize MCP server for advanced retrieval, Private Deep Research, Anything-to-Markdown file extraction and text chunking.
Mathematica Documentation MCP server
A server that provides access to Mathematica documentation through FastMCP, enabling users to retrieve function documentation and list package symbols from Wolfram Mathematica.
kb-mcp-server
An MCP server aimed to be portable, local, easy and convenient to support semantic/graph based retrieval of txtai "all in one" embeddings database. Any txtai embeddings db in tar.gz form can be loaded
Research MCP Server
The server functions as an MCP server to interact with Notion for retrieving and creating survey data, integrating with the Claude Desktop Client for conducting and reviewing surveys.