MCP Client

MCP Client

By garvk GitHub

-

Overview

what is MCP Client?

MCP Client is a Python implementation of the Model Context Protocol (MCP) that integrates with Claude 3.5 Sonnet, allowing for interactive chat and query processing with a PostgreSQL database.

how to use MCP Client?

To use MCP Client, clone the repository, set up a virtual environment, install the necessary dependencies, and run the client either through the command line interface or a UI with Chainlit.

key features of MCP Client?

  • 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

use cases of MCP Client?

  1. Building interactive chat applications using Claude 3.5 Sonnet.
  2. Managing and querying data stored in a PostgreSQL database.
  3. Developing applications that require integration with the Model Context Protocol.

FAQ from MCP Client?

  • What are the prerequisites for using MCP Client?

You need Python 3.12 or higher, a PostgreSQL database, Node.js, and the uv package manager.

  • Can I run the client without a PostgreSQL database?

No, the client requires a PostgreSQL database for storing and managing chat history.

  • Is there a graphical user interface available?

Yes, you can use Chainlit to run a UI for the MCP Client.

Content

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:

# Create virtual environment
uv venv

# Activate virtual environment
# On Windows:
.venv\Scripts\activate
# On Unix or MacOS:
source .venv/bin/activate



  1. Install dependencies
# For python equivalent of:
# Install required packages
uv add mcp anthropic python-dotenv chainlit asyncpg

# or install from requirements.txt

# For node:
npm init

npm install @modelcontextprotocol/server-postgres
  1. Create a .env file 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:
uv run client.py <path-to-mcp-server> <database-url>

For example:

uv run client.py ./node_modules/@modelcontextprotocol/server-postgres/dist/index.js postgresql://localhost/your_database
  1. UI with Chainlit For first time setup:
  2. Create a db in postgres with name chat_history
  3. initialise tables in db by running init_db.py. bash python app/init_db.py

To start chainlit run:

chainlit 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

No tools information available.
No content found.