MCP Psycopg2 logo

MCP Psycopg2

Expose PostgreSQL operations through psycopg2-backed MCP tools for connections, SQL execution, transactions, cursors, and data transfer.

Install MCP Psycopg2

Pick your client, then add it in one click or paste the config.

STDIOPython
~/Library/Application Support/Claude/claude_desktop_config.json
claude_desktop_config.json
{
  "mcpServers": {
    "mcp-psycopg2": {
      "command": "uvx",
      "args": [
        "mcp-psycopg2"
      ]
    }
  }
}

Settings → Developer → Edit Config, merge this into mcpServers, then fully quit and reopen Claude Desktop.

Claude Code command
claude mcp add --transport stdio mcp-psycopg2 -- uvx mcp-psycopg2

Run in your terminal. Add --scope project to share it with your team through .mcp.json.

We couldn’t confirm it starts correctly

We ran the install command but it didn't respond within our test window — this can mean a slow first-time install rather than a real problem.

uvx mcp-psycopg2

Process exited before answering initialize.

This is an experimental automated check and can have false negatives — missing environment variables, a slow cold install, etc. It doesn’t necessarily mean something’s wrong. Last checked .

Overview

mcp-psycopg2 MCP server exposes psycopg2-backed operations for connecting to PostgreSQL and managing database work through MCP tools. It covers connections, transactions, cursors, SQL execution, parameter binding, COPY operations, type adapters, large objects, and server information. Install it from PyPI, import the MCP object, and run it with Python. Reach for it when an MCP client needs direct access to psycopg2-style PostgreSQL operations rather than a narrower database abstraction.

Use cases

  • Connect an agent to a PostgreSQL database
  • Execute parameterized SQL and fetch results
  • Manage explicit database transactions
  • Transfer table data with PostgreSQL COPY
  • Process PostgreSQL cursors and large objects

Key features

  • PostgreSQL connections and transaction control
  • SQL execution with cursor-based fetching
  • COPY, named cursor, and large-object operations
  • JSON, hstore, and composite type registration
  • DSN, server, backend, and session information

Tools37

What MCP Psycopg2 lets your agent do. Expand a tool for its parameters.

Self-reported~372 tokens of context

Security & health

What it can reach and how reliably it runs — from our own checks, not the maintainer’s claims.

ActiveLast checked

Recent health check succeeded.

15/15 checks healthy over the last 84d

Supply-chain signal

No high-severity advisories surfaced by our automated scan.

Critical 0High 0Medium 0Low 0

Scanned 9d ago via OSV.dev · mcp-psycopg2 (PyPI)

Adoption & maintenance

Factual signals from GitHub, npm, and our automated checks — not a rating.

Last commit7mo agoMost recent push to the default branch.
Install checkInconclusiveDidn't respond in our test window — often a slow first install.
Tools exposed37Callable tools this server registers over MCP.

How MCP Psycopg2 works

What mcp-psycopg2 MCP server does

The mcp-psycopg2 MCP server maps a broad portion of the psycopg2 PostgreSQL adapter to MCP tools. It lets an MCP client create and inspect database connections, control transactions, create cursors, execute SQL, and retrieve query results. The available operations are close to the underlying adapter’s concepts, so it is suited to workflows that need explicit control over connection and cursor lifecycles.

Beyond ordinary queries, the server supports PostgreSQL-oriented features including identifier quoting, parameter-bound query rendering with mogrify, JSON, hstore, and composite type registration, and COPY-based data movement. It also exposes named cursors, cursor scrolling, large-object operations, and server metadata such as the PostgreSQL version, backend process ID, and DSN parameters.

How it works

Connection management starts with connect, followed by operations such as get_connection_info or close_connection. Transaction tools provide explicit begin, commit, rollback, and isolation-level control. Cursor tools support creation, execution, batch execution, fetching one or many rows, fetching all remaining rows, and closure.

The mcp-psycopg2 MCP server also includes information and session utilities listed by the project: database notices, DSN parsing and construction, query cancellation, session parameter updates, and lists of active connections or cursors. These operations give an agent access to both routine query work and lower-level PostgreSQL session behavior.

Setup and configuration

Install the package from PyPI:

Terminal
pip install mcp-psycopg2

The documented Python entry point imports mcp from mcp_psycopg2 and starts the server with mcp.run():

server.ts
from mcp_psycopg2 import mcp

mcp.run()

Database connection details are supplied through the connection operation and can be inspected with the connection and DSN information tools.

Tools and capabilities

The mcp-psycopg2 MCP server provides tools for:

  • Opening, inspecting, and closing PostgreSQL connections.
  • Starting, committing, rolling back, and configuring transactions.
  • Creating regular or server-side named cursors and scrolling cursor results.
  • Executing single SQL statements or batches, then fetching rows.
  • Quoting identifiers and rendering SQL after parameter binding.
  • Registering JSON, hstore, and composite type adapters.
  • Copying data between files and tables, including custom COPY statements.
  • Creating, reading, and writing PostgreSQL large objects.
  • Reading server details, backend identity, DSN values, and database notices.
  • Cancelling operations, setting session parameters, and listing active resources.

Limitations and notes

The material describes the package and its tool surface but does not document authentication defaults, connection-string requirements, transport settings, permission handling, result serialization details, or client compatibility. Those details should be verified before deploying it in a particular MCP host. The repository’s development instructions include pytest, Ruff formatting and linting, and mypy, but they do not describe production deployment behavior.

Written by AllMCPs with AI assistance from the project’s README and listing data. How we build listings

Reviews

No reviews yet — be the first to share how it worked for you.

Frequently Asked Questions about MCP Psycopg2

mcp-psycopg2 is an MCP server that connects MCP clients to PostgreSQL through the psycopg2 adapter. Its main tools manage connections and transactions, execute SQL through cursors, fetch results, handle COPY operations, register type adapters, work with large objects, and inspect server or connection details.

Install it with pip using `pip install mcp-psycopg2`. The documented Python startup imports `mcp` from `mcp_psycopg2` and calls `mcp.run()`.

Use `connect` to create a database connection, then create a cursor and call `execute_query` or `execute_many`. Retrieve results with `fetch_one`, `fetch_many`, or `fetch_all`, and close the cursor or connection when finished.

Yes, it provides tools to begin, commit, and roll back transactions, as well as set the transaction isolation level.

Related MCP servers

Add a badge to your READMEShow it’s listed — live SVG, Markdown or HTML.

AllMCPs Directory Badge

Full Badge Customizer

Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.

Badge Style:
Live Dynamic SVG PreviewMCP Psycopg2 AllMCPs Directory Badge
Markdown (GitHub README)
[![AllMCPs](https://allmcps.com/api/badge/mcp-psycopg2?style=directory)](https://allmcps.com/mcp/mcp-psycopg2)
HTML Embed
<a href="https://allmcps.com/mcp/mcp-psycopg2"><img src="https://allmcps.com/api/badge/mcp-psycopg2?style=directory" alt="MCP Psycopg2 on AllMCPs" /></a>