A Model Context Protocol (MCP) server that provides PostgreSQL database access with query execution and schema inspection capabilities.
This MCP server enables AI assistants (like Claude) to interact with a PostgreSQL database containing data from multiple systems:
- cs (CustomerScoreView): Customer and credit assessment data
- dms (Data Management System): Document management data
- los (Loan Management System): Loan and payment data
- mls (Mahatheun Leasing System): Contract and asset leasing data
- ✅ Query Execution: Execute SQL SELECT, INSERT, UPDATE, DELETE queries
- ✅ Schema Inspection: List schemas, tables, and column details
- ✅ Multi-Schema Support: Organize data by system (cs, dms, los, mls)
- ✅ Docker Setup: PostgreSQL in Docker with automatic initialization
- ✅ CSV Import: Sample data included and ready to import
- Python 3.10 or higher
- Docker and Docker Compose
- pip (Python package installer)
-
Clone or navigate to the project directory:
cd c:\Users\chaya\project\mcp-database
-
Install Python dependencies:
pip install -r requirements.txt
-
Configure environment variables:
copy .env.example .env
Edit
.envif you need to change database credentials (optional).
Start the PostgreSQL container with Docker Compose:
docker-compose up -dVerify the database is running:
docker-compose psThe database will automatically initialize with schemas and sample data. Check the schemas:
docker-compose exec postgres psql -U postgres -d mcp_database -c "\dn"List tables in a schema:
docker-compose exec postgres psql -U postgres -d mcp_database -c "\dt cs.*"Sample CSV files are provided in raw_data/. To import them into the database:
docker-compose exec postgres bash -c "cd /raw_data && find . -name '*.csv' -type f"Import a specific CSV file:
docker-compose exec postgres psql -U postgres -d mcp_database -c "\COPY cs.customers FROM '/raw_data/cs/customers.csv' WITH CSV HEADER;"
docker-compose exec postgres psql -U postgres -d mcp_database -c "\COPY dms.documents FROM '/raw_data/dms/documents.csv' WITH CSV HEADER;"
docker-compose exec postgres psql -U postgres -d mcp_database -c "\COPY los.loans FROM '/raw_data/los/loans.csv' WITH CSV HEADER;"
docker-compose exec postgres psql -U postgres -d mcp_database -c "\COPY mls.contracts FROM '/raw_data/mls/contracts.csv' WITH CSV HEADER;"Run the server directly to test:
python src/server.pyThe server will start and listen for MCP messages via stdio.
To use this MCP server with Claude Desktop, add it to your Claude configuration file:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Add this configuration:
{
"mcpServers": {
"mcp-database": {
"command": "python",
"args": ["c:\\Users\\chaya\\project\\mcp-database\\src\\server.py"],
"env": {
"DB_HOST": "localhost",
"DB_PORT": "5432",
"DB_NAME": "mcp_database",
"DB_USER": "postgres",
"DB_PASSWORD": "postgres"
}
}
}
}Restart Claude Desktop to load the server.
Lists all available database schemas.
Example:
Can you list all database schemas?
Lists all tables, optionally filtered by schema.
Parameters:
schema(optional): Schema name to filter (e.g., "cs", "dms", "los", "mls")
Example:
Show me all tables in the cs schema
Get detailed column information for a specific table.
Parameters:
table_name(required): Name of the tableschema(optional): Schema name (default: "public")
Example:
Describe the structure of the customers table in the cs schema
Execute a SQL query on the database.
Parameters:
query(required): SQL query stringparams(optional): Array of parameters for parameterized queries
Examples:
Query all customers with credit score above 700
SELECT * FROM cs.customers WHERE credit_score > 700
Get total loan amount by customer
SELECT customer_code, SUM(loan_amount) as total_loans
FROM los.loans
GROUP BY customer_code
customers: Customer information and credit scorescredit_assessments: Credit assessment history
documents: Document metadata and storage infodocument_versions: Document version history
loans: Loan accounts and termspayments: Payment history
contracts: Lease contract informationassets: Asset details for leased itemslease_payments: Lease payment records
mcp-database/
├── src/
│ ├── server.py # Main MCP server
│ ├── database.py # Database connection manager
│ └── tools.py # MCP tool definitions
├── db/
│ └── init.sql # Database initialization script
├── raw_data/
│ ├── cs/ # CustomerScoreView CSV files
│ ├── dms/ # Data Management System CSV files
│ ├── los/ # Loan Management System CSV files
│ └── mls/ # Mahatheun Leasing System CSV files
├── docker-compose.yml # Docker configuration
├── requirements.txt # Python dependencies
├── pyproject.toml # Python project metadata
└── .env.example # Environment variable template
# Check logs
docker-compose logs postgres
# Restart container
docker-compose restart postgres- Ensure PostgreSQL is running:
docker-compose ps - Check port 5432 is not in use by another process
- Verify
.envfile has correct credentials
# Reinstall dependencies
pip install --upgrade -r requirements.txtTo extend the server:
- Add new tools in
src/tools.py - Register handlers in
src/server.py - Update database schema in
db/init.sql - Add sample data in
raw_data/
This project is provided as-is for database integration purposes.