AgentPayClient
in your MCP Server application. This client object is your primary interface for interacting with AgentPay services like recording consumption and validating API keys.
Basic Initialization
To initialize the client, you need your Service Token (obtained when you registered your server).Key Points for Initialization:
- Service Token Security: Always load your Service Token from a secure source, like an environment variable or a secrets management system. Do not hardcode it in your source code.
- Singleton Instance (Recommended): Typically, you should initialize the
AgentPayClient
once when your application starts and reuse the same instance throughout the lifetime of your server process. This is more efficient than creating a new client for every request.- How you achieve this depends on your web framework (e.g. storing it on the application object in Starlette).
- Error Handling: Be prepared to handle cases where the
SERVICE_TOKEN
environment variable might not be set or if the client initialization itself fails for some reason (though typically, basic initialization is lightweight).
Client Configuration Options
At the moment, there are no other client configuration options, since:- Sandboxing is handled via Server Registration & Management
- There are no custom timeout or URL settings, currently
Next Steps
Once theAgentPayClient
is successfully initialized, you can proceed to:
- Extracting User API Key from incoming requests.
- Validating User API Keys using the
validate_api_key()
method. - Charging for tool usage using the
consume()
method.