UNPKG

@stripe/mcp

Version:

A command line tool for setting up Stripe MCP server

63 lines (62 loc) 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ACCEPTED_ARGS = void 0; exports.parseArgs = parseArgs; exports.validateApiKey = validateApiKey; exports.validateStripeAccount = validateStripeAccount; exports.buildHeaders = buildHeaders; const colors_1 = require("colors"); exports.ACCEPTED_ARGS = ['api-key', 'stripe-account']; function parseArgs(args) { const options = {}; args.forEach((arg) => { if (arg.startsWith('--')) { const [key, value] = arg.slice(2).split('='); if (key === 'tools') { console.warn((0, colors_1.yellow)('The --tools flag has been removed. ' + 'Tool permissions are now controlled by your Restricted API Key (RAK). ' + 'Create a RAK with the desired permissions at https://dashboard.stripe.com/apikeys')); } else if (key === 'api-key') { options.apiKey = value; } else if (key === 'stripe-account') { options.stripeAccount = value; } else { throw new Error(`Invalid argument: ${key}. Accepted arguments are: ${exports.ACCEPTED_ARGS.join(', ')}`); } } }); // Check if API key is either provided in args or set in environment variables const apiKey = options.apiKey || process.env.STRIPE_SECRET_KEY; if (!apiKey) { throw new Error('Stripe API key not provided. Please either pass it as an argument --api-key=$KEY or set the STRIPE_SECRET_KEY environment variable.'); } options.apiKey = apiKey; return options; } function validateApiKey(apiKey) { if (!apiKey.startsWith('sk_') && !apiKey.startsWith('rk_')) { throw new Error('Invalid API key format. Expected sk_* (secret key) or rk_* (restricted key).'); } if (apiKey.startsWith('sk_')) { console.warn((0, colors_1.yellow)('[WARNING] We strongly recommend using rk_* (restricted keys) instead of sk_* keys for better security and granular permissions.\n' + 'See: https://docs.stripe.com/keys#create-restricted-api-keys\n')); } } function validateStripeAccount(account) { if (!account.startsWith('acct_')) { throw new Error('Stripe account must start with "acct_".'); } } function buildHeaders(options, userAgent) { const headers = { Authorization: `Bearer ${options.apiKey}`, 'User-Agent': userAgent, }; if (options.stripeAccount) { headers['Stripe-Account'] = options.stripeAccount; } return headers; }