This project implements a Model Context Protocol (MCP) server that provides a bridge between a PostgreSQL database and an AI agent powered by Google's Gemini LLM. The server allows natural language interactions with the database through MCP endpoints.
- SQL Alchemy integration for database operations
- MCP Server implementation with standardized endpoints
- Gemini LLM-powered agent for natural language database interactions
- PostgreSQL database support
- Structured query processing and response handling
mcp-server-client/
├── main.py # Main application entry point
├── pyproject.toml # Project dependencies and configuration
├── client/
│ ├── __init__.py
│ └── db_client.py # Database client implementation
├── server/
│ ├── __init__.py
│ ├── postgres_db.py # PostgreSQL database connection and operations
│ └── weather.py # Weather-related functionality
- install uv:
pip install uv- activate virtual environment'
# for linux
source .venv/bin/activate
# for windows
.venv\Scripts\activate
- Install dependencies:
uv add mcp[cli] mcp-use psycopg2 psycopg2-binary sqlalchemy langchain-google-genai- Set up environment variables:
# create .env file
touch .env
# add this into .env file
# PostgreSQL connection
DB_URL= "postgresql://postgres:admin@localhost:5432/mydb"
GEMINI_API_KEY= "API_KEY"- start the agent
uv run client/db_client.py Below are some examples of interactions with the SQL agent:









