Add your description here
Project description
// Start of Selection
mcp-server-postgresql: A PostgreSQL MCP Server
The Model Context Protocol (MCP) is an open protocol that enables seamless integration between LLM applications and external data sources and tools. Whether you're building an AI-powered IDE, enhancing a chat interface, or creating custom AI workflows, MCP provides a standardized way to connect LLMs with the context they need.
This repository is an example of how to create an MCP server for managing PostgreSQL databases.
Overview
A Model Context Protocol server for interacting with PostgreSQL. It provides tools for executing queries, creating tables, inserting rows of data, and retrieving results.
Components
Tools
The server implements the following tools:
-
execute_query: Execute an arbitrary SQL query- Takes a
querystring - Returns results for SELECT-like statements, or a success message for others
- Takes a
-
create_table: Create a new table- Takes a
nameand aschema(column definitions) - Creates the specified table
- Takes a
-
insert_data: Insert a row of data into a table- Takes a
tablename and adatadict of column values - Inserts the specified row
- Takes a
-
fetch_data: Fetch data by executing a SELECT query- Takes a
querystring - Returns matching rows as a result set
- Takes a
Configuration
The server connects to PostgreSQL using the following environment variables (all are required):
PG_HOST: PostgreSQL hostPG_PORT: PostgreSQL portPG_USER: PostgreSQL userPG_PASSWORD: PostgreSQL passwordPG_DATABASE: PostgreSQL database name
If any of these variables are missing, the server will raise an error during startup. Make sure to set each of these before running the server.
Quickstart
Claude Desktop
On MacOS: ~/Library/Application\ Support/Claude/claude_desktop_config.json
On Windows: %APPDATA%/Claude/claude_desktop_config.json
{
"postgresql": {
"command": "uvx",
"args": [
"mcp-server-postgresql"
]
}
}
Development
Building and Publishing
To prepare the package for distribution:
- Sync dependencies and update lockfile:
uv sync
- Build package distributions:
uv build
This will create source and wheel distributions in the dist/ directory.
- Publish to PyPI:
uv publish
Note: You'll need to set PyPI credentials via environment variables or command flags:
- Token:
--tokenorUV_PUBLISH_TOKEN - Or username/password:
--username/UV_PUBLISH_USERNAMEand--password/UV_PUBLISH_PASSWORD
Debugging
Since MCP servers run over stdio, debugging can be challenging. For the best debugging experience, we strongly recommend using the MCP Inspector.
You can launch the MCP Inspector via npm with this command:
npx @modelcontextprotocol/inspector uv --directory $(PWD) run mcp-server-postgresql
Upon launching, the Inspector will display a URL that you can access in your browser to begin debugging.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_server_postgresql-0.1.8.tar.gz.
File metadata
- Download URL: mcp_server_postgresql-0.1.8.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71a92fc836c22fb4b3d77a90a92545fcb85820ed492501eec76efff0a2f02c76
|
|
| MD5 |
f88387f22f3c9794501f7e0730cb2102
|
|
| BLAKE2b-256 |
234b7325ef10f373a4597bb621720a8303e5ae3755b7b081d3529b8f8277c623
|
File details
Details for the file mcp_server_postgresql-0.1.8-py3-none-any.whl.
File metadata
- Download URL: mcp_server_postgresql-0.1.8-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
276a61f8c4e4b3513f2731b4b4ad628f260a4db6ad400f58cf07eae475b22add
|
|
| MD5 |
31c872321827ba72d07aa903747e6741
|
|
| BLAKE2b-256 |
802385d95cc70827b2c4fcc11c7adaa74ba092cb9754cae0f8060e36c690b2c2
|