GitHub Stars
0
User Rating
Not Rated
Favorites
0
Views
24
Forks
0
Issues
0
PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides tools and prompts for PostgreSQL database monitoring and optimization.
Features
- Connection statistics and monitoring
- Database size information
- Index usage statistics
- Slow query detection
- Cache hit ratio monitoring
- Table statistics
- Table analysis tools
- Query EXPLAIN plan generation
Installation
go get github.com/yourusername/psql-go-mcp
Configuration
The server requires PostgreSQL connection details to be provided via environment variables:
export PG_HOST=localhost
export PG_PORT=5432
export PG_USER=postgres
export PG_PASSWORD=postgres
export PG_DB=postgres
export PG_SSLMODE=disable
Usage
Starting the Server
psql-go-mcp
Available Tools
postgresql/connection-stats: Get PostgreSQL connection statisticspostgresql/database-size: Get PostgreSQL database size informationpostgresql/index-usage: Get PostgreSQL index usage statisticspostgresql/slow-queries: Get PostgreSQL slow query statisticspostgresql/cache-hit-ratio: Get PostgreSQL cache hit ratiopostgresql/table-stats: Get PostgreSQL table statisticspostgresql/analyze-table: Analyze a specific PostgreSQL tablepostgresql/explain-query: Get the EXPLAIN plan for a PostgreSQL query
Available Prompts
connection-optimization: Guidance on optimizing PostgreSQL connectionsquery-optimization: Guidance on optimizing PostgreSQL queries
Using with MCP Inspector
The MCP Inspector provides a visual interface for interacting with the PostgreSQL MCP server. Here's how to use it:
Install the MCP Inspector:
npm install -g @modelcontextprotocol/inspectorCreate Inspector Configuration:
Create a file namedinspector-config.jsonwith the following content:{ "mcpServers": { "my-server": { "type": "sse", "url": "http://localhost:8080/events" } } }Start the Inspector:
npx @modelcontextprotocol/inspector --config inspector-config.json --server my-serverAccess the Inspector UI:
- Open your browser and navigate to
http://127.0.0.1:6274 - You should see the Inspector interface with your PostgreSQL MCP server connected
- Use the interface to:
- View available tools and prompts
- Execute database monitoring tools
- Get optimization guidance
- Monitor real-time database statistics
- Open your browser and navigate to
Requirements
- Go 1.23 or later
- PostgreSQL server
- MCP-compatible client
:robot: The free, Open Source alternative to OpenAI, Claude and others. Self-hosted and local-first. Drop-in replacement for OpenAI, running on consumer-grade hardware. No GPU required. Runs gguf, transformers, diffusers and many more. Features: Generate Text, Audio, Video, Images, Voice Cloning, Distributed, P2P and decentralized inference