| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
中文文档 | English
A Python-based PostgreSQL MCP server providing secure database operations with built-in safety checks and AST-based SQL parsing.
Set environment variable PG_ALLOW_DANGEROUS=true to enable:
| Variable | Description | Required |
|---|---|---|
| PG_HOST | PostgreSQL host address and port (format: host:port or host) | Yes |
| PG_USER | PostgreSQL username | Yes |
| PG_PASSWORD | PostgreSQL password | Yes |
| PG_DATABASE | Target database name | Yes |
| PG_ALLOW_DANGEROUS | Allow dangerous operations (true/false) | No (default: false) |
Add to your Claude Desktop configuration file:
{
"mcpServers": {
"postgresql": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/hexonal/pg-python-mcp-.git",
"pg-python-mcp"
],
"env": {
"PG_HOST": "your-postgres-host:5432",
"PG_USER": "your-username",
"PG_PASSWORD": "your-password",
"PG_DATABASE": "your-database"
}
}
}
}Lists all databases in the PostgreSQL instance (current configured database is highlighted).
Lists all tables in the currently configured database.
Describes the structure of a specified table, including column names, types, null constraints, and key information.
Parameters:
Executes SQL query statements and returns results in JSON format.
Parameters:
Security Constraints:
JSON Output Format:
{
"status": "success",
"message": "Query executed successfully, returned 2 rows",
"columns": ["id", "name", "email"],
"data": [
{
"id": 1,
"name": "User 1",
"email": "user1@example.com"
},
{
"id": 2,
"name": "User 2",
"email": "user2@example.com"
}
]
}# Install from Git
uvx --from git+https://github.com/hexonal/pg-python-mcp-.git pg-python-mcp
# Or for local development
uvx pg-python-mcp# Clone repository
git clone https://github.com/hexonal/pg-python-mcp-.git
cd pg-python-mcp
# Install dependencies
pip install -e .
# Run server
python -m pg_mcpTool: list_databases
Tool: list_tables
Tool: describe_table
Parameters: {"table_name": "users"}
Tool: execute_query
Parameters: {"query": "SELECT * FROM users LIMIT 10"}
pg-python-mcp/ ├── pg_mcp/ │ ├── __init__.py # Main MCP server entry point │ ├── __main__.py # Run script │ └── pg_handler.py # PostgreSQL handler with AST security ├── test_ast_security.py # AST security validation tests ├── test_stdio.py # MCP protocol testing ├── pyproject.toml # Project configuration ├── README.md # English documentation └── README_zh.md # Chinese documentation
# Clone project
git clone https://github.com/hexonal/pg-python-mcp-.git
cd pg-python-mcp
# Install development dependencies
pip install -e ".[dev]"
# Run security tests
python test_ast_security.py
# Test MCP protocol
python test_stdio.py
# Code formatting
black pg_mcp/
isort pg_mcp/
# Type checking
mypy pg_mcp/The server uses Abstract Syntax Tree parsing to achieve 100% accuracy in SQL security checking:
def is_query_safe(self, query: str) -> tuple[bool, str]:
"""Check query safety using AST parsing"""
try:
parsed = sqlparse.parse(query)
for statement in parsed:
is_safe, error_msg = self._check_statement_safety(statement)
if not is_safe:
return False, error_msg
return True, ""MIT License
⚠️ Important Security Guidelines:
| Back | FazBrowse Home | New Git URL |