Skip to main content
Glama

MCP Server for PostgreSQL

by asadudin

PostgreSQL용 MCP 서버

PostgreSQL을 위한 MCP(Model Context Protocol) 서버 구현으로, MCP를 통해 PostgreSQL 데이터베이스와 상호 작용할 수 있는 간단한 인터페이스를 제공합니다.

특징

  • 매개변수화된 입력으로 SQL 쿼리 실행
  • INSERT/UPDATE/DELETE 작업 실행
  • 새로운 데이터베이스 생성
  • 테이블 스키마 생성 또는 업데이트
  • PostgreSQL 연결 디버깅
  • Docker로 컨테이너화하여 쉽게 배포 가능
  • 환경 기반 구성

필수 조건

  • 파이썬 3.8 이상
  • 포스트그레SQL 10+
  • Docker(컨테이너화된 배포를 위한 선택 사항)
  • Docker Compose(선택 사항, 개발용)

설치

Docker 사용(권장)

  1. 저장소를 복제합니다.지엑스피1
  2. 예제 환경 파일을 복사하세요.
    cp .env.example .env
  3. PostgreSQL 자격 증명으로 .env 파일을 업데이트합니다.
    PG_HOST=postgres PG_PORT=5432 PG_USER=postgres PG_PASSWORD=your_password PG_DATABASE=your_database HOST=0.0.0.0 PORT=8056
  4. Docker Compose를 사용하여 서비스를 시작합니다.
    docker-compose up -d

수동 설치

  1. 저장소를 복제합니다.
    git clone https://github.com/asadudin/mcp-server-postgres.git cd mcp-server-postgres
  2. 가상 환경을 만들고 활성화하세요.
    python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
  3. 종속성 설치:
    pip install -r requirements.txt
  4. 예제 환경 파일을 복사하여 업데이트합니다.
    cp .env.example .env # Edit .env with your configuration
  5. 서버를 실행합니다:
    python mcp_server_postgres.py

용법

MCP 서버는 다음과 같은 엔드포인트를 제공합니다.

sql_query

SELECT 쿼리를 실행하고 결과를 JSON으로 반환합니다.

매개변수:

  • query : SQL 쿼리 문자열
  • params : 쿼리 매개변수의 선택적 JSON 문자열(목록 또는 사전)

예:

{ "query": "SELECT * FROM users WHERE id = $1", "params": [1] }

sql_execute

INSERT/UPDATE/DELETE 문을 실행합니다.

매개변수:

  • query : SQL 문
  • params : 쿼리 매개변수의 선택적 JSON 문자열(목록 또는 사전)

예:

{ "query": "INSERT INTO users (name, email) VALUES ($1, $2)", "params": ["John Doe", "john@example.com"] }

create_database

새로운 PostgreSQL 데이터베이스를 만듭니다.

매개변수:

  • database_name : 생성할 데이터베이스의 이름

create_or_update_table

테이블 스키마를 생성하거나 업데이트합니다.

매개변수:

  • sql : CREATE TABLE 또는 ALTER TABLE SQL 문

debug_postgres_connection

PostgreSQL 연결을 디버깅합니다.

환경 변수

변하기 쉬운기본설명
PG_호스트로컬호스트PostgreSQL 호스트
PG_PORT5432PostgreSQL 포트
PG_USER포스트그레스PostgreSQL 사용자 이름
PG_비밀번호PostgreSQL 비밀번호
PG_데이터베이스포스트그레스기본 데이터베이스 이름
주인0.0.0.0MCP 서버를 바인딩할 호스트
포트8056MCP 서버를 실행할 포트

개발

테스트 실행

# Install test dependencies pip install -r requirements-dev.txt # Run tests pytest

Docker 이미지 빌드

docker build -t mcp-server-postgres .

API 문서

자세한 API 문서는 OpenAPI 사양을 참조하세요.

기여하다

기여를 환영합니다! 풀 리퀘스트를 제출해 주세요.

특허

이 프로젝트는 MIT 라이선스에 따라 라이선스가 부여되었습니다. 자세한 내용은 라이선스 파일을 참조하세요.

감사의 말

  • FastMCP - MCP 서버 프레임워크
  • asyncpg - Python용 PostgreSQL 클라이언트
  • FastAPI - API 구축을 위한 현대적이고 빠른 웹 프레임워크
-
security - not tested
F
license - not found
-
quality - not tested

MCP를 통해 SQL 쿼리, 데이터베이스 작업 및 스키마 관리를 가능하게 하여 PostgreSQL 데이터베이스와 상호 작용할 수 있는 간단한 인터페이스를 제공하는 모델 컨텍스트 프로토콜 서버 구현입니다.

  1. 특징
    1. 필수 조건
      1. 설치
        1. Docker 사용(권장)
        2. 수동 설치
      2. 용법
        1. sql_query
        2. sql_execute
        3. create_database
        4. create_or_update_table
        5. debug_postgres_connection
      3. 환경 변수
        1. 개발
          1. 테스트 실행
          2. Docker 이미지 빌드
        2. API 문서
          1. 기여하다
            1. 특허
              1. 감사의 말

                Related MCP Servers

                • -
                  security
                  F
                  license
                  -
                  quality
                  A Model Context Protocol server providing both read and write access to PostgreSQL databases, enabling LLMs to query data, modify records, and manage database schemas.
                  Last updated -
                  4
                  JavaScript
                • -
                  security
                  A
                  license
                  -
                  quality
                  A Model Context Protocol server that enables powerful PostgreSQL database management capabilities including analysis, schema management, data migration, and monitoring through natural language interactions.
                  Last updated -
                  355
                  46
                  TypeScript
                  AGPL 3.0
                  • Linux
                  • Apple
                • -
                  security
                  -
                  license
                  -
                  quality
                  A Model Context Protocol server that provides tools for connecting to and interacting with various database systems (SQLite, PostgreSQL, MySQL/MariaDB, SQL Server) through a unified interface.
                  Last updated -
                  Python
                • -
                  security
                  F
                  license
                  -
                  quality
                  A Model Context Protocol server that enables performing PostgreSQL database operations (create, read, update, delete) on User and Post entities through MCP tools.
                  Last updated -
                  TypeScript

                View all related MCP servers

                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/asadudin/mcp-server-postgres'

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