convez.ai
MCP ServerIntegração & APIsIntermediário
corporatepiyush

MCP PostgreSQL Server em Rust

corporatepiyush/mcp-pg-rust

PostgreSQL em Claude: 135 tools, pool lock-free, sub-10ms latency

Ver no GitHub
BomPluginScore · de 0 a 100

Servidor MCP de alta performance que integra PostgreSQL ao Claude Desktop e ferramentas compatíveis com MCP. Oferece 135 ferramentas pré-construídas, pool de conexões sem locks e latência sub-10ms para operações de banco de dados via IA.

Instalação

$npx convez-ai corporatepiyush/mcp-pg-rust

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
22
Forks
4
Acompanhando
0
Saúde
42%
Último commit
há 4 meses
Versão
—
Issues abertas
1
Contribuidores
1

Casos de uso

  • Consultas estruturadas a PostgreSQL via Claude Desktop
  • Automação de operações de banco de dados através de agentes IA
  • Inspeção de schema, auditoria de segurança e manutenção de BD
  • Replicação, text search e gerenciamento de extensões PostgreSQL

Veredito

Implementação sólida de acesso PostgreSQL para MCP com foco em performance e segurança. Ideal para quem precisa conectar Claude a bancos de dados já existentes, mas requer conhecimento de PostgreSQL e configuração local.

README

A tradução para o português deste README ainda está na fila.

mcp-postgres

Crates.io License Rust

mcp-postgres is a high-performance MCP server that brings PostgreSQL into Claude Desktop and any MCP-compatible AI tool. 135 PostgreSQL tools, lock-free connection pooling, sub-10ms latency.

Quick Start

Install

# From crates.io
cargo install mcp-postgres

# Or from Homebrew (macOS)
brew tap corporatepiyush/mcp-postgres
brew install mcp-postgres

Run

# Stdio mode (for Claude Desktop)
mcp-postgres --database-url "postgres://user:pass@localhost:5432/mydb" --stdio

# TCP server (port 3000)
mcp-postgres --database-url "postgres://user:pass@localhost:5432/mydb"

# HTTP/2 server (port 3001)
mcp-postgres --database-url "postgres://user:pass@localhost:5432/mydb" --http-port 3001

Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "postgres": {
      "command": "mcp-postgres",
      "args": ["--database-url", "postgres://user:pass@localhost:5432/mydb", "--stdio"]
    }
  }
}

Complete setup guide →


Why mcp-postgres?

Featuremcp-postgresDIY / psql
135 purpose-built toolsSchema inspection, DDL, monitoring, replication, batch ops, security audit, text search, extensions, maintenance, and moreYou build every query from scratch
Lock-free connection poolZero-mutex crossbeam::ArrayQueue — pure CAS loops, no kernel overheadDeadpool or manual Mutex<VecDeque>
Dual-protocolTCP (3000) + HTTP/2 (3001) + stdio — one binary, three transportsMultiple servers to wire up
Sub-10ms latencyAllocated for AI interactivity — hot path is allocation-freeUnpredictable
SQL injection preventionEvery identifier validated, quote_ident sanitization, structured predicatesManual parameterization
PG version-awareQueries verified against PG 16–18 docs, graceful fallbacks for version differencesVersion-specific failures

Command-Line Options

Usage: mcp-postgres [OPTIONS]

Options:
  -d, --database-url <URL>       PostgreSQL connection string
  -H, --host <HOST>              TCP server host             [127.0.0.1]
  -p, --port <PORT>              TCP server port             [3000]
      --http-port <PORT>         HTTP/2 server port          [3001]
      --min-connections <N>      Min pool connections        [5]
      --max-connections <N>      Max pool connections        [20]
      --log-level <LEVEL>        Log level                   [info]
      --enable-metrics           Prometheus /metrics endpoint
      --metrics-port <PORT>      Metrics port                [9090]
      --stdio                    Stdio mode (Claude Desktop)
      --access-mode <MODE>       unrestricted, restricted    [unrestricted]
  -h, --help                     Print help
  -V, --version                  Print version

Protocol & API

JSON-RPC 2.0 over TCP, HTTP/2, or stdio.

{
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": { "name": "list_tables", "arguments": {} },
  "id": 1
}

Tools (135 Total)


Performance

Lock-Free Connection Pool (v4.0.0)

No mutexes. No semaphores. Just CAS loops.

┌─────────────┐     ┌──────────────────┐     ┌─────────────┐
│  Task 1     │     │  crossbeam::     │     │  Task 2     │
│  (acquire)  │────▶│  ArrayQueue      │◀────│  (release)  │
└─────────────┘     │  CachePadded     │     └─────────────┘
                    │  Head/Tail       │
                    │  (CAS only)      │
                    └──────────────────┘
MetricDeadpool (v3.x)LockFreePool (v4.0.0)
Lock acquisitions per acquire+release3+ (Mutex + Semaphore)0
Allocation on hot pathYes (VecDeque growth)Zero (pre-allocated)
False sharingLikely (adjacent fields)Cache-padded atomics
InliningCross-crate, opaqueMonomorphic, LTO-friendly
Dependencies2 (deadpool + deadpool-postgres)0 external (crossbeam already in tree)

Sub-10ms latency is guaranteed by design: zero allocation on the hot path, monomorphic dispatch, cache-line-isolated atomics, and a single-pointer CAS for connection handoff.

Architecture

┌─────────────────┐         ┌─────────────────┐
│   TCP Client    │         │   HTTP Client   │
│  (port 3000)    │         │  (port 3001)    │
└────────┬────────┘         └────────┬────────┘
         └─────────────┬─────────────┘
                       │
              ┌────────┴────────┐
              │   JSON-RPC 2.0  │
              │  (MCP Protocol) │
              └────────┬────────┘
                       │
          ┌────────────┴────────────┐
          │   Tool Dispatcher       │
          │   (135 tools)           │
          └────────────┬────────────┘
                       │
          ┌────────────┴────────────┐
          │   Connection Pool       │
          │   (lock-free, CAS-only) │
          │   Min: 5, Max: 20       │
          └────────────┬────────────┘
                       │
              ┌────────┴────────┐
              │  PostgreSQL DB  │
              └─────────────────┘

Key Design Principles

  • Stateless HTTP — Each request is independent. Transaction state isolated per-connection.
  • Lock-free pooling — crossbeam::ArrayQueue with CachePadded atomics. Zero mutex acquisitions.
  • Input validation at the boundary — SQL capped at 10K chars, identifiers at 255, batch rows at 1K. SQL injection prevention via quote_ident.
  • PG version-aware queries — Verified against PG 16–18. Graceful fallbacks when views/columns differ across versions.

License

Apache-2.0

Support

GitHub Issues

Ver o original no GitHub

Bom para

Relacionados