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/commetCommet Setup
Follow these steps to configure your billing product before integrating the plugin:
- Create an account at commet.co/templates/xmcp
- Copy your API Key (
ck_xxx) from Settings > API Keys - Create a Product from the dashboard. This represents your xmcp server
- Define your Plans (e.g., Free, Pro, Enterprise). Each plan includes a set of features
- 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_generatewith 1000 included units)
- Boolean: on/off access (e.g.,
- 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:
Configuration Options
apiKey: Your Commet API key (starts withck_)environment: Defaults to the SDK's default environmentcustomerHeader: 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:
Example: Usage tracking
Track metered consumption with the SDK:
Example: AI token tracking
Track per-model token consumption:
Example: Billing portal
Get the customer's billing portal URL for upgrade and management flows:
Example
See the full working example with free, gated, metered, and AI token tools in the commet-http example.