ivanliu1989
MCP Serverivanliu1989public

mcp client server

一个用于与 MCP 服务器交互的 Python 客户端,包含天气工具示例。

Repository Info

0
Stars
0
Forks
0
Watchers
0
Issues
Python
Language
-
License

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

  1. Clone the repository:

    git clone <your-repo-url>
    cd mcp-client
    
  2. Install dependencies:

    uv pip install -r requirements.txt
    

    Or, if you use uv and pyproject.toml:

    uv pip install
    
  3. Set up your Anthropic API key:

    • Create a .env file in the project root:
      ANTHROPIC_API_KEY=your-anthropic-api-key-here
      
    • The .env file is in .gitignore and will be loaded automatically.

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 .env using python-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 reach https://api.weather.gov.

License

Quick Start

1

Clone the repository

git clone https://github.com/ivanliu1989/mcp-client-server
2

Install dependencies

cd mcp-client-server
npm install
3

Follow the documentation

Check the repository's README.md file for specific installation and usage instructions.

Repository Details

Ownerivanliu1989
Repomcp-client-server
LanguagePython
License-
Last fetched8/10/2025

Recommended MCP Servers

💬

Discord MCP

Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.

integrationsdiscordchat
🔗

Knit MCP

Connect AI agents to 200+ SaaS applications and automate workflows.

integrationsautomationsaas
🕷️

Apify MCP Server

Deploy and interact with Apify actors for web scraping and data extraction.

apifycrawlerdata
🌐

BrowserStack MCP

BrowserStack MCP Server for automated testing across multiple browsers.

testingqabrowsers

Zapier MCP

A Zapier server that provides automation capabilities for various apps.

zapierautomation