PostgreSQL MCP Server
Provides tools for querying and managing PostgreSQL databases, including CRUD operations, schema management, indexing, introspection, and performance analysis.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@PostgreSQL MCP Servershow me the schema of the users table"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides a standardized interface for interacting with PostgreSQL databases. This server enables LLMs and other tools to perform database operations through a consistent protocol.
Features
Full CRUD Operations: Execute queries, insert, update, and delete data
Schema Management: Create/drop tables, manage indexes
Database Introspection: List tables, describe table structures, analyze indexes
Performance Analysis: Query performance analysis and table statistics
Configurable Schema Support: Use custom schemas or default to 'public'
Connection Pooling: Efficient database connection management
Type Safety: Full TypeScript support
Related MCP server: PostgreSQL MCP Server
Installation
npm installConfiguration
Create a .env file in the project root with your PostgreSQL connection details:
# PostgreSQL Database Configuration
DATABASE_URL=postgresql://username:password@localhost:5432/dbname
# Or use individual parameters
DB_HOST=localhost
DB_PORT=5432
DB_NAME=your_database
DB_USER=your_username
DB_PASSWORD=your_password
DB_SCHEMA= # Optional: defaults to 'public' if not specified
# Connection Pool Settings (optional)
DB_POOL_MIN=2
DB_POOL_MAX=10
DB_POOL_IDLE_TIMEOUT=30000
# Logging Level (optional)
LOG_LEVEL=infoSchema Configuration
If
DB_SCHEMAis empty or not provided, the server uses 'public' schemaIf
DB_SCHEMAis set (e.g.,DB_SCHEMA=myschema), that schema is used as defaultIndividual tool calls can override the default by providing a
schemaparameter
Building
npm run buildRunning the Server
npm startThe server communicates via stdin/stdout using the MCP protocol.
Available Tools
Query Operations
execute_query: Execute SELECT queries with optional parameters
analyze_query_performance: Analyze query execution plans
Data Manipulation
insert_data: Insert data into tables
update_data: Update existing data
delete_data: Delete data from tables
Schema Operations
create_table: Create new tables with column definitions
drop_table: Drop existing tables
create_index: Create indexes on table columns
Introspection
list_tables: List all tables in a schema
describe_table: Get detailed table structure information
list_indexes: List all indexes for a table
get_table_stats: Get table statistics (row count, size, etc.)
Development
# Run in development mode with auto-reload
npm run dev
# Clean build artifacts
npm run clean
# Run tests (if available)
npm testMCP Protocol
This server implements the Model Context Protocol, allowing it to be used with any MCP-compatible client. The protocol uses JSON-RPC 2.0 for communication.
Example Request
{
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "list_tables",
"arguments": {
"schema": "public"
}
},
"id": 1
}Example Response
{
"jsonrpc": "2.0",
"result": {
"content": [
{
"type": "text",
"text": "{\"success\": true, \"tables\": [...]}"
}
]
},
"id": 1
}Security Considerations
Never commit
.envfiles with real credentialsUse environment-specific configurations for different deployments
Consider using connection pooling for production environments
Implement proper access controls at the database level
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
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/kripala/postgres-mcp-server-stateless'
If you have feedback or need assistance with the MCP directory API, please join our Discord server