MCP Client
- other
About
What is MCP Client?
MCP Client is a Python implementation of the Model Context Protocol (MCP) that integrates with Claude 3.5 Sonnet. It runs on the command line or through a Chainlit UI, targeting developers who need to connect AI assistants to tools like PostgreSQL databases.
How to use MCP Client?
Ensure Python 3.12+, Node.js, and uv (or pip) are installed. Clone the repository, create and activate a virtual environment, then install dependencies: uv add mcp anthropic python-dotenv chainlit asyncpg and npm install @modelcontextprotocol/server-postgres. Add your Anthropic API key to a .env file. Run in CLI mode with uv run client.py <path-to-mcp-server> <database-url>, or in UI mode by first creating a PostgreSQL database named chat_history, running python app/init_db.py, then executing chainlit run app/chainlit_app.py. Type quit to exit.
Key features of MCP Client
- Interactive chat with Claude 3.5 Sonnet
- PostgreSQL database integration via MCP
- Support for Python and JavaScript MCP servers
- Tool-based query processing
- Command line and Chainlit UI modes
Use cases of MCP Client
- Query a PostgreSQL database using natural language
- Build a chat interface with live database access
- Prototype an AI assistant that fetches and processes database records
- Develop applications using the Model Context Protocol with minimal setup
FAQ from MCP Client
What are the prerequisites to run MCP Client?
You need Python 3.12 or higher, a PostgreSQL database, Node.js, and the uv package manager (or pip). An Anthropic API key is required.
How do I connect MCP Client to a database?
Pass the path to the MCP server JavaScript file and your PostgreSQL connection string as arguments to the client: uv run client.py ./path/to/server-postgres/index.js postgresql://localhost/your_database.
Can I use other MCP servers beyond PostgreSQL?
Yes. The README states support for both Python and JavaScript MCP servers, so you can adapt the client to any MCP-compatible server.
How do I run MCP Client with a graphical interface?
Use Chainlit: create a PostgreSQL database called chat_history, run python app/init_db.py to initialize tables, then start the UI with chainlit run app/chainlit_app.py.
What license does MCP Client use?
The project is licensed under the MIT License.
Details
- Author
- garvk
- Category
- other
- Repository
- garvk/mcp-postgresql-agent-hack
MCP Client
A Python client implementation for the Model Context Protocol (MCP) that integrates with Claude 3.5 Sonnet.
Prerequisites
- Python 3.12 or higher
- PostgreSQL database
- Node.js (for running the PostgreSQL MCP server)
- uv package manager (recommended) or pip
Installation
1. Clone the repository:
2. Create and activate a virtual environment:
``bash
Create virtual environment
uv venv
Activate virtual environment
On Windows:
.venv\Scripts\activateOn Unix or MacOS:
source .venv/bin/activate
3. Install dependencies
bashFor python equivalent of:
Install required packages
uv add mcp anthropic python-dotenv chainlit asyncpg
or install from requirements.txt
For node:
npm initnpm install @modelcontextprotocol/server-postgres
bash.env
4. Create afile in the project root and add your Anthropic API key:
ANTHROPIC_API_KEY=your_api_key_here
Usage
The client can be run in two modes:
1. Command Line Interface:
bashuv run client.py <path-to-mcp-server> <database-url>
For example:
bashuv run client.py ./node_modules/@modelcontextprotocol/server-postgres/dist/index.js postgresql://localhost/your_database
bash python app/init_db.pychat_history
2. UI with Chainlit
For first time setup:
1. Create a db in postgres with nameinit_db.py
2. initialise tables in db by running.
To start chainlit run:
bashchainlit run app/chainlit_app.py
`
Where:
-
<path-to-mcp-server> is the path to the MCP server JavaScript file
- <database-url> is your PostgreSQL connection string
Once running, you can interact with the client through the command line interface. Type your queries and type 'quit' to exit.
Features
- Interactive chat interface with Claude 3.5 Sonnet
- Integration with PostgreSQL database through MCP
- Support for both Python and JavaScript MCP servers
- Tool-based query processing
Development
The project uses:
-
anthropic for Claude API integration
- mcp for Model Context Protocol implementation
- python-dotenv` for environment variable management
License
MIT License