
mcp client server
一个用于与 MCP 服务器交互的 Python 客户端,包含天气工具示例。
Repository Info
About This Server
一个用于与 MCP 服务器交互的 Python 客户端,包含天气工具示例。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP Client
A Python client for interacting with MCP servers, featuring a weather tool server as an example. The client uses Anthropic's Claude API for natural language queries and can connect to any compatible MCP server script.
Features
- Interactive chat client for MCP servers
- Example weather server (
server/weather.py) with:- US state weather alerts
- Location-based weather forecasts (via NWS API)
- Extensible: connect to any MCP-compatible server script
- Uses Anthropic Claude API for natural language understanding
Requirements
- Python 3.12+
- Anthropic API key
- MCP Python package (
mcp>=1.9.2) - uv (for running with isolated environments, optional but recommended)
Installation
-
Clone the repository:
git clone <your-repo-url> cd mcp-client -
Install dependencies:
uv pip install -r requirements.txtOr, if you use
uvandpyproject.toml:uv pip install -
Set up your Anthropic API key:
- Create a
.envfile in the project root:ANTHROPIC_API_KEY=your-anthropic-api-key-here - The
.envfile is in.gitignoreand will be loaded automatically.
- Create a
Usage
Start the Weather Server
The example weather server is located at server/weather.py. It provides two tools: get_alerts and get_forecast.
Run the Client
You can connect the client to the weather server using:
uv run client.py ./server/weather.py
Or, if you prefer plain Python:
python client.py ./server/weather.py
You should see output like:
Connected to server with tools: ['get_alerts', 'get_forecast']
MCP Client Started!
Type your queries or 'quit' to exit.
Example Queries
What is the weather in New York?Are there any weather alerts for CA?Give me the forecast for latitude 40.7, longitude -74.0
Exiting
Type quit to exit the chat loop.
Project Structure
.
├── client.py # Main MCP client
├── server/
│ └── weather.py # Example weather MCP server
├── pyproject.toml # Project metadata and dependencies
├── .env # (Not committed) Your API keys
├── .gitignore
└── README.md
Development
- The client loads environment variables from
.envusingpython-dotenv. - The weather server uses the US National Weather Service API and requires internet access.
Troubleshooting
- Anthropic API errors:
Ensure your API key is valid and has sufficient credits. - Python version:
The project requires Python 3.12 or newer. - Network issues:
The weather server needs to reachhttps://api.weather.gov.
License
Quick Start
Clone the repository
git clone https://github.com/ivanliu1989/mcp-client-serverInstall dependencies
cd mcp-client-server
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.