Mcp Psycopg2

io.github.daedalus由 GitHub 账号 daedalus 发布v0.1.0更新于 Oct 25, 2026

MCP server exposing psycopg2 PostgreSQL database adapter functionality

已验证STDIO仅桌面数据库开发者工具

概览

AI 生成的概览

一个本地 MCP 服务器,封装 psycopg2 PostgreSQL 适配器功能,让助手连接并查询 PostgreSQL 数据库。

可以做什么
通过 psycopg2 风格的工具建立、关闭、查看和列出数据库连接,并解析或构造连接字符串与 DSN 参数。管理事务:开始、提交、回滚、设置隔离级别和会话参数。创建和关闭游标,执行单条或参数化批量 SQL,并获取一行、多行或全部结果。引用标识符、绑定参数,并注册 JSON、hstore 和复合类型适配器。执行 COPY 操作、服务端命名游标、大对象读写以及取消查询。
适用场景
适合助手需要在桌面端直接、底层地访问 PostgreSQL 数据库的场景:执行临时 SQL、查看结构或数据、管理事务,或用 COPY 和大对象搬运数据。
运行要求
作为本地进程在用户机器上运行,从 PyPI 包 mcp-psycopg2 安装(Python)。需要可访问的 PostgreSQL 服务器和有效的连接信息;清单未声明环境变量、请求头或认证,连接参数通过工具传入。
安装前请注意
工具可执行任意 SQL、写入或删除数据、提交事务、通过 COPY 读写文件以及写入大对象;请使用最小权限的数据库账号并在执行前检查语句。连接字符串和 DSN 参数可能包含凭据,并会通过 get_dsn_parameters、make_dsn 等工具暴露。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Mcp Psycopg2,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

mcp-psycopg2

MCP server exposing psycopg2 PostgreSQL database adapter functionality.

[PyPI] [Python] [Ruff]

mcp-name: io.github.daedalus/mcp-psycopg2

Install

bash
pip install mcp-psycopg2

Usage

python
from mcp_psycopg2 import mcp
# Run the MCP servermcp.run()

MCP Tools

The server exposes the following tools for interacting with PostgreSQL databases:

Connection Management

  • connect - Create a new database connection
  • close_connection - Close an existing connection
  • get_connection_info - Get connection details

Transaction Management

  • 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

Cursor Operations

  • 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

SQL Composition

  • quote_identifier - Quote an SQL identifier
  • mogrify - Return query string after parameter binding

Type Registration

  • register_json - Register JSON type adapter
  • register_hstore - Register hstore type adapter
  • register_composite - Register composite type adapter

COPY Operations

  • copy_from - Copy data from file to table
  • copy_to - Copy data from table to file
  • copy_expert - Execute custom COPY statement

Server-Side Cursors

  • create_named_cursor - Create a server-side named cursor
  • scroll_cursor - Scroll through cursor results

Large Objects

  • 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

Information

  • 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

Utility

  • cancel_query - Cancel the current database operation
  • set_session - Set session parameters
  • list_connections - List all active connections
  • list_cursors - List all active cursors

Development

bash
git clone https://github.com/daedalus/mcp-psycopg2.gitcd mcp-psycopg2pip install -e ".[test]"
# run testspytest
# formatruff format src/ tests/
# lintruff check src/ tests/
# type checkmypy src/

来源:README.md,提交 768b769

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分