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:

  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

  • type - Environment type (defaults to "production" if not set)
  • token - Polar authentication token
  • organizationId - Your Polar organization ID
  • productId - 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:

src/tools/protected-tool.ts

On this page

One framework to rule them all

    Polar | xmcp Documentation