Server

Server

By aquental GitHub

Weather MCP server in python

Overview

what is Python MCP Server?

Python MCP Server is a weather server built using the Model Context Protocol (MCP) in Python, designed to provide weather data through a structured API.

how to use Python MCP Server?

To use the Python MCP Server, follow these steps: 1. Create a new directory for your project. 2. Initialize the project with uv init. 3. Create a virtual environment and activate it using uv venv and source .venv/bin/activate. 4. Install the necessary dependencies with uv add "mcp[cli]" httpx. 5. Create your server file (e.g., weather.py).

key features of Python MCP Server?

  • Built on the Model Context Protocol for structured data handling.
  • Easy setup with virtual environments.
  • Supports HTTP requests for weather data retrieval.

use cases of Python MCP Server?

  1. Providing real-time weather updates for applications.
  2. Integrating weather data into IoT devices.
  3. Serving as a backend for weather-related web applications.

FAQ from Python MCP Server?

  • What programming language is used for Python MCP Server?

Python is the primary language used for developing the MCP server.

  • Is there documentation available?

Yes, comprehensive documentation can be found at MCP Documentation.

  • What license is Python MCP Server under?

The project is licensed under the MIT license.

Content

MCP Server

Weather MCP server in python

docs

python-sdk

# Create a new directory for our project
uv init

# Create virtual environment and activate it
uv venv
source .venv/bin/activate

# Install dependencies
uv add "mcp[cli]" httpx

# Create our server file
touch weather.py

Testing

This project includes a comprehensive test suite for the weather service API. The tests use pytest and pytest-asyncio to test the asynchronous functions that interact with the National Weather Service API.

Test Requirements

  • Python 3.12+
  • pytest
  • pytest-asyncio
  • pytest-cov
  • httpx

Installing Development Dependencies

You can install all development dependencies using:

# Using uv
uv pip install -e ".[dev]"

# Or using pip
pip install -e ".[dev]"

Running the Tests

To run the tests:

# Run all tests
pytest

# Run with verbose output
pytest -v

# Run with code coverage
pytest --cov=weather

Test Coverage

The test suite covers:

  1. Unit Tests for Helper Functions

    • format_alert function for formatting alert data
    • Error handling in make_nws_request
  2. API Function Tests

    • get_alerts: Testing successful retrieval, empty results, and API failures
    • get_forecast: Testing successful forecast retrieval and error handling for both API endpoints
  3. Mock Responses

    • All HTTP requests are mocked using httpx.AsyncMock
    • Multiple test scenarios with different API responses

Continuous Integration

When adding new features to the weather service, please ensure all tests pass by running the test suite before submitting changes.

No tools information available.
No content found.