@xmcp-dev/polar
Version:
Polar integration for xmcp
84 lines (61 loc) • 1.56 kB
Markdown
for license validation and usage tracking in xmcp tools.
```bash
npm install @xmcp-dev/polar
```
```typescript
import { PolarProvider } from "@xmcp-dev/polar";
export const polar = PolarProvider.getInstance({
type: "sandbox", // defaults to "production"
token: process.env.POLAR_TOKEN,
organizationId: process.env.POLAR_ORGANIZATION_ID,
productId: process.env.POLAR_PRODUCT_ID,
});
```
**Interface:**
```typescript
interface Configuration {
type?: "production" | "sandbox";
token: string;
organizationId: string;
productId: string;
}
```
```typescript
import { headers } from "xmcp/headers";
export default async function myTool() {
const licenseKey = headers()["license-key"];
const response = await polar.validateLicenseKey(licenseKey);
if (!response.valid) {
return response.message; // Auto-generated checkout URLs
}
// Tool implementation
}
```
**Response Schema:**
```typescript
{
valid: boolean;
code: string;
message: string;
}
```
You can also pass an event object to the `validateLicenseKey` method to track usage.
```typescript
const event = {
name: "tool_call_event",
metadata: { tool_name: "tool_name", calls: 1 },
};
const response = await polar.validateLicenseKey(licenseKey, event);
```
The metadata can be any type of string or number.
```bash
POLAR_TOKEN=your_polar_token
POLAR_ORGANIZATION_ID=your_org_id
POLAR_PRODUCT_ID=your_product_id
```
Polar.sh integration