Skip to main content

Add your description here

Project description

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 query string
    • Returns results for SELECT-like statements, or a success message for others
  • create_table: Create a new table

    • Takes a name and a schema (column definitions)
    • Creates the specified table
  • insert_data: Insert a row of data into a table

    • Takes a table name and a data dict of column values
    • Inserts the specified row
  • fetch_data: Fetch data by executing a SELECT query

    • Takes a query string
    • Returns matching rows as a result set

Configuration

The server connects to PostgreSQL using host, port, user, password, and database name. By default, these are set in the source code, but they can be overridden by environment variables or modified directly in the configuration.

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:

  1. Sync dependencies and update lockfile:
uv sync
  1. Build package distributions:
uv build

This will create source and wheel distributions in the dist/ directory.

  1. Publish to PyPI:
uv publish

Note: You'll need to set PyPI credentials via environment variables or command flags:

  • Token: --token or UV_PUBLISH_TOKEN
  • Or username/password: --username/UV_PUBLISH_USERNAME and --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

mcp_server_postgresql-0.1.6.tar.gz (15.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_server_postgresql-0.1.6-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file mcp_server_postgresql-0.1.6.tar.gz.

File metadata

File hashes

Hashes for mcp_server_postgresql-0.1.6.tar.gz
Algorithm Hash digest
SHA256 5cfac7c8bdc89dc32c17763ccfc29b0903f7eed7931cf5b97bd7d5fd721dec7b
MD5 b9e78af6f6a35d1b26faa3bb4e5f8ea6
BLAKE2b-256 1fdbdd974ae47c17d121ffb4ec9955aa5000dabcbfaafe9ef5bc99202dbb5898

See more details on using hashes here.

File details

Details for the file mcp_server_postgresql-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_server_postgresql-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 982ef94db08740715308b50aa878fe590c1dfb72cb24456f40905c042bb516f2
MD5 cf4fd5bfa55655fce65bb4a50dc437b6
BLAKE2b-256 b552702faf15ac44682661a58e946d3bebbad4c1e88e96cf940ca8efb806259a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page