mcp_client_python_getting_started
mcp client (following getting started tutorial on modelcontextprotocol.io)
GitHubスター
0
ユーザー評価
未評価
お気に入り
0
閲覧数
5
フォーク
0
イシュー
0
README
MCP Client Python Getting Started
Note: This project follows the Model Context Protocol (MCP) Getting Started tutorial for client developers. The official code sample can also be found at github.com/modelcontextprotocol/quickstart-resources/tree/main/mcp-client-python.
This project provides a Python client for interacting with an MCP (Model Context Protocol) server using Anthropic's Claude models and tool use. It demonstrates how to connect to a remote MCP server, send queries, and process tool calls via Claude.
Features
- Connects to a Python or Node.js MCP server via stdio
- Uses Anthropic Claude (via the
anthropic
Python SDK) for LLM-powered tool use - Interactive chat loop for sending queries and receiving responses
- Automatic tool discovery and invocation
Requirements
- Python 3.10+
- An Anthropic API key (get one here)
- Access to an MCP server script (Python or Node.js)
Installation
- Clone this repository and navigate to the
mcp-client
directory:git clone <repo-url> cd mcp-client
- Install dependencies (preferably in a virtual environment):
pip install -e . # or pip install anthropic mcp python-dotenv
Setup
Set your Anthropic API key:
- Create a
.env
file in themcp-client
directory with the following content:ANTHROPIC_API_KEY=your-anthropic-api-key-here
- Alternatively, export it in your shell:
export ANTHROPIC_API_KEY=your-anthropic-api-key-here
- Create a
Prepare an MCP server script:
- You need a compatible MCP server script (Python
.py
or Node.js.js
). - Example:
python my_mcp_server.py
ornode my_mcp_server.js
- You need a compatible MCP server script (Python
Usage
Run the client and connect to your MCP server:
uv run client.py <path_to_server_script>
eg.
uv run client.py ../../mcp_python_getting_started3/weather/weather.py
- Replace
<path_to_server_script>
with the path to your MCP server script (e.g.,../my_mcp_server.py
). - The client will connect, list available tools, and start an interactive chat loop.
- Type your queries and press Enter. Type
quit
to exit.
Example
python client.py ../my_mcp_server.py
Project Structure
client.py
- Main client implementationpyproject.toml
- Project metadata and dependencies.env
- (Not included) Place your Anthropic API key here
Environment Variables
ANTHROPIC_API_KEY
(required): Your Anthropic Claude API key. Get one here.
License
MIT