MCP Client
A modular Python client for connecting to MCP servers, integrating with Anthropic Claude, and exposing a FastAPI-based API for handling queries and tool calls.
Features
-
MCP Client: Connects to an MCP server (Node or Python) over stdio, negotiates available tools and manages tool calls.
-
Claude AI Integration: Uses Anthropic Claude to generate natural language responses and decide when to invoke tools.
-
Tool Invocation: Handles multi-turn reasoning between Claude and external tools, returning structured responses (markdown, code, chart data).
-
FastAPI Server: Provides HTTP API endpoints for frontend integration.
-
.env support: Loads Anthropic API keys and other environment variables from a .env file.
-
CORS Support: Allows flexible frontend/backend development.
Installation
Prerequisites
-
Python 3.10+
-
An MCP server — e.g., mcp-node or compatible Python or Node MCP server.
-
An Anthropic API Key (for Claude).
Clone the Repo
git clone https://github.com/Kiran1689/mcp-proxy-server
cd mcp-proxy-server
Install the Python Dependencies
It's recommended to use a virtual environment:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv sync
Configure Environment Variables
Create a .env file in the project root:
ANTHROPIC_API_KEY=your-anthropic-api-key-here
Usage
1. Launch your MCP Server
Follow your MCP server's instructions (e.g., NodeJS or Python). Example for Node:
cd /path/to/mcp-node
npm install
npm run start
2. Run the FastAPI Server
uvicorn client_server:app --reload
By default, this will:
-
Connect to your MCP server
-
Expose endpoints at http://localhost:8000
API Endpoints
-
POST /query— Send a user query, receives structured response from Claude (may invoke tools). -
GET /tools— Lists available server tools. -
GET /server-name— Returns server name identifier.
3. Interactive Local Client (CLI)
You can run the interactive CLI for experimenting directly:
python client.py
Code Structure
-
client.py— Implements MCPClient: connects to the MCP server, interfaces with Claude, manages conversation state, processes tool calls, and structures responses. -
client_server.py— Launches a FastAPI server, provides API endpoints, manages single MCPClient instance. -
pyproject.toml— Python packaging and dependencies.
Customizing
-
You can update the system prompt for Claude in
client.pyto control formatting, chart standards, or code output. -
Tool schemas are detected live from your MCP server.
-
Extend or replace tool invocation logic as needed.
Troubleshooting
-
Check
.envis present and contains your Anthropic key. -
Ensure server path/config in
client.pymatches your MCP server. -
View server/console logs for debugging info on tool calls and Claude's responses.
License
MIT
Contributions & issues welcome!
Feel free to submit pull requests or questions.
Built with 💙 by Kiran
