Skip to content

Polar

Add paywalls and track tool usage with license keys using Polar

For the complete documentation index, see llms.txt. Markdown variants of every page are available by appending .md to the URL.

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:

Shell

Polar Setup

Before integrating the plugin, set up your product on Polar:

  1. Create a new product with your desired payment configuration
  2. Add the License Key benefit to the product
  3. (Optional) Add a Meter Credit benefit to track and limit tool usage

Configuration

Initialize the Polar provider to access validation methods:

src/lib/polar.ts

Configuration Options

TypeScript
  • type - Environment type (defaults to "production" if not set)
  • token - Polar authentication token
  • organizationId - Your Polar organization ID
  • productId - Your Polar product ID
Info

These examples read the license key from the license-key header and pass it explicitly to the provider.

License Key Validation

Validate license keys in your tools using the validateLicenseKey method:

TypeScript

Response Object

The validation response contains:

TypeScript

Handling Invalid Keys

Return appropriate messages when validation fails:

TypeScript

The returned message can include a checkout URL. Return it before executing protected work; this does not automatically open checkout in the client.

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:

TypeScript

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:

src/tools/protected-tool.ts

One framework to rule them all