MCP Server PostgreSQL
A Model Context Protocol (MCP) server for PostgreSQL built with Spring Boot and Spring AI. This server provides read-only access to PostgreSQL databases through dynamic connections.
接入你的智能体
從發布者安裝。不是 PlugMCP 端點。
遠端 URL 還是本機指令? 兩種安裝方式的差異
COMPLETED: The MCP server is fully functional with the following features:
list_schemas: List all schemas in a databaselist_tables: List all tables in a specific schemaselect: Select rows from a table with optional conditions and orderingexecute_query: Execute read-only SQL queriesClone and build the project:
git clone https://github.com/luanvuhlu/mcp-server-postgres.git
cd mcp-server-postgres
mvn clean compile
Start test PostgreSQL database:
docker-compose up -d
Run the MCP server:
mvn spring-boot:run
The MCP server will start and be ready to accept connections via the Model Context Protocol.
The Docker Compose setup includes a PostgreSQL instance with sample data:
Sample schemas and tables are automatically created:
public schema: users, productssales schema: orders, order_itemsinventory schema: stockThis server can be used with any MCP-compatible client. Here are some examples:
Add the following to your Claude Desktop configuration file:
{
"mcpServers": {
"postgres": {
"command": "java",
"args": ["-jar", "target/mcp-server-postgres-1.0.0-SNAPSHOT.jar"]
}
}
}
The server implements the standard MCP protocol and can be used with any compatible client by running:
java -jar target/mcp-server-postgres-1.0.0-SNAPSHOT.jar
List all schemas in a PostgreSQL database:
{
"name": "list_schemas",
"arguments": {
"host": "localhost",
"database": "postgres",
"username": "postgres",
"password": "your_name"
}
}
List all tables in a specific schema:
{
"name": "list_tables",
"arguments": {
"host": "localhost",
"database": "postgres",
"username": "postgres",
"password": "your_name",
"schema": "public"
}
}
Select rows from a table with optional conditions and ordering:
{
"name": "select",
"arguments": {
"host": "localhost",
"database": "postgres",
"username": "postgres",
"password": "your_name",
"table": "users",
"schema": "public",
"conditions": "id > 1",
"orderBy": "username ASC",
"limit": 10
}
}
Execute a read-only SQL query:
{
"name": "execute_query",
"arguments": {
"host": "localhost",
"database": "postgres",
"username": "postgres",
"password": "your_name",
"query": "SELECT * FROM users LIMIT 10"
}
}
Configure the MCP server in src/main/resources/application.yml:
spring:
ai:
mcp:
server:
enabled: true
port: 3000
All database connections are dynamic and provided per request. No default database connection is configured.
This server implements the Model Context Protocol (MCP) specification and communicates via JSON-RPC over stdio or TCP. The server registers the following tools that can be called by MCP-compatible clients.
src/main/java/com/luanvv/mcp/
├── McpServerPostgresApplication.java # Main application
├── config/
│ └── McpServerConfig.java # MCP configuration
├── model/
│ └── DatabaseConnection.java # Connection model
├── service/
│ └── PostgresService.java # Database operations
└── tools/
├── ListSchemaTool.java # List schemas tool
├── ListTablesTool.java # List tables tool
├── SelectTool.java # Select queries tool
└── ExecuteQueryTool.java # Execute query tool
# Compile
mvn clean compile
# Run tests
mvn test
# Package
mvn clean package
# Run
mvn spring-boot:run
Build and run with Docker:
# Build image
docker build -t mcp-server-postgres .
# Run container
docker run -p 3000:3000 mcp-server-postgres
This project is licensed under the MIT License.
For issues and questions, please use the GitHub issue tracker.
Model Context Protocol (MCP) Server for PostgreSQL with Spring Boot and Spring AI
工具
尚無工具清單。遠端伺服器會在首次健康檢查後取得工具清單。
常見問題
在本頁複製適用於 Cursor、Claude Desktop、Claude Code 或 VS Code 的 stdio 設定。它使用發布者的安裝方式,而不是 PlugMCP 代理伺服器。
這筆記錄未列出必要的環境變數。
MCP Server Postgres 透過 stdio 在本機執行。
上次檢查時間:2026-10-28。 Model Context Protocol (MCP) Server for PostgreSQL with Spring Boot and Spring AI