solana-devs-mit/MCP-Server-Client
If you are the rightful owner of MCP-Server-Client and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
This repository provides an implementation of a Model Context Protocol (MCP) client and server, focusing on weather-related tools.
MCP-Server-Client
This repository contains a Model Context Protocol (MCP) client and server implementation based on the official MCP documentation. It demonstrates how to create a client that connects to MCP servers and how to build a functional MCP server that provides weather-related tools.
Project Structure
mcp-client/: Contains an implementation of an MCP client that connects to MCP serversweather/: Contains an MCP server implementation providing weather forecast and alerts tools
MCP Client
The MCP client (mcp-client/client.py) demonstrates how to:
- Connect to an MCP server using stdio transport
- List available tools from the server
- Process user queries by combining Claude AI with MCP tools
- Handle tool calls and responses
Client Requirements
- Python 3.12+
- Dependencies:
anthropic>=0.71.0mcp>=1.18.0python-dotenv>=1.1.1
Client Usage
-
Set up your Anthropic API key in a
.envfile:ANTHROPIC_API_KEY=your_api_key_here -
Run the client, pointing it to an MCP server:
python mcp-client/client.py weather/weather.py -
Enter queries when prompted, and the client will:
- Send queries to Claude
- Process tool calls using the connected MCP server
- Return formatted responses
Weather MCP Server
The weather server (weather/weather.py) implements an MCP server that provides weather-related tools using the National Weather Service API.
Available Tools
get_alerts: Retrieve weather alerts for a US stateget_forecast: Get weather forecasts for specific coordinates
Server Requirements
- Python 3.12+
- Dependencies:
httpx>=0.28.1mcp[cli]>=1.18.0
Server Usage
Run the server directly:
python weather/weather.py
Or connect to it using the MCP client as shown above.
Creating Your Own MCP Components
Building an MCP Client
To build your own MCP client, follow the official MCP client development guide.
Key steps:
- Set up a client session using one of the available transports
- Connect to an MCP server
- Use the
list_tools()method to discover available tools - Call tools using the
call_tool()method - Process and display tool responses
Building an MCP Server
To create your own MCP server, follow the official MCP server development guide.
Key steps:
- Choose an MCP server framework (like FastMCP used in this project)
- Define tool functions with appropriate decorators
- Implement proper error handling
- Document each tool with clear descriptions and argument specifications
- Run the server with your preferred transport