# mcp-psycopg2 [Health: Active]

**Category:** 🗄️ Databases  
**Repository:** https://github.com/daedalus/mcp-psycopg2  
**GitHub Stars:** 0  
**Views:** 0  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/mcp-psycopg2

## Description
MCP server exposing psycopg2 PostgreSQL database adapter functionality

## Tools
Capabilities this server exposes over MCP:

- **connect** — Create a new database connection
- **close_connection** — Close an existing connection
- **get_connection_info** — Get connection details
- **begin_transaction** — Start a new transaction
- **commit_transaction** — Commit the current transaction
- **rollback_transaction** — Rollback the current transaction
- **set_isolation_level** — Set transaction isolation level
- **create_cursor** — Create a new cursor
- **close_cursor** — Close a cursor
- **execute_query** — Execute a SQL query
- **execute_many** — Execute a query with multiple parameter sets
- **fetch_one** — Fetch one row
- **fetch_many** — Fetch multiple rows
- **fetch_all** — Fetch all remaining rows
- **quote_identifier** — Quote an SQL identifier
- **mogrify** — Return query string after parameter binding
- **register_json** — Register JSON type adapter
- **register_hstore** — Register hstore type adapter
- **register_composite** — Register composite type adapter
- **copy_from** — Copy data from file to table
- **copy_to** — Copy data from table to file
- **copy_expert** — Execute custom COPY statement
- **create_named_cursor** — Create a server-side named cursor
- **scroll_cursor** — Scroll through cursor results
- **create_large_object** — Create or open a large object
- **read_large_object** — Read from a large object
- **write_large_object** — Write to a large object
- **get_server_version** — Get PostgreSQL server version
- **get_backend_pid** — Get backend process ID
- **get_dsn_parameters** — Get connection parameters
- **get_notices** — Get database notices
- **parse_dsn** — Parse a connection string
- **make_dsn** — Create a connection string
- **cancel_query** — Cancel the current database operation
- **set_session** — Set session parameters
- **list_connections** — List all active connections
- **list_cursors** — List all active cursors

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "mcp-psycopg2": {
    "command": "uvx",
    "args": ["mcp-psycopg2"]
  }
}
```

## Documentation

## 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:

```bash
pip install mcp-psycopg2
```

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

```python
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.

_Full upstream README: https://allmcps.com/mcp/mcp-psycopg2/readme_

