An MCP server that provides tools to interact with PostgreSQL databases.
A Model Context Protocol (MCP) server that provides tools to interact with PostgreSQL databases. Built using the official Kotlin MCP SDK for robust and standardized protocol compliance.
database.properties
)Tool Name | Description | Required Parameters | Optional Parameters | Returns |
---|---|---|---|---|
postgres_query | Execute SELECT queries against the database | sql (string) | environment (staging/release/production) | Query results in table format |
postgres_list_tables | List all tables in the database | None | environment (staging/release/production) | List of table names |
postgres_get_table_schema | Get detailed schema information for a table | table_name (string) | environment (staging/release/production) | Column details with data types, constraints, and relationship indicators |
postgres_get_relationships | Get table relationships (FK, PK, constraints) | table_name (string) | environment (staging/release/production) | Primary keys, foreign keys, referenced by, unique constraints |
postgres_suggest_joins | Suggest JOIN queries based on relationships | table_name (string) | environment (staging/release/production) | Suggested JOIN conditions and example queries |
postgres_get_database_info | Get database name and connection information | None | environment (staging/release/production) | Database name, version, driver info, and connection details |
postgres_connection_stats | Get connection pool statistics and health info | None | None | HikariCP pool status, metrics, and health information |
Create a database.properties
file in src/main/resources/
with your database connection details:
# PostgreSQL Database Configuration
# All sensitive information should be provided via environment variables
# Staging Environment
database.staging.jdbc-url=${POSTGRES_STAGING_JDBC_URL}
database.staging.username=${POSTGRES_STAGING_USERNAME}
database.staging.password=${POSTGRES_STAGING_PASSWORD}
# Release Environment
database.release.jdbc-url=${POSTGRES_RELEASE_JDBC_URL}
database.release.username=${POSTGRES_RELEASE_USERNAME}
database.release.password=${POSTGRES_RELEASE_PASSWORD}
# Production Environment
database.production.jdbc-url=${POSTGRES_PRODUCTION_JDBC_URL}
database.production.username=${POSTGRES_PRODUCTION_USERNAME}
database.production.password=${POSTGRES_PRODUCTION_PASSWORD}
# HikariCP Connection Pool Configuration (Optional)
# Uses sensible defaults if not specified
# Optional: Override default pool sizes per environment
hikari.staging.maximum-pool-size=5
hikari.staging.minimum-idle=1
hikari.release.maximum-pool-size=8
hikari.release.minimum-idle=2
hikari.production.maximum-pool-size=15
hikari.production.minimum-idle=3
Set the required environment variables for your database connections:
# Staging Environment
export POSTGRES_STAGING_JDBC_URL="jdbc:postgresql://localhost:5432/mydb_staging"
export POSTGRES_STAGING_USERNAME="your_staging_username"
export POSTGRES_STAGING_PASSWORD="your_staging_password"
# Release Environment
export POSTGRES_RELEASE_JDBC_URL="jdbc:postgresql://localhost:5432/mydb_release"
export POSTGRES_RELEASE_USERNAME="your_release_username"
export POSTGRES_RELEASE_PASSWORD="your_release_password"
# Production Environment
export POSTGRES_PRODUCTION_JDBC_URL="jdbc:postgresql://prod-host:5432/mydb_production"
export POSTGRES_PRODUCTION_USERNAME="your_production_username"
export POSTGRES_PRODUCTION_PASSWORD="your_production_password"
For Windows (PowerShell):
$env:POSTGRES_STAGING_JDBC_URL="jdbc:postgresql://localhost:5432/mydb_staging"
$env:POSTGRES_STAGING_USERNAME="your_staging_username"
$env:POSTGRES_STAGING_PASSWORD="your_staging_password"
# ... repeat for release and production
For Docker/Container environments:
environment:
- POSTGRES_STAGING_JDBC_URL=jdbc:postgresql://localhost:5432/mydb_staging
- POSTGRES_STAGING_USERNAME=your_staging_username
- POSTGRES_STAGING_PASSWORD=your_staging_password
The build system requires a jarSuffix
parameter to create database-specific JAR files:
# Build JAR for specific database system
./gradlew shadowJar -PjarSuffix=incidents
./gradlew shadowJar -PjarSuffix=users
./gradlew shadowJar -PjarSuffix=analytics
./gradlew shadowJar -PjarSuffix=payroll
This creates JAR files with descriptive names:
build/libs/postgres-mcp-tool-incidents.jar
build/libs/postgres-mcp-tool-users.jar
build/libs/postgres-mcp-tool-analytics.jar
build/libs/postgres-mcp-tool-payroll.jar
Note: The jarSuffix
parameter is required. Running ./gradlew shadowJar
without it will fail with a clear error message.
This naming convention enables you to manage multiple database systems efficiently:
database.properties
for the target database system./gradlew shadowJar -PjarSuffix=incidents
Example Workflow:
# Configure database.properties for incidents database
# Build incidents JAR
./gradlew shadowJar -PjarSuffix=incidents
# Update database.properties for users database
# Build users JAR
./gradlew shadowJar -PjarSuffix=users
# Update database.properties for analytics database
# Build analytics JAR
./gradlew shadowJar -PjarSuffix=analytics
All tools support environment-based database routing with an optional environment
parameter:
staging
(default) - Routes to staging databaserelease
- Routes to release databaseproduction
- Routes to production databaseAI agents automatically extract environment information from user prompts:
environment: "production"
environment: "staging"
environment: "release"
Add this configuration to your AI agent's MCP configuration file:
Add to your claude_desktop_config.json
:
{
"mcpServers": {
"postgres-incidents": {
"command": "java",
"args": ["-jar", "/absolute/path/to/postgres-mcp-tool-incidents.jar"]
},
"postgres-users": {
"command": "java",
"args": ["-jar", "/absolute/path/to/postgres-mcp-tool-users.jar"]
},
"postgres-analytics": {
"command": "java",
"args": ["-jar", "/absolute/path/to/postgres-mcp-tool-analytics.jar"]
}
}
}
Single Database Setup:
{
"mcpServers": {
"postgres-mcp-tool": {
"command": "java",
"args": ["-jar", "/absolute/path/to/postgres-mcp-tool-incidents.jar"]
}
}
}
In the Augment IntelliJ plugin, add MCP servers for each database system:
For Incidents Database:
postgres-incidents
java -jar /absolute/path/to/postgres-mcp-tool-incidents.jar
For Users Database:
postgres-users
java -jar /absolute/path/to/postgres-mcp-tool-users.jar
For Analytics Database:
postgres-analytics
java -jar /absolute/path/to/postgres-mcp-tool-analytics.jar
For other MCP-compatible AI agents, use the standard MCP server configuration format:
Multiple Database Systems:
[
{
"name": "postgres-incidents",
"command": "java",
"args": ["-jar", "/absolute/path/to/postgres-mcp-tool-incidents.jar"],
"env": {}
},
{
"name": "postgres-users",
"command": "java",
"args": ["-jar", "/absolute/path/to/postgres-mcp-tool-users.jar"],
"env": {}
}
]
Single Database System:
{
"name": "postgres-mcp-tool",
"command": "java",
"args": ["-jar", "/absolute/path/to/postgres-mcp-tool-incidents.jar"],
"env": {}
}
Before using the MCP server, ensure you have:
./gradlew shadowJar -PjarSuffix=<database-name>
Since you can create multiple JAR files for different database systems, you can:
This server is built using:
postgres-mcp-tool/
āāā src/
ā āāā main/
ā ā āāā kotlin/
ā ā ā āāā PostgreSqlMcpServer.kt # Main MCP server implementation
ā ā ā āāā PostgreSqlRepository.kt # Database operations and queries
ā ā ā āāā HikariConnectionManager.kt # Connection pool management
ā ā ā āāā DatabaseConnectionConfig.kt # Database configuration DTO
ā ā āāā resources/
ā ā āāā database.properties # Database configuration
ā āāā test/kotlin/
ā āāā PostgreSqlMcpServerTest.kt # Integration tests
ā āāā DatabaseConnectionConfigTest.kt # DTO unit tests
ā āāā DatabaseConfigurationTest.kt # Configuration integration tests
āāā build.gradle.kts # Build configuration
āāā docker-compose.yml # Docker setup for testing
āāā init.sql # Sample database schema
āāā README.md # This documentation
jdbc:postgresql://host:port/database
./gradlew shadowJar -PjarSuffix=<database-name>
instead of ./gradlew shadowJar
postgres-mcp-tool-incidents.jar
for incidents database)Check your AI agent's logs for errors. For example:
Claude Desktop:
# macOS/Linux
tail -f ~/Library/Logs/Claude/mcp*.log
# Windows
# Check %APPDATA%\Claude\Logs\
Other AI Agents:
š Updated: This server has been migrated from a custom JSON-RPC implementation to use the official Kotlin MCP SDK, providing:
Server
class from the official SDKserver.addTool()
methodStdioServerTransport
with proper kotlinx.io integrationdatabase.properties
with simplified formatlistChanged
supportThis migration ensures the server remains compatible with all MCP clients while benefiting from the official SDK's improvements and future updates.
This project is licensed under the MIT License.
A server for managing PostgreSQL databases, enabling comprehensive database operations.
Interact with the microCMS headless CMS API, enabling AI assistants to manage content.
A production-ready MCP server for Customer Relationship Management (CRM) functionality, built with TypeScript and SQLite.
Query and manage data through CData Connect Cloud, providing a unified interface to various data sources.
A Model Context Protocol Server for MongoDB
A server for accessing and interacting with a Neo4j graph database, configured via environment variables.
Provides financial data. Requires external Python dependencies installed with the uv package manager.
Knowledge graph-based persistent memory system
Access the ChEMBL chemical database for drug discovery, chemical informatics, and bioactivity research using specialized tools via its REST API.
A lightweight server to connect AI assistants with Kintone applications and data.