Weather MCP (Python: High-Level and Low-Level servers)
Minimal MCP server exposing a weather.today(city)
tool, a weather://today/{city}
resource and a weather.ensureCity
prompt. Includes both a FastMCP-based server (High-Level) and a Low-Level server to demonstrate Nevermined Payments integration.
About this demo
This repository is a reference/demo project used to test and validate the Model Context Protocol (MCP) integration inside Nevermined's Python SDK payments-py
. It showcases how to protect MCP tools, resources and prompts with the paywall, both in a High‑Level (FastMCP) server and a Low‑Level JSON‑RPC server. It is intended for examples, local experimentation and integration tests, not as production‑ready code.
Requirements
- Python >= 3.10
- Poetry (recommended) or pip
Install
Run the server (High-Level: FastMCP over HTTP)
Environment (server):
Run the server (Low-Level)
- High-Level endpoint:
POST /mcp
(JSON‑RPC; stateful HTTP via headers) - Low-Level endpoint:
POST /mcp-low
(raw JSON‑RPC; path is arbitrary, client default uses/mcp-low
) - Health:
GET /health
Client demo (High-Level)
Client environment:
Client demo (Low-Level)
Tests
Nevermined auth
The client obtains an access token with its NVM_API_KEY
and sends it as Authorization: Bearer ...
. The server requires Authorization
and performs validation via the paywall. If unauthorized, the server responds with a custom JSON‑RPC error -32003
.
Server env (recap):
Client env (recap):
MCP Inspector (over HTTP)
If you have Node.js available, you can use the MCP Inspector to connect to the High-Level server:
Note: Inspector requests typically do not include Authorization
headers; use the Python clients above for auth tests.
Endpoints
- High-Level (FastMCP):
POST /mcp
— JSON‑RPC requests (initialize handled here; server-side session via headers)GET /mcp
— SSE stream for server notifications (if supported by the client/tooling)GET /health
— simple health check
- Low-Level:
POST /mcp-low
— Minimal JSON‑RPC with Authorization header passthroughGET /health
— simple health check
Context and Authorization: FastMCP vs Low‑Level
- FastMCP (High‑Level): the paywall obtains the context automatically because it is configured with FastMCP's
getContext
. You do not need to passextra
to the handler.
- Low‑Level: you must pass
extra
explicitly to the handler. Typically you capture the request and theAuthorization
header in middleware or directly in the ASGI app and buildextra
withbuild_extra_from_http_headers
.
In this app, the Low‑Level variant already implements this pattern inside the ASGI (server_lowlevel.py
): it builds extra
from the headers and passes it as the second parameter to the handler (handler(args, extra)
).
Additional note (resources in FastMCP): when invoking a protected resource from FastMCP, you can pass None
as extra
and the paywall will resolve the context via the configured getContext
.
Acceptance checklist
- List Tools shows
weather.today
- Calling
weather.today
with{ "city": "Madrid" }
returns a text summary and aresource_link
toweather://today/Madrid
- Reading that resource returns JSON with the TodayWeather fields
Notes
- Inspector requests do not include
Authorization
; prefer the demo clients when testing paywall.
Tutorial: Protecting an MCP server with Nevermined (Paywall + Credits Burn)
This guide shows how to protect your MCP tools with Nevermined so that only subscribed users can access them, and how to burn credits after each call. The Python SDK mirrors the TypeScript flow but with Python naming.
1) Initialize Nevermined in your MCP server
2) Wrap your handlers with the paywall (works in both servers)
What the paywall does:
- Extracts
Authorization
from the MCP HTTP headers automatically. - Validates access with Nevermined.
- If unauthorized, responds with a JSON‑RPC error
-32003
(and suggests plans when possible). - Runs your handler.
- Burns credits after the call based on the
credits
option.
3) Client side
Use the Nevermined client to obtain an access token and pass it as Authorization
to your MCP transport.
4) Error semantics
- Missing token → JSON‑RPC
-32003
(“Authorization required”). - Invalid/not subscribed → JSON‑RPC
-32003
(“Payment required”, optionally with plan suggestions). - Network/other errors → JSON‑RPC
-32002
.
5) Advanced
- Customize
credits
to a function that receives a context{ args, result, request }
and returns anint
. - Use
payments.mcp.with_paywall
to protect tools, resources, and prompts.
Example: dynamic credits for tool calls (e.g., random 1..10 credits per call):
Example: burn 1 credit for resource reads (manual control, without the paywall wrapper):
In most cases, prefer the with_paywall
wrapper which authenticates and redeems for you and supports streaming (async iterables).
Weather MCP Python
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Provides weather information for cities through a protected MCP interface with Nevermined payment integration. Demonstrates both high-level and low-level MCP server implementations with paywall protection for tools, resources, and prompts.
- About this demo
- Requirements
- Install
- Run the server (High-Level: FastMCP over HTTP)
- Run the server (Low-Level)
- Client demo (High-Level)
- Client demo (Low-Level)
- Tests
- Nevermined auth
- MCP Inspector (over HTTP)
- Endpoints
- Context and Authorization: FastMCP vs Low‑Level
- Acceptance checklist
- Notes
- Tutorial: Protecting an MCP server with Nevermined (Paywall + Credits Burn)
- Weather MCP Python
Related MCP Servers
- -securityFlicense-qualityAn MCP server implementation that allows users to fetch and display weather information for specified cities, including temperature, humidity, wind speed, and weather descriptions.Last updated -1Python
- -securityFlicense-qualityAn MCP server that provides access to the Interzoid GetWeatherCity API, allowing users to retrieve weather information for specified cities through natural language interactions.Last updated -Python
- AsecurityFlicenseAqualityA simple MCP server that provides a tool to fetch current weather information for cities using the Open-Meteo API, communicating through stdin/stdout.Last updated -12TypeScript
- AsecurityFlicenseAqualityAn MCP server that provides weather information and alerts for US locations using the National Weather Service API, enabling retrieval of weather forecasts and active weather alerts.Last updated -2Python