MCP客户端原型

一个用于连接MCP服务器的客户端原型,支持Anthropic Claude、Ollama和LiteLLM等多种模型提供商,方便开发者在本地环境中配置、测试和调试MCP服务。

  • by jurajama
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 jurajama/mcp-client-proto

使用说明

Prototyping MCP client implementation

Setup

Create a virtual environment and install dependencies:

python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt

Note that Python 3.10 or later is required as mcp package does not work with Python 3.9 or older versions.

Configuration

Create a .env file in the project root. The client supports three model providers.


Option 1: Anthropic Claude (default)

MODEL_PROVIDER=anthropic
CLAUDE_API_KEY=your_api_key_here

Get an API key at https://console.anthropic.com. The client uses claude-opus-4-6 by default.


Option 2: Local Ollama (llama, mistral, etc.)

Install Ollama, then pull a model and start the server:

ollama pull llama3.2
ollama serve
MODEL_PROVIDER=ollama
OLLAMA_MODEL=llama3.2
# OLLAMA_BASE_URL=http://localhost:11434/v1  # optional, this is the default

For tool/function calling to work, use a model that supports it (e.g. llama3.1, llama3.2, mistral-nemo).


Option 3: LiteLLM gateway

Point the client at a LiteLLM proxy/gateway. The gateway's token is sent as a standard Authorization: Bearer header via the OpenAI SDK.

MODEL_PROVIDER=litellm
LITELLM_BASE_URL=https://your-litellm-gateway/v1
LITELLM_API_KEY=your_gateway_token
LITELLM_MODEL=your-model-alias   # the model alias configured on your gateway

If your gateway expects the token under a different header instead of Authorization: Bearer, you'll need to adjust the OpenAI(...) client construction in client.py accordingly (e.g. via default_headers).


Running

Make sure your MCP server is running at http://localhost:8000/mcp (or set MCP_SERVER_URL in .env to point elsewhere), then:

python client.py