Cover image
Try Now
2025-03-17

Mirror ofhttps://github.com/JackKuo666/Weather-MCP-Server

3 years

Works with Finder

0

Github Watches

1

Github Forks

0

Github Stars

Weather MCP Server

This is a Model Context Protocol (MCP) server that provides weather information using the National Weather Service (NWS) API.

Features

  • Get weather alerts for a US state
  • Get weather forecast for a specific location (using latitude and longitude)

Requirements

  • Python 3.10+
  • FastMCP
  • httpx

Installation

  1. Clone this repository
  2. Set up a virtual environment:
    python -m venv .venv
    source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`
    
  3. Install the required packages using uv:
    uv add "mcp[cli]" httpx
    

Configuration

The server uses a configuration file config.py with the following settings:

  • NWS_API_BASE: The base URL for the National Weather Service API
  • USER_AGENT: The User-Agent string used when making requests to the NWS API
  • LOG_LEVEL: The logging level (e.g., "INFO", "DEBUG")
  • LOG_FORMAT: The format string for log messages
  • REQUEST_TIMEOUT: The timeout for API requests in seconds

You can modify these settings in the config.py file to customize the server behavior.

Usage

Running the server standalone

To run the server standalone:

  1. Activate the virtual environment if not already activated:
    source .venv/bin/activate  # On Windows, use `.venv\Scripts\activate`
    
  2. Run the server:
    python weather.py
    

Using with Cline

The Weather MCP Server has been added to the Cline configuration. To use it within Cline:

  1. Ensure that Cline is properly set up and running.

  2. The Weather MCP Server will be available as a tool named "weather".

  3. You can use the following tools within Cline:

    a. get_alerts(state: str): Get weather alerts for a US state (use two-letter state code, e.g., "CA" for California) b. get_forecast(latitude: float, longitude: float): Get weather forecast for a specific location

Example usage in Cline:

# Get alerts for California
result = await mcp.call_tool("weather.get_alerts", state="CA")
print(result)

# Get forecast for San Francisco (approximate coordinates)
result = await mcp.call_tool("weather.get_forecast", latitude=37.7749, longitude=-122.4194)
print(result)

Note: The exact syntax for calling MCP tools may vary depending on your Cline setup. Refer to Cline documentation for the most up-to-date usage instructions.

Error Handling and Logging

The server includes improved error handling for API requests and logging. If an error occurs during a request, the server will log the error and return an appropriate error message. Logs are printed to the console with the configured log level and format.

Testing

Unit Tests

To run the unit tests:

python -m unittest test_weather.py

These tests cover the basic functionality of the get_alerts and get_forecast tools.

Manual Testing

To manually test the server, you can use the MCP client to call the provided tools. Here are some example commands:

# Get alerts for California
result = await mcp.call_tool("get_alerts", state="CA")
print(result)

# Get forecast for San Francisco (approximate coordinates)
result = await mcp.call_tool("get_forecast", latitude=37.7749, longitude=-122.4194)
print(result)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • momi
  • Provides initial medical assessments and advice.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • Daren White
  • A supportive coach for mastering all Spanish tenses.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://zenepic.net
  • Embark on a thrilling diplomatic quest across a galaxy on the brink of war. Navigate complex politics and alien cultures to forge peace and avert catastrophe in this immersive interstellar adventure.

  • huahuayu
  • A unified API gateway for integrating multiple etherscan-like blockchain explorer APIs with Model Context Protocol (MCP) support for AI assistants.

  • deemkeen
  • control your mbot2 with a power combo: mqtt+mcp+llm

  • zhaoyunxing92
  • 本项目是一个钉钉MCP(Message Connector Protocol)服务,提供了与钉钉企业应用交互的API接口。项目基于Go语言开发,支持员工信息查询和消息发送等功能。

  • justmywyw
  • Short and sweet example MCP server / client implementation for Tools, Resources and Prompts.

  • sligter
  • Lite-MCP-Client是一个基于命令行的轻量级MCP客户端工具

    Reviews

    2 (1)
    Avatar
    user_8846GBwM
    2025-04-15

    I've been using the Ksrk Mcp Server Client developed by karan-ksrk and it has significantly streamlined my server management tasks. Its intuitive interface and reliability are top-notch. The seamless integration and performance make it a must-have for anyone in need of a robust server client. Highly recommend!