Cover image
Try Now
2025-04-06

具有语义搜索功能的AI聊天机器人的PostgreSQL MCP服务器

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

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

相关推荐

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • https://reddgr.com
  • Delivers concise Python code and interprets non-English comments

  • apappascs
  • 发现市场上最全面,最新的MCP服务器集合。该存储库充当集中式枢纽,提供了广泛的开源和专有MCP服务器目录,并提供功能,文档链接和贡献者。

  • ShrimpingIt
  • MCP系列GPIO Expander的基于Micropython I2C的操作,源自ADAFRUIT_MCP230XX

  • pontusab
  • 光标与风浪冲浪社区,查找规则和MCP

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • jae-jae
  • MCP服务器使用剧作《无头浏览器》获取网页内容。

  • Mintplex-Labs
  • 带有内置抹布,AI代理,无代理构建器,MCP兼容性等的多合一桌面和Docker AI应用程序。

  • ravitemer
  • 一个功能强大的Neovim插件,用于管理MCP(模型上下文协议)服务器

  • GeyserMC
  • 与Minecraft客户端/服务器通信的库。

  • patruff
  • Ollama和MCP服务器之间的桥梁,使本地LLMS可以使用模型上下文协议工具

    Reviews

    3 (1)
    Avatar
    user_SKTJHa9Y
    2025-04-18

    The semantic-postgres-mcp by cpenniman12 is a game-changer for managing semantic data within PostgreSQL. It effectively combines the power of databases with semantic processing capabilities, making data handling more intuitive and efficient. Highly recommended for anyone dealing with complex data relationships! Check it out on GitHub: https://github.com/cpenniman12/semantic-postgres-mcp.