AgenticMCP
Provides secure, role-based access to PostgreSQL databases, enabling AI agents to query, insert, update, delete data with fine-grained permissions.
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., "@AgenticMCPshow me the users table schema"
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.
AgenticMCP - PostgreSQL MCP Server
A Model Context Protocol (MCP) server that provides secure, role-based access to PostgreSQL databases for AI agents.
Features
PostgreSQL Integration: Connect to any PostgreSQL database
Role-Based Access Control (RBAC): Fine-grained permissions at table, column, and row levels
Safe Query Building: All queries use parameterized statements to prevent SQL injection
Docker Support: Easy deployment with Docker and Docker Compose
CI/CD Ready: GitHub Actions workflows included
Multiple MCP Tools: Comprehensive tools for database operations
Related MCP server: @pilat/mcp-datalink
Available MCP Tools
Tool | Description | Permission Required |
| List all accessible tables | Any role |
| Get table schema | Read access |
| Query data with filtering, sorting, pagination | Read access |
| Insert new rows | Write access |
| Update existing rows | Write access |
| Delete rows | Write access |
| Execute raw SQL SELECT | Admin only |
| Get current role and permissions | Any role |
| Reload permissions configuration | Any role |
Quick Start
1. Using Docker Compose (Recommended)
# Clone the repository
git clone https://github.com/YOUR_USERNAME/AgenticMCP.git
cd AgenticMCP
# Start PostgreSQL and the MCP server
docker compose -f docker/docker-compose.yml up -d
# Check logs
docker compose -f docker/docker-compose.yml logs -fThis will start:
PostgreSQL on port 5432
Sample database with test data
MCP server instances for different roles
2. Local Installation
# Create virtual environment
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # Linux/Mac
# Install with dependencies
pip install -e ".[dev]"
# Set environment variables
export MCP_DB_HOST=localhost
export MCP_DB_PORT=5432
export MCP_DB_NAME=app_db
export MCP_DB_USER=app_user
export MCP_DB_PASSWORD=your_password
export MCP_ROLE=reader
# Run the server
agenticmcp3. Using Docker Image
# Pull the image
docker pull ghcr.io/YOUR_USERNAME/agenticmcp:latest
# Run the server
docker run -i --rm \
-e MCP_DB_HOST=host.docker.internal \
-e MCP_DB_PORT=5432 \
-e MCP_DB_NAME=app_db \
-e MCP_DB_USER=app_user \
-e MCP_DB_PASSWORD=your_password \
-e MCP_ROLE=reader \
-v $(pwd)/config:/app/config:ro \
ghcr.io/YOUR_USERNAME/agenticmcp:latestConfiguration
Environment Variables
Variable | Description | Default |
| PostgreSQL host | localhost |
| PostgreSQL port | 5432 |
| Database name | postgres |
| Database user | postgres |
| Database password | (empty) |
| Role for access control | reader |
| User ID for row-level security | (optional) |
| Tenant ID for multi-tenant | (optional) |
| Path to permissions.yaml | config/permissions.yaml |
| Maximum rows per query | 1000 |
| Query timeout in seconds | 30 |
Permissions Configuration
Edit config/permissions.yaml to define roles and access:
version: "1.0"
default_role: "reader"
roles:
admin:
description: "Full administrative access"
tables: ["*"]
operations: ["*"]
reader:
description: "Read-only access"
tables: ["users", "products"]
operations: ["read"]
columns:
users: ["id", "name"] # Exclude sensitive columns
writer:
description: "Read and write access"
tables: ["users", "orders"]
operations: ["read", "write"]
row_filters:
orders: "user_id = {user_id}" # Row-level security
tables:
users:
primary_key: "id"
columns:
- name: id
type: "integer"
- name: email
type: "text"
sensitive: true
visible_to: ["admin"]Client Configuration
Claude Desktop
Add to your Claude Desktop config (claude_desktop_config.json):
{
"mcpServers": {
"agenticmcp-postgres": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MCP_DB_HOST=host.docker.internal",
"-e", "MCP_DB_PORT=5432",
"-e", "MCP_DB_NAME=app_db",
"-e", "MCP_DB_USER=app_user",
"-e", "MCP_DB_PASSWORD=your_password",
"-e", "MCP_ROLE=reader",
"ghcr.io/YOUR_USERNAME/agenticmcp:latest"
]
}
}
}See examples/claude_desktop_config.json for more examples.
MCP Inspector
# Start the server
agenticmcp
# In another terminal, run inspector
npx @modelcontextprotocol/inspectorDevelopment
Setup
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run with coverage
pytest --cov=agenticmcp
# Format code
black src/
# Lint
ruff check src/
# Type check
mypy src/Database Initialization
The docker/init.sql file creates sample tables for testing:
users- User accountsproducts- Product catalogorders- Orders with statusorder_items- Order line itemsanalytics- Analytics metrics
CI/CD
GitHub Actions
The project includes two workflows:
CI Workflow (.github/workflows/ci.yml):
Runs on push and pull requests
Executes linting, type checking, and tests
Builds Docker image
Release Workflow (.github/workflows/release.yml):
Triggers on version tags (
v*.*.*)Builds and pushes Docker image to GHCR
Creates GitHub release
Manual Docker Build
# Build the image
docker build -f docker/Dockerfile -t agenticmcp:test .
# Run the container
docker run -i --rm \
-e MCP_DB_HOST=host.docker.internal \
-e MCP_DB_NAME=app_db \
-e MCP_ROLE=admin \
agenticmcp:testSecurity
SQL Injection Prevention: All queries use parameterized statements
Row-Level Security: Support for WHERE clause injection based on user context
Column-Level Filtering: Sensitive columns can be hidden from specific roles
Admin-Only Raw Queries: Raw SQL execution restricted to admin role
Connection Pooling: Efficient database connection management
Project Structure
agenticmcp/
├── src/agenticmcp/
│ ├── __init__.py
│ ├── server.py # MCP server implementation
│ ├── database.py # Database connection and queries
│ ├── permissions.py # Access control system
│ ├── config.py # Configuration management
│ └── tools/ # MCP tool implementations
├── config/
│ └── permissions.yaml # Role and table permissions
├── docker/
│ ├── Dockerfile
│ ├── docker-compose.yml
│ └── init.sql # Sample database schema
├── .github/workflows/
│ ├── ci.yml # Continuous Integration
│ └── release.yml # Release automation
├── examples/
│ ├── claude_desktop_config.json
│ └── inspector_config.json
└── tests/
├── test_server.py
├── test_database.py
└── test_permissions.pyLicense
MIT
Contributing
Fork the repository
Create a feature branch
Make your changes
Add tests
Submit a pull request
Support
For issues and questions, please use the GitHub issue tracker.
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
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/mattma87/AgenticMCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server