Sponsored by Deepsite.site

Semantic PostgreSQL MCP Server

Created By
cpenniman128 months ago
A PostgreSQL MCP server with semantic search capabilities for AI chatbots
Content

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

  1. Metadata Storage: The system stores detailed descriptions of your database schema (tables, columns, relationships) with vector embeddings.
  2. Query Understanding: When you ask a question, the system converts it to an embedding and finds semantically similar columns/tables.
  3. SQL Generation: Based on the matched metadata, the system generates appropriate SQL queries.
  4. Result Presentation: The results are formatted and presented to the user in a readable format.

Project Structure

  • index.js - Main MCP server implementation
  • schema.sql - Database schema with metadata tables and sample data
  • .env.example - Example environment configuration
  • package.json - Node.js dependencies

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
ChatWiseThe second fastest AI chatbot™
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
CursorThe AI Code Editor
Playwright McpPlaywright MCP server
Tavily Mcp
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
DeepChatYour AI Partner on Desktop
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Amap Maps高德地图官方 MCP Server
WindsurfThe new purpose-built IDE to harness magic
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Serper MCP ServerA Serper MCP Server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.