io.github.daedalus/mcp-psycopg2
MCP server exposing psycopg2 PostgreSQL database adapter functionality
Versions
0.1.0latestTools 37
connect Create a new PostgreSQL database connection. Args: dbname: Database name to connect to. user: User name for authentication. password: Password for authentication. host: Database host address. port: Connection port number (default 5432). connection_id: Unique identifier for this connection (default 'default'). Returns: Connection ID if successful. Example: >>> connect(dbname="mydb", user="admin", password="secret", host="localhost") "default"
close_connection Close an existing database connection. Args: connection_id: The ID of the connection to close. Returns: Confirmation message. Example: >>> close_connection("default") "Connection closed"
get_connection_info Get information about a database connection. Args: connection_id: The ID of the connection. Returns: Dictionary containing connection information. Example: >>> get_connection_info("default") {"dbname": "test", "user": "postgres", "host": "localhost", ...}
begin_transaction Begin a new transaction. Args: connection_id: The ID of the connection. Returns: Confirmation message. Example: >>> begin_transaction("default") "Transaction started"
commit_transaction Commit the current transaction. Args: connection_id: The ID of the connection. Returns: Confirmation message. Example: >>> commit_transaction("default") "Transaction committed"
rollback_transaction Rollback the current transaction. Args: connection_id: The ID of the connection. Returns: Confirmation message. Example: >>> rollback_transaction("default") "Transaction rolled back"
set_isolation_level Set transaction isolation level. Args: level: Isolation level (AUTOCOMMIT, READ_UNCOMMITTED, READ_COMMITTED, REPEATABLE_READ, SERIALIZABLE, DEFAULT). connection_id: The ID of the connection. Returns: Confirmation message. Example: >>> set_isolation_level("READ_COMMITTED", "default") "Isolation level set"
create_cursor Create a new database cursor. Args: cursor_name: Name for server-side cursor (optional). connection_id: The ID of the connection. cursor_id: Custom cursor ID (defaults to auto-generated). scrollable: Whether cursor can scroll backwards. withhold: Whether cursor persists after commit. Returns: Cursor ID. Example: >>> create_cursor(connection_id="default") "cursor_default_1"
close_cursor Close a database cursor. Args: cursor_id: The ID of the cursor to close. Returns: Confirmation message. Example: >>> close_cursor("cursor_default_1") "Cursor closed"
execute_query Execute a SQL query. Args: query: SQL query to execute. params: Query parameters (optional). cursor_id: Cursor ID to use (creates new if not provided). connection_id: Connection ID. Returns: Dictionary with query results and metadata. Example: >>> execute_query("SELECT * FROM users WHERE id = %s", [1]) {"rows": [[1, "john"]], "rowcount": 1, "columns": [...]}
execute_many Execute a SQL query with multiple parameter sets. Args: query: SQL query to execute. params_list: List of parameter sets. cursor_id: Cursor ID to use. connection_id: Connection ID. Returns: Dictionary with execution results. Example: >>> execute_many("INSERT INTO users (name) VALUES (%s)", [["alice"], ["bob"]]) {"rowcount": 2}
fetch_one Fetch one row from cursor. Args: cursor_id: Cursor ID. Returns: Row data as list, or None if no more rows. Example: >>> fetch_one("cursor_default_1") [1, "john"]
fetch_many Fetch multiple rows from cursor. Args: cursor_id: Cursor ID. size: Number of rows to fetch. Returns: List of rows. Example: >>> fetch_many("cursor_default_1", 10) [[1, "john"], [2, "jane"]]
fetch_all Fetch all remaining rows from cursor. Args: cursor_id: Cursor ID. Returns: List of all rows. Example: >>> fetch_all("cursor_default_1") [[1, "john"], [2, "jane"], [3, "bob"]]
quote_identifier Quote an SQL identifier. Args: identifier: The identifier to quote. connection_id: Connection ID. Returns: Quoted identifier. Example: >>> quote_identifier("my_table") '"my_table"'
create_named_cursor Create a server-side named cursor. Args: name: Name for the cursor. query: Initial query to execute (optional). scrollable: Whether cursor can scroll backwards. withhold: Whether cursor persists after commit. connection_id: Connection ID. Returns: Cursor ID. Example: >>> create_named_cursor("my_cursor", "SELECT * FROM large_table") "cursor_default_1"
scroll_cursor Scroll through cursor results. Args: cursor_id: Cursor ID. value: Offset or absolute position. mode: 'relative' or 'absolute'. Returns: Confirmation message. Example: >>> scroll_cursor("cursor_default_1", 10, "relative") "Cursor scrolled"
copy_from Copy data from a file-like object to a table. Args: table: Target table name. columns: Column names (optional). sep: Column separator. null: NULL representation. size: Buffer size. cursor_id: Cursor ID. connection_id: Connection ID. Returns: Status message. Example: >>> copy_from("my_table", columns=["id", "name"]) "Copied 100 rows"
copy_to Copy data from a table to a file-like object. Args: table: Source table name. columns: Column names (optional). sep: Column separator. null: NULL representation. cursor_id: Cursor ID. connection_id: Connection ID. Returns: Copied data as string. Example: >>> copy_to("my_table") "1\tjohn\n2\tjane\n"
copy_expert Execute custom COPY statement. Args: sql: COPY SQL statement. connection_id: Connection ID. Returns: Status message. Example: >>> copy_expert("COPY my_table TO STDOUT WITH CSV HEADER") "data\n1,john\n2,jane\n"
get_server_version Get PostgreSQL server version. Args: connection_id: Connection ID. Returns: Server version as integer. Example: >>> get_server_version("default") 150005
get_backend_pid Get backend process ID. Args: connection_id: Connection ID. Returns: Backend PID. Example: >>> get_backend_pid("default") 12345
get_dsn_parameters Get connection parameters. Args: connection_id: Connection ID. Returns: Dictionary of DSN parameters. Example: >>> get_dsn_parameters("default") {"dbname": "test", "user": "postgres", "host": "localhost"}
get_notices Get database notices. Args: connection_id: Connection ID. Returns: List of notice messages. Example: >>> get_notices("default") ["NOTICE: CREATE TABLE will create implicit sequence..."]
parse_dsn Parse a connection string. Args: dsn: Connection string to parse. Returns: Dictionary of connection parameters. Example: >>> parse_dsn("dbname=test user=postgres") {"dbname": "test", "user": "postgres"}
make_dsn Create a connection string from arguments. Args: dbname: Database name. user: User name. password: Password. host: Host address. port: Port number. Returns: Connection string. Example: >>> make_dsn(dbname="test", user="postgres", host="localhost") "dbname=test user=postgres host=localhost"
register_json Register JSON type adapter. Args: connection_id: Connection ID. globally: Register globally. Returns: Confirmation message. Example: >>> register_json("default") "JSON type registered"
register_hstore Register hstore type adapter. Args: connection_id: Connection ID. globally: Register globally. unicode: Use unicode keys/values. Returns: Confirmation message. Example: >>> register_hstore("default") "Hstore type registered"
register_composite Register composite type adapter. Args: name: Composite type name. connection_id: Connection ID. globally: Register globally. Returns: Confirmation message. Example: >>> register_composite("my_type", "default") "Composite type registered"
create_large_object Create or open a large object. Args: connection_id: Connection ID. oid: Object OID (0 for new). mode: Access mode (r, w, rw, n, b, t). Returns: Dictionary with OID and mode. Example: >>> create_large_object("default") {"oid": 12345, "mode": "rw"}
read_large_object Read from a large object. Args: oid: Object OID. size: Bytes to read (-1 for all). connection_id: Connection ID. Returns: Data read from large object. Example: >>> read_large_object(12345, "default") "binary data..."
write_large_object Write to a large object. Args: data: Data to write. oid: Object OID (0 for new). connection_id: Connection ID. Returns: Dictionary with OID and bytes written. Example: >>> write_large_object("data", 0, "default") {"oid": 12345, "bytes_written": 4}
cancel_query Cancel the current database operation. Args: connection_id: Connection ID. Returns: Confirmation message. Example: >>> cancel_query("default") "Query cancelled"
mogrify Return query string after parameter binding. Args: query: SQL query. params: Query parameters. connection_id: Connection ID. Returns: Mogrified query string. Example: >>> mogrify("INSERT INTO t VALUES (%s)", ["value"]) "INSERT INTO t VALUES (E'value')"
set_session Set session parameters. Args: isolation_level: Isolation level. readonly: Read-only mode. deferrable: Deferrable mode. autocommit: Autocommit mode. connection_id: Connection ID. Returns: Confirmation message. Example: >>> set_session(readonly=True, connection_id="default") "Session parameters set"
list_connections List all active connections. Returns: List of connection information. Example: >>> list_connections() [{"id": "default", "status": "OK"}]
list_cursors List all active cursors. Args: connection_id: Filter by connection ID. Returns: List of cursor information. Example: >>> list_cursors() [{"id": "cursor_default_1", "name": None, "closed": False}]
Permissions 0
No permissions indexed yet.