Commet

Add subscription-aware billing, feature gating, and usage tracking to your xmcp server with Commet

Overview

The Commet plugin enables subscription-aware billing for your xmcp server using Commet. Your tools get full context: which plan the customer is on, what features they can access, how much usage remains, and automatic consumption tracking.

  • Feature-level gating: Tool A is free, Tool B is Pro, Tool C is Enterprise
  • Usage tracking: report units or AI tokens, your plan's consumption model handles the rest
  • Rich context: your tools know the customer's plan, remaining quota, and limits
  • Full billing: invoices, proration, checkout, customer portal
  • Taxes and compliance: Commet handles everything as Merchant of Record

Installation

Install the Commet plugin:

pnpm i @xmcp-dev/commet

Commet Setup

Follow these steps to configure your billing product before integrating the plugin:

  1. Create an account at commet.co/templates/xmcp
  2. Copy your API Key (ck_xxx) from Settings > API Keys
  3. Create a Product from the dashboard. This represents your xmcp server
  4. Define your Plans (e.g., Free, Pro, Enterprise). Each plan includes a set of features
  5. Add Features to each plan. Choose the type per feature:
    • Boolean: on/off access (e.g., export, custom-branding)
    • Metered: usage-based with included quotas and optional overage pricing (e.g., ai_generate with 1000 included units)
  6. Set pricing for each plan: monthly/yearly intervals, per-seat, or flat rate

Use the sandbox environment (ck_test_xxx) during development. Switch to your production key when you're ready to go live.

Configuration

Register the Commet provider in your middleware:

src/middleware.ts

Configuration Options

  • apiKey: Your Commet API key (starts with ck_)
  • environment: Defaults to the SDK's default environment
  • customerHeader: HTTP header name for the customer identifier (defaults to "customer-key")

Customer identity is provided via the customer-key header (or the established header name you configure in customerHeader). This is the same ID you use when creating customers in Commet.

Access the client

The getClient() function gives you access to the full @commet/node SDK, allowing you to leverage all Commet features in your MCP tools. The getCustomerId() function returns the customer ID extracted from the request header.

Example: Feature gating

Use the SDK to gate tools behind boolean features:

src/tools/export-tool.ts

Example: Usage tracking

Track metered consumption with the SDK:

src/tools/ai-generate.ts

Example: AI token tracking

Track per-model token consumption:

src/tools/ai-chat.ts

Example: Billing portal

Get the customer's billing portal URL for upgrade and management flows:

src/tools/manage-billing.ts

Example

See the full working example with free, gated, metered, and AI token tools in the commet-http example.

On this page

One framework to rule them all