- Home
- MCP servers
- Weather
Weather
- python
0
GitHub Stars
python
Language
7 months ago
First Indexed
3 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
You will learn to build, configure, and run MCP servers that let AI assistants discover and call tools safely. This guide covers practical steps to set up a Python-based MCP server, run it locally, test it with tooling, and connect clients for real workflows.
How to use
You connect an MCP server to an AI assistant or client and expose one or more tools that perform tasks for the user. Start the local MCP server, ensure its tools are registered, and then let the client discover and invoke those tools. You can test individual tools, run a full MCP server for production-style usage, or use inspector tooling to debug and validate requests and responses. The workflow emphasizes rapid iteration, type safety with predefined inputs, and clear tool semantics so your AI assistant can compose reliable actions.
How to install
Prerequisites you need to prepare before starting:
# Prerequisites
python3 --version
uv --version 2>/dev/null || echo 'UV not installed'
# If you plan to use UV (recommended) or pip + venv
Then follow these concrete steps to set up a local MCP project using UV (recommended) or pip + virtual environment.
# UV installation and project setup
powershell -c "irm https://astral.sh/uv/install.ps1 | iex" # Windows
# macOS/Linux: follow UV install instructions for your shell
uv init learn-mcp-2025
cd learn-mcp-2025
uv add "mcp[cli]"
# This creates/updates: pyproject.toml, uv.lock
uv sync
# Or alternative: using pip + venv
python -m venv .venv
.venv/Scripts/Activate.ps1 # PowerShell (Windows)
# Or: source .venv/bin/activate # Bash/zsh (macOS/Linux)
pip install -r requirements.txt
Generated configuration files you will use to run servers and tests include UV-based setup and a pip-based setup. You will create or edit a configuration file to register MCP servers.
Configuration examples
{
"servers": {
"weather-service": {
"command": "python",
"args": ["weather.py"],
"env": {}
}
}
}
For a multi-server configuration that includes a local server and a separate Windows-based MCP server, you can register both entries as shown below.
{
"servers": {
"weather-service": {
"command": "python",
"args": ["weather.py"],
"env": {}
},
"winget-mcp": {
"type": "stdio",
"command": "C:\\Users\\YourUser\\AppData\\Local\\Microsoft\\WindowsApps\\...\\WindowsPackageManagerMCPServer.exe"
}
}
}
Running the MCP Server
Choose your run mode based on what you want to test or deploy.
# Quick testing: direct function call using UV
uv run python -c "from weather import get_weather; print(get_weather('London'))"
# Production style: run the full MCP server
uv run python weather.py
If you prefer a virtual environment, activate it first and then run the server.
# Activate venv and run
.venv\Scripts\Activate.ps1
python weather.py
Testing and debugging with MCP Studio
Use MCP Studio for an interactive web UI to test streams and multi-server setups. Start a streamable HTTP server, then connect MCP Studio to the remote URL.
# Start a streamable MCP server (example on port 8000)
uv run python sample_mcp_streamable_server.py
# Open MCP Studio at the remote URL
mcp-studio --remote http://127.0.0.1:8000
Python client usage
You can connect to MCP servers from Python client code to call tools, list available tools, and automate workflows.
# client.py (example)
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(
command="uv",
args=["run", "weather.py"]
)
async def main():
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.call_tool("get_weather", arguments={"location": "Tokyo"})
print(result)
tools = await session.list_tools()
print(f"Available tools: {tools}")
if __name__ == "__main__":
import asyncio
asyncio.run(main())
MCP Studio and streamable transport details
When you work with streamable HTTP transports, you can test and debug interactions using a visual interface. This is especially helpful for complex multi-tool integrations and production-like testing.
Project structure tips
Organize your MCP project with clear separation between servers, clients, and configuration. Maintain a dedicated virtual environment, pinned dependencies, and explicit tool definitions to ensure stable behavior across development and production.
Troubleshooting and notes
If a server does not respond, verify the transport configuration (stdio vs http), ensure the correct command and script paths are used, and confirm environment variables are set when required. Use MCP Inspector for step-by-step debugging and enable verbose logs to capture tool invocation details.
Security considerations
Limit exposure of internal tools to trusted clients only. Validate inputs with strict typing and use defined tool interfaces to reduce risk. Prefer streamable transports for fine-grained access control and auditing.
Available tools
get_weather
Fetches the current weather for a specified location, returning a text summary.
get_forecast
Provides a weather forecast for a location over a given number of days.
get_temperature
Returns the current temperature for a location in a specified unit.