Skip to main content
Glama
BerkantACUN

pg-guard-mcp

by BerkantACUN

pg-guard-mcp

PyPI

PostgreSQL MCP 서버로, 프로토콜 및 권한 수준에서 읽기 전용 접근을 강제합니다. 어떤 문자열을 파싱하고 "그냥 대하" 하라는 식이 아닙니다.

설치

pip install pg-guard-mcp
# or, without installing anything permanently:
uvx pg-guard-mcp

Related MCP server: MCP PostgreSQL Read-Only Server

존재 이유

공식 @modelcontextprotocol/server-postgres에는 COMMIT; 한 개로 우회할 수 있는 읽기 전용 모드가 있었습니다. 이 모드는 에이전트의 쿼리를 BEGIN TRANSACTION READ ONLY로 감싸고 전체를 하나의 문자열로 보냈습니다. Postgres는 해당 모드에서 세미클롴으로 구분된 여러 문을 허용하기 때문에, SELECT 1; COMMIT; DROP SCHEMA public CASCADE; 는 읽기 전용 트랜잭션을 일찍 종료시키고 DROP을 일반 쓰기로 실행할 수 있었습니다. 이 문제로 패키지가 deprecated 되었습니다. (Datadog Security Labs의 글)

pg-guard-mcp는 바로 이 버그 클래스, 즉 "읽기 전용"을 문자열 검사만으로 강하는 접근 방식이 여전히 MCP 생태케에 흔하다는 사실에 기반ㅇ고 있습니다. 세 가지 독립적인 계층으로 대방하기 때문에, 남은 실수하나가 치명적真实 않습니다:

  1. 프로토콜 계층(진정한 경계). 모든 크리는 Postgres의 확장 크지 프로토콜 (Parse/Bind/Execute) 로 처리하며, 단순 크지 프로토[콜은 절대에서 사용하지 않습니다. 확장 프로토콜은 Parse 메시지 하나에 두 개 이상의 문을 구조적으로 거부합니다. Postgres는 우리 코드가 실행되기 전에 자체적으로 이를 거부합니다. 따라서 어떤 문자열이 전송되더라도 Datadog 공격은 여기서 작동할 수 없습니다.

  2. 세션 계층. 모든 연결은 자션의 수준에서 default_transaction_read_only = on을 설정합니다. 그래서 어떻게든 쓰기로 데이터베이스에 도달하는 쿼리라도 Postgres가 거부합니다.

  3. 사전 점검 계층. 쿼리를 실제로 보내기 전에, 문장이 여러 개인지 및 트랜잭션 제어 키워드(COMMIT, ROLLBACK, BEGIN, SAVEPOINT, ...)를 검사하고 그런 경우명확한 오류와 함께 거부합니다. 이것은 1차 방어가 아니라, 빠르고 분명하게 실패하게 하기 위한 계층입니다.

이에 더해, 쓰기 권한이 REVOKE된 데이터베이스 역할로 연결하는 것이 권장(그리고가 시작 시 확인되는) 설정입니다. 권한 계층에도 이중 안전을 더하는 것입니다.

도구

도구

기능

pg_run_query(sql

읽기 전 문장 하나를 실행하고 행을 반환합니다.

pg_explain_query(sql

리를 실행하지 않고 실행 계획을 반환합니다.

pg_list_tables(schema="public")

스크지이 테이블/뷔 담귀.

pg_describe_table(table_name, schema="public")

테이블엳 컬럼 담담.

pg_check_privileges()

연결이된 역할이 실제로 가진 쓰기 혀자를 보고합니다. 항상 비어 있어야 합니다.

설정

pip install pg-guard-mcp
export PG_GUARD_DSN="host=127.0.0.1 dbname=mydb user=myapp_readonly password=..."
pg-guard-mcp

MCP 클라이언트가 환경 설정에 PG_GUARD_DSN을 가지고 상태에서 pg-guard-mcp 명령, 또는 "영구 설치를 건너뛰어고 싶은 경우 uvx pg-guard-mcp"를 하나이게 합니다.

지원되는 모든 환경 변수는 .env.example, 권한 적절하게 제한리된 읽기 전용 역할을 만드는 실제 예시는 scripts/setup_dev_db.sh를 참조하세요 (이 프로젝트의 자체 테스트가 쓰는 설정입니다).

테스트

pip install -e ".[dev]"
pytest tests/ -v

tests/test_safety.py는 순수 Python이며 데이터베이스가 필요 없습니다. tests/test_db.pytests/test_server.py는 실제 로컬 PostgreSQL 인스턴스를 대르로실행되며, 공식 Postgres MCP 서버를 deprecated 하게 만든 바로 그 익스프링트 페이르드를 시험합니다. pgguard_test에 연결실 수 없으면 자동으로 건너or십니다. scripts/setup_dev_db.sh를 한 번 실행해 만들면 됩니다.

상태

v0.1.0, PyPI에서 운영 중입니다. 58개 테스트 통과(공식 server-postgres를 폐기시킨 정확한 익스프링트를 포함한 단위 + 실제 Postgres 통합 테스트로, 패치지 자체를 새로 pip install한 상태로 실행했습니다).

라이선스

MIT

Install Server
A
license - permissive license
A
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    Enables read-only access to PostgreSQL databases with multi-tenant support, allowing users to query data, explore schemas, inspect table structures, and view function definitions across different tenant schemas safely.
    55
    1
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables secure read-only access to PostgreSQL databases through SELECT queries only, with tools for exploring schemas, listing tables, and executing common queries while preventing any data modification operations.
    505
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides secure, read-only access to PostgreSQL databases for schema inspection and data querying. It enables users to list tables, describe structures, and execute SELECT statements while strictly blocking destructive operations.
    11
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables safe interaction with PostgreSQL databases through read-only queries, schema exploration, and performance analysis.
    225
    MIT

View all related MCP servers

Related MCP Connectors

  • Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.

  • Comprehensive PostgreSQL documentation and best practices, including ecosystem tools

  • Read-only bank access for your AI agent. Connects Claude, ChatGPT, Cursor, Gemini, Codex.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BerkantACUN/pg-guard-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server