MCP cover image
See in Github
2025-03-23

一款用golang实现的操作pg数据库的pg数据库的mcp服务器,支持创建表、查询表、插入数据等,欢迎

1

Github Watches

1

Github Forks

1

Github Stars

PostgreSQL MCP Server

A Model Context Protocol (MCP) server that provides tools for interacting with a PostgreSQL database. This server enables AI assistants to execute SQL queries, create tables, and list database tables through the MCP protocol.

Features

The server provides the following tools:

  • read_query: Execute SELECT queries on the PostgreSQL database
  • write_query: Execute INSERT, UPDATE, or DELETE queries on the PostgreSQL database
  • create_table: Create a new table in the PostgreSQL database
  • list_tables: List all user tables in the database (with optional schema filtering)

Installation

Prerequisites

  • Go 1.23 or later
  • PostgreSQL database server

Steps

  1. Clone the repository:

    git clone https://github.com/sql-mcp-server.git
    cd sql-mcp-server
    
  2. Install dependencies:

    go mod download
    
  3. Build the server:

    go build -o sql-mcp-server
    

Configuration

The server requires database connection details through environment variables. Create a .env file in the project root with the following variables:

DB_HOST=localhost      # PostgreSQL server host
DB_PORT=5432           # PostgreSQL server port
DB_NAME=postgres       # Database name
DB_USER=your_username  # Database user
DB_PASSWORD=your_pass  # Database password
DB_SSLMODE=disable     # SSL mode (disable, require, verify-ca, verify-full)

Usage

Running the Server

./sql-mcp-server

MCP Configuration

To use this server with an AI assistant that supports MCP, add the following to your MCP configuration:

{
  "mcpServers": {
    "pgsql-mcp-server": {
      "command": "/path/to/sql-mcp-server",
      "args": [],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "5432",
        "DB_NAME": "postgres",
        "DB_USER": "your_username",
        "DB_PASSWORD": "your_password",
        "DB_SSLMODE": "disable"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

Tool Examples

List Tables

List all user tables in the database:

{
  "server_name": "pgsql-mcp-server",
  "tool_name": "list_tables",
  "arguments": {}
}

List tables in a specific schema:

{
  "server_name": "pgsql-mcp-server",
  "tool_name": "list_tables",
  "arguments": {
    "schema": "public"
  }
}

Create Table

Create a new table:

{
  "server_name": "pgsql-mcp-server",
  "tool_name": "create_table",
  "arguments": {
    "schema": "CREATE TABLE users (id SERIAL PRIMARY KEY, name VARCHAR(100), email VARCHAR(100) UNIQUE, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP)"
  }
}

Read Query

Execute a SELECT query:

{
  "server_name": "pgsql-mcp-server",
  "tool_name": "read_query",
  "arguments": {
    "query": "SELECT * FROM users LIMIT 10"
  }
}

Write Query

Execute an INSERT query:

{
  "server_name": "pgsql-mcp-server",
  "tool_name": "write_query",
  "arguments": {
    "query": "INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com')"
  }
}

Execute an UPDATE query:

{
  "server_name": "pgsql-mcp-server",
  "tool_name": "write_query",
  "arguments": {
    "query": "UPDATE users SET name = 'Jane Doe' WHERE id = 1"
  }
}

Execute a DELETE query:

{
  "server_name": "pgsql-mcp-server",
  "tool_name": "write_query",
  "arguments": {
    "query": "DELETE FROM users WHERE id = 1"
  }
}

Security Considerations

  • The server validates query types to ensure that only appropriate operations are performed with each tool.
  • Input sanitization is performed for schema names to prevent SQL injection.
  • Consider using a dedicated database user with limited permissions for this server.
  • In production environments, enable SSL by setting DB_SSLMODE to require or higher.

Dependencies

License

[Add license information here]

Contributing

[Add contribution guidelines here]

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

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

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

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

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

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

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

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

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

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

  • Alexandru Strujac
  • Efficient thumbnail creator for YouTube videos

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

  • modelcontextprotocol
  • 模型上下文协议服务器

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

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

  • n8n-io
  • 具有本机AI功能的公平代码工作流程自动化平台。将视觉构建与自定义代码,自宿主或云相结合,400+集成。

  • huahuayu
  • 统一的API网关,用于将多个Etherscan样区块链Explorer API与对AI助手的模型上下文协议(MCP)支持。

    Reviews

    3 (1)
    Avatar
    user_o5NZrMwM
    2025-04-15

    As a dedicated user of the WhatsApp MCP Server by piyushgupta53, I have been extremely impressed with its seamless integration and performance. The server offers robust functionalities that enhance my messaging experience, making it reliable for both personal and professional use. The detailed documentation and user-friendly interface make it accessible, even for those new to MCP applications. Highly recommend checking it out!