working-example

agentauthco/working-example

3.2

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.

Tools
2
Resources
0
Prompts
0

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:

  1. Create a remote MCP server using Starlette
  2. Use middleware for API key management
  3. Integrate with AgentPay for API key validation and usage-based billing
  4. Implement MCP tools with proper error handling

This working example pairs with the Working Example Walkthrough from the AgentPay documentation.

Prerequisites

[!NOTE] AgentPay is currently in Early Access. To get early access to AgentPay, please sign up for the Waitlist.

Setup

  1. Clone this repository
  2. Create a virtual environment:
    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. 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:

  1. get_alerts(state: str): Get weather alerts for a US state

    • Cost: 2 cents per call
    • Example: get_alerts("CA")
  2. 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:

  1. Platform Setup

  2. 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": {}
        }
      }
    }
    
  3. 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.

Additional Resources