agentauthco/working-example
If you are the rightful owner of working-example and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a comprehensive guide to setting up and running a remote MCP server with AgentPay integration for weather data services.
Remote MCP Server with AgentPay Integration
This is a complete working example of a remote MCP server that provides weather data and integrates with AgentPay for usage-based billing. It demonstrates how to:
- Create a remote MCP server using Starlette
- Use middleware for API key management
- Integrate with AgentPay for API key validation and usage-based billing
- Implement MCP tools with proper error handling
This working example pairs with the Working Example Walkthrough from the AgentPay documentation.
Prerequisites
- Python 3.10 or higher
- Basic understanding of MCP (see the official MCP documentation)
- An AgentPay account and Service Token (see Registering Your MCP Server on AgentPay)
[!NOTE] AgentPay is currently in Early Access. To get early access to AgentPay, please sign up for the Waitlist.
Setup
- Clone this repository
- Create a virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Copy
.env.example
to.env
and add your AgentPay Service Token:cp .env.example .env # Edit .env and add your Service Token
[!NOTE] The
agentpay-sdk
package currently on PyPI is a placeholder during Early Access. To get the actual SDK now, join the Waitlist.
Running the Server
Start the server:
python weather_server.py
The server will be available at http://localhost:8000
.
Usage
The server provides two MCP tools:
-
get_alerts(state: str)
: Get weather alerts for a US state- Cost: 2 cents per call
- Example:
get_alerts("CA")
-
get_forecast(latitude: float, longitude: float)
: Get weather forecast for a location- Cost: 3 cents per call
- Example:
get_forecast(37.7749, -122.4194)
For more details on implementing usage-based billing, see our Charging for Usage guide or SDK Reference.
Testing
To test your server integration:
-
Platform Setup
- Ensure that you have gone through the proper setup on AgentPay
- For more information, you can refer to the following guides: Developer Quickstart and Server Registration
- Retrieve an API key for your MCP Server to test with at AgentPay
-
Configure Your MCP Client Create or modify your
mcp.json
configuration in your MCP Client (e.g. Claude, Cursor):{ "mcpServers": { "weather-server": { "command": "npx", "args": [ "-y", "mcp-remote", "http://localhost:8000/sse", "--header", "X-AGENTPAY-API-KEY:YOUR_TEST_API_KEY", "--allow-http" ], "env": {} } } }
-
Test the Integration
- Verify your client can connect to the server
- Make test requests to both tools
- Check usage tracking in the AgentPay Hub
- Test error handling with invalid API keys
For detailed testing instructions, see our Testing Guide.