Polar
Add paywalls and track tool usage with license keys using Polar
Overview
The Polar plugin enables you to add paywalls with license key validation and track tool usage for your xmcp server using Polar.
Installation
Install the Polar plugin:
Polar Setup
Before integrating the plugin, set up your product on Polar:
- Create a new product with your desired payment configuration
- Add the License Key benefit to the product
- (Optional) Add a Meter Credit benefit to track and limit tool usage
Configuration
Initialize the Polar provider to access validation methods:
Configuration Options
type- Environment type (defaults to"production"if not set)token- Polar authentication tokenorganizationId- Your Polar organization IDproductId- Your Polar product ID
License keys must be provided in the license-key header. This header name is
not customizable.
License Key Validation
Validate license keys in your tools using the validateLicenseKey method:
Response Object
The validation response contains:
Handling Invalid Keys
Return appropriate messages when validation fails:
This automatically prompts users with the checkout URL when the license key is invalid.
Usage Tracking
Track tool usage by adding a meter credit benefit to your product and passing event objects during validation.
Meter Credit Setup
Configure a meter credit benefit in your Polar product with the appropriate limits and tracking settings.
Tracking Events
Pass an event object to validateLicenseKey to record usage:
The metadata field accepts any string or number values for flexible usage tracking.
Example
Here's a complete example integrating license validation and usage tracking: