Skip to content

PostgreSQL MCP Server Usage Guide

Overview

This guide shows how to use the PostgreSQL MCP Server with different MCP clients and integration methods.

Tool Discovery

# Start interactive mode
mcp_platform interactive

# List available tools
mcpp> tools postgres
# Discover tools using CLI
mcp_platform tools postgres
from mcp_platform.client import MCPClient

async def discover_tools():
    client = MCPClient()
    tools = client.list_tools("postgres")
    for tool in tools:
        print(f"Tool: {tool['name']} - {tool['description']}")

Available Tools

list_databases

Description: List all databases on the PostgreSQL server

Parameters: - No parameters required

list_schemas

Description: List all accessible database schemas for a given database

Parameters: - database (string) (optional): No description

list_tables

Description: List tables in a specific schema

Parameters: - schema (string) (optional): No description

describe_table

Description: Get detailed schema information for a table

Parameters: - table (string) (required): No description - schema (string) (optional): No description

list_columns

Description: List columns in a specific table

Parameters: - table (string) (required): No description - schema (string) (optional): No description

execute_query

Description: Execute a SQL query against PostgreSQL (subject to read-only restrictions)

Parameters: - query (string) (required): No description - limit (string) (optional): No description

explain_query

Description: Get query execution plan for a SQL query

Parameters: - query (string) (required): No description

get_database_info

Description: Get information about the PostgreSQL database

Parameters: - No parameters required

get_table_stats

Description: Get statistics for a specific table

Parameters: - table (string) (required): No description - schema (string) (optional): No description

list_indexes

Description: List indexes for a specific table

Parameters: - table (string) (required): No description - schema (string) (optional): No description

list_constraints

Description: List constraints for a specific table

Parameters: - table (string) (required): No description - schema (string) (optional): No description

test_connection

Description: Test the database connection

Parameters: - No parameters required

get_connection_info

Description: Get information about the current database connection

Parameters: - No parameters required

Usage Examples

# Start interactive mode
mcp_platform interactive

# Deploy the template (if not already deployed)
mcpp> deploy postgres

# List available tools after deployment
mcpp> tools postgres

Then call tools:

mcpp> call postgres list_databases
mcpp> call postgres list_schemas '{"database": "example_value"}'
mcpp> call postgres list_tables '{"schema": "example_value"}'
# Deploy the template
mcp_platform deploy postgres

# Check deployment status
mcp_platform status

# View logs
mcp_platform logs postgres

# Stop the template
mcp_platform stop postgres
import asyncio
from mcp_platform.client import MCPClient

async def use_postgres():
    client = MCPClient()

    # Start the server
    deployment = client.start_server("postgres", {})

    if deployment["success"]:
        deployment_id = deployment["deployment_id"]

        try:
            # Discover available tools
            tools = client.list_tools("postgres")
            print(f"Available tools: {[t['name'] for t in tools]}")

            # Call list_databases
            result = client.call_tool("postgres", "list_databases", {})
            print(f"list_databases result: {result}")

            # Call list_schemas
            result = client.call_tool("postgres", "list_schemas", {'database': 'example_value'})
            print(f"list_schemas result: {result}")

        finally:
            # Clean up
            client.stop_server(deployment_id)
    else:
        print("Failed to start server")

# Run the example
asyncio.run(use_postgres())

Integration Examples

Add this configuration to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "postgres": {
      "command": "python",
      "args": ["-m", "mcp_platform", "connect", "postgres", "--stdio"],
      "env": {
        "LOG_LEVEL": "info"
      }
    }
  }
}

Install the MCP extension and add this to your VS Code settings (.vscode/settings.json):

{
  "mcp.servers": {
    "postgres": {
      "command": "python",
      "args": ["-m", "mcp_platform", "connect", "postgres", "--stdio"],
      "env": {
        "LOG_LEVEL": "info"
      }
    }
  }
}
# Get connection details for other integrations
mcp_platform connect postgres --llm claude
mcp_platform connect postgres --llm vscode

Configuration

For template-specific configuration options, see the main template documentation. Common configuration methods:

# Deploy with environment variables
mcp_platform deploy postgres --env KEY=VALUE
# Deploy with configuration
mcp_platform deploy postgres --config key=value

# Deploy with nested configuration
mcp_platform deploy postgres --config category__property=value
# Deploy with config file
mcp_platform deploy postgres --config-file config.json

Troubleshooting

Common Issues

  1. Template not found: Ensure the template name is correct

    mcp_platform list  # List available templates
    

  2. Connection issues: Check if the server is running

    mcp_platform status
    

  3. Tool discovery fails: Try refreshing the tool cache

    mcpp> tools postgres --refresh
    

Debug Mode

Enable debug logging for troubleshooting:

# Interactive CLI with debug
LOG_LEVEL=debug mcp_platform interactive
# Deploy with debug logging
mcp_platform deploy postgres --config log_level=debug

For more help, see the main documentation or open an issue in the repository.