Skip to content

PostgreSQL MCP Server API Reference

Production-ready PostgreSQL MCP server for secure database access with configurable authentication, read-only mode, SSH tunneling, and comprehensive query capabilities using FastMCP and SQLAlchemy

This reference provides detailed information about all available tools and their parameters.

Available Tools

list_databases

Description: List all databases on the PostgreSQL server

Parameters: No parameters required

Example Usage:

mcp_platform call postgres list_databases
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "list_databases", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "list_databases", "arguments": {}}'

list_schemas

Description: List all accessible database schemas for a given database

Parameters:

  • database (string) (required): Database name to list schemas from

Example Usage:

mcp_platform call postgres list_schemas
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "list_schemas", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "list_schemas", "arguments": {}}'

list_tables

Description: List tables in a specific schema

Parameters:

  • schema (string) (optional): Schema name to list tables from

Example Usage:

mcp_platform call postgres list_tables
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "list_tables", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "list_tables", "arguments": {}}'

describe_table

Description: Get detailed schema information for a table

Parameters:

  • table (string) (required): Table name to describe
  • schema (string) (optional): Schema name containing the table

Example Usage:

mcp_platform call postgres describe_table
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "describe_table", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "describe_table", "arguments": {}}'

list_columns

Description: List columns in a specific table

Parameters:

  • table (string) (required): Table name to list columns from
  • schema (string) (optional): Schema name containing the table

Example Usage:

mcp_platform call postgres list_columns
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "list_columns", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "list_columns", "arguments": {}}'

execute_query

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

Parameters:

  • query (string) (required): SQL query to execute
  • limit (integer) (optional): Maximum number of rows to return (optional)

Example Usage:

mcp_platform call postgres execute_query
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "execute_query", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "execute_query", "arguments": {}}'

explain_query

Description: Get query execution plan for a SQL query

Parameters:

  • query (string) (required): SQL query to explain

Example Usage:

mcp_platform call postgres explain_query
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "explain_query", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "explain_query", "arguments": {}}'

get_database_info

Description: Get information about the PostgreSQL database

Parameters: No parameters required

Example Usage:

mcp_platform call postgres get_database_info
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "get_database_info", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "get_database_info", "arguments": {}}'

get_table_stats

Description: Get statistics for a specific table

Parameters:

  • table (string) (required): Table name to get statistics for
  • schema (string) (optional): Schema name containing the table

Example Usage:

mcp_platform call postgres get_table_stats
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "get_table_stats", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "get_table_stats", "arguments": {}}'

list_indexes

Description: List indexes for a specific table

Parameters:

  • table (string) (required): Table name to list indexes for
  • schema (string) (optional): Schema name containing the table

Example Usage:

mcp_platform call postgres list_indexes
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "list_indexes", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "list_indexes", "arguments": {}}'

list_constraints

Description: List constraints for a specific table

Parameters:

  • table (string) (required): Table name to list constraints for
  • schema (string) (optional): Schema name containing the table

Example Usage:

mcp_platform call postgres list_constraints
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "list_constraints", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "list_constraints", "arguments": {}}'

test_connection

Description: Test the database connection

Parameters: No parameters required

Example Usage:

mcp_platform call postgres test_connection
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "test_connection", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "test_connection", "arguments": {}}'

get_connection_info

Description: Get information about the current database connection

Parameters: No parameters required

Example Usage:

mcp_platform call postgres get_connection_info
from mcp_platform.client import MCPClient

client = MCPClient()
result = client.call_tool("postgres", "get_connection_info", {})
curl -X POST http://localhost:8000/v1/call \
  -H "Content-Type: application/json" \
  -d '{"template_id": "postgres", "tool_name": "get_connection_info", "arguments": {}}'

Integration Examples

For more integration examples and usage patterns, see the Usage Guide.

Support

For questions and issues related to the PostgreSQL MCP Server, please refer to: - Usage Guide for comprehensive examples - Template Overview for setup and configuration - MCP Platform Documentation for general platform usage