@meter-mcp/mcp
v0.2.0
Published
Drop-in metered tool wrappers for Model Context Protocol servers
Maintainers
Readme
@meter-mcp/mcp
Drop-in prepaid billing wrappers for Model Context Protocol tools.
Install
npm install @meter-mcp/sdk @meter-mcp/mcpRegister a paid tool
import { MeterPublicApiClient } from "@meter-mcp/sdk";
import { registerPaidTool } from "@meter-mcp/mcp";
const meter = new MeterPublicApiClient({
baseUrl: process.env.METER_API_URL!,
serviceId: process.env.METER_SERVICE_ID!,
serviceApiKey: process.env.METER_SERVICE_API_KEY!,
});
registerPaidTool({
server,
meter,
name: "knowledge_search",
definition: { description: "Search knowledge", inputSchema },
billing: {
customer: ({ extra }) => extra.auth.subject,
credits: 8,
provider: ({ input }) => `creator:${input.creatorId}`,
product: ({ input }) => input.productId,
aiUsage: (result) => result.aiUsage,
},
handler: searchKnowledge,
});The wrapper reserves credits before invoking the tool, commits after success,
and releases on failure. Payment-required and suspended-account responses are
returned as MCP tool errors with structured billing details in _meta.meter.
Unexpected errors continue to throw.
Use paidTool when your MCP framework has a different registration API, and
use meterErrorToMcpResult when you need to translate errors yourself.
Both ESM import and CommonJS require are supported on Node.js 20 or newer.
License
MIT
