Labsco
leixiaotian1 logo

PostgreSQL

β˜… 11

from leixiaotian1

An MCP server for interacting with a PostgreSQL database.

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredAdvanced setup

PostgreSQL MCP Server

GoDoc Stars Forks

δΈ­ζ–‡ | English

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

✨ Features

  • Interact with Databases via AI: Enables LLMs to perform database operations through a structured protocol.
  • Secure Toolset: Separates read and write operations into distinct, authorizable tools (read_query, write_query).
  • Schema Management: Allows for table creation (create_table) and listing (list_tables).
  • Query Analysis: Provides a tool to analyze query execution plans (explain_query).
  • Multiple Transport Modes: Supports stdio, Server-Sent Events (sse), and streamableHttp for flexible client integration.
  • Environment-Based Configuration: Easily configurable using a .env file.

πŸ› οΈ Available Tools

The server exposes the following tools for MCP clients to invoke:

Tool NameDescriptionParameters
read_queryExecutes a SELECT SQL query.query (string, required): The SELECT statement to execute.
write_queryExecutes an INSERT, UPDATE, or DELETE SQL query.query (string, required): The INSERT/UPDATE/DELETE statement to execute.
create_tableExecutes a CREATE TABLE SQL statement.schema (string, required): The CREATE TABLE statement.
list_tablesLists all user-created tables in the database.schema (string, optional): The schema name to filter tables by.
explain_queryReturns the execution plan for a given SQL query.query (string, required): The query to explain (must start with EXPLAIN).

πŸ”Œ Server Modes

You can select the transport protocol by setting the SERVER_MODE environment variable.

stdio

The server communicates over standard input and output. This is the default mode and is ideal for local testing or direct integration with command-line-based MCP clients.

sse

The server communicates using Server-Sent Events (SSE). When this mode is enabled, the server will start an HTTP service and listen for connections.

  • SSE Endpoint: http://localhost:8088/sse
  • Message Endpoint: http://localhost:8088/message

streamableHttp

The server uses the Streamable HTTP transport, a more modern and flexible HTTP-based transport for MCP.

  • Endpoint: http://localhost:8088/mcp

🀝 Contributing

Contributions are welcome! If you find any bugs, have feature requests, or suggestions for improvement, please feel free to submit a Pull Request or open an Issue.

  1. Fork the Project.
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature).
  3. Commit your Changes (git commit -m 'Add some AmazingFeature').
  4. Push to the Branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

πŸ“„ License

This project is open source and is licensed under the MIT License.