Stripe MCP Integration by wrsmith108/stripe-mcp-skill
npx skills add https://github.com/wrsmith108/stripe-mcp-skill --skill 'Stripe MCP Integration'通过模型上下文协议(MCP)将 Claude 连接到 Stripe 的支付基础设施。此技能支持直接与 Stripe API 交互,用于客户管理、订阅、发票和文档搜索。
选择您的安装方法:
添加到 ~/.claude/settings.json:
{
"mcpServers": {
"stripe": {
"type": "http",
"url": "https://mcp.stripe.com/v1/sse"
}
}
}
出现提示时,使用 stripe_sk_... 密钥进行身份验证。
# 安装 MCP 服务器
npm install -g @stripe/mcp
# 添加到设置
claude mcp add stripe -- npx -y @stripe/mcp
在项目根目录创建 .mcp.json:
{
"mcpServers": {
"stripe": {
"command": "npx",
"args": ["-y", "@stripe/mcp"],
"env": {
"STRIPE_SECRET_KEY": "${STRIPE_SECRET_KEY}"
}
}
}
}
| 工具 | 描述 | 使用示例 |
|---|---|---|
stripe_create_customer | 创建新客户 | "创建邮箱为 user@example.com 的客户" |
stripe_retrieve_customer | 通过 ID 获取客户 | "获取客户 cus_xxx" |
stripe_list_customers | 列出所有客户 | "显示我的 Stripe 客户" |
stripe_create_product |
在代码中使用这些前缀来验证 ID:
| 对象 | 前缀 | 示例 |
|---|---|---|
| 客户 | cus_ | cus_NffrFeUfNV2Hib |
| 订阅 | sub_ | sub_1MowQVLkdIwHu7ixeRlqHVzs |
| 价格 | price_ | price_1MowQULkdIwHu7ixspc |
| 产品 | prod_ |
| 卡号 | 场景 |
|---|---|
4242424242424242 | 支付成功 |
4000000000000002 | 卡被拒绝 |
4000002500003155 | 需要 3D 安全验证 |
4000000000009995 | 资金不足 |
4000000000000341 | 附加失败 |
# 安装 Stripe CLI
brew install stripe/stripe-cli/stripe
# 登录到您的账户
stripe login
# 本地监听 webhooks
stripe listen --forward-to localhost:3000/api/webhooks/stripe
# 触发测试事件
stripe trigger checkout.session.completed
stripe trigger customer.subscription.created
stripe trigger invoice.payment_succeeded
| 变量 | 必需 | 描述 |
|---|---|---|
STRIPE_SECRET_KEY | 是 | API 密钥 (sk_test_... 或 sk_live_...) |
STRIPE_WEBHOOK_SECRET | 用于 webhooks | Webhook 签名密钥 (whsec_...) |
STRIPE_API_VERSION | 否 | 锁定 API 版本 (例如,2024-12-18.acacia) |
切勿将密钥提交到版本控制系统。使用环境变量或密钥管理器:
# 开发:使用 .env 文件(已 gitignore)
echo "STRIPE_SECRET_KEY=sk_test_..." >> .env
# 生产:使用您平台的密钥管理器
# - 云平台:环境变量或密钥管理器
# - AWS:Secrets Manager 或 Parameter Store
# - 自托管:HashiCorp Vault 或类似工具
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function handleWebhook(request: Request) {
const body = await request.text();
const signature = request.headers.get('stripe-signature')!;
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(
body,
signature,
process.env.STRIPE_WEBHOOK_SECRET!
);
} catch (err) {
console.error('Webhook signature verification failed:', err);
return new Response('Webhook Error', { status: 400 });
}
// 处理事件
switch (event.type) {
case 'checkout.session.completed':
const session = event.data.object as Stripe.Checkout.Session;
await fulfillOrder(session);
break;
case 'customer.subscription.updated':
const subscription = event.data.object as Stripe.Subscription;
await updateSubscriptionStatus(subscription);
break;
// ... 处理其他事件
}
return new Response('OK', { status: 200 });
}
import Stripe from 'npm:stripe@latest';
const stripe = new Stripe(Deno.env.get('STRIPE_SECRET_KEY')!, {
apiVersion: '2024-12-18.acacia',
});
Deno.serve(async (req) => {
const body = await req.text();
const signature = req.headers.get('stripe-signature')!;
// 重要:Deno 需要异步验证
const event = await stripe.webhooks.constructEventAsync(
body,
signature,
Deno.env.get('STRIPE_WEBHOOK_SECRET')!
);
// 处理事件...
return new Response(JSON.stringify({ received: true }));
});
关键 : Deno 和边缘运行时需要
constructEventAsync(),而不是constructEvent()。
| 事件 | 触发时机 | 典型操作 |
|---|---|---|
checkout.session.completed | 结账成功时 | 授予访问权限,发送确认信息 |
customer.subscription.created | 新订阅时 | 配置账户,发送欢迎邮件 |
customer.subscription.updated | 计划变更、续订时 | 更新访问级别 |
customer.subscription.deleted | 取消订阅时 | 撤销访问权限,发送下线通知 |
invoice.payment_succeeded | 成功扣款时 |
StripeInvalidRequestError: No such customer: 'cus_xxx'
原因 : 客户 ID 不存在或在生产模式中使用了测试 ID。 解决方法 : 验证该 ID 是否存在于您的 Stripe 仪表板中。检查您是否使用了匹配的测试/生产密钥。
Webhook signature verification failed
原因 : 错误的 webhook 密钥或修改后的负载。 解决方法 :
stripe listen 打印的密钥StripeRateLimitError: Too many requests
原因 : 超过每秒 100 次读取或 100 次写入请求。 解决方法 : 实现指数退避,尽可能批量操作,缓存读取结果。
每周安装次数
–
代码仓库
首次出现
–
安全审计
Connect Claude to Stripe's payment infrastructure via the Model Context Protocol (MCP). This skill enables direct interaction with Stripe APIs for customer management, subscriptions, invoices, and documentation search.
Choose your installation method:
Add to ~/.claude/settings.json:
{
"mcpServers": {
"stripe": {
"type": "http",
"url": "https://mcp.stripe.com/v1/sse"
}
}
}
Authenticate when prompted with stripe_sk_... key.
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 创建产品 |
"创建价格为 29 美元/月的产品 '专业版套餐'" |
stripe_list_products | 列出产品 | "显示所有产品" |
stripe_create_subscription | 开始订阅 | "为客户订阅 price_xxx" |
stripe_cancel_subscription | 取消订阅 | "取消订阅 sub_xxx" |
stripe_create_invoice | 创建草稿发票 | "为客户 cus_xxx 创建发票" |
stripe_finalize_invoice | 最终确定以便支付 | "最终确定发票 in_xxx" |
stripe_search_documentation | 搜索 Stripe 文档 | "在 Stripe 文档中搜索 webhooks" |
prod_NWjs8kKbJWmuuc |
| 发票 | in_ | in_1MtHbELkdIwHu7ixl4OzzPMI |
| 支付意向 | pi_ | pi_3MtwBwLkdIwHu7ix28a3tqPa |
| 事件 | evt_ | evt_1NG8Du2eZvKYlo2CUI79vXWy |
| Webhook 端点 | we_ | we_1Mr5jALkdIwHu7ixNsD8AdJZ |
| 结账会话 | cs_ | cs_test_a1b2c3d4 |
| 更新账单记录 |
invoice.payment_failed | 扣款失败时 | 通知客户,重试逻辑 |
# Install the MCP server
npm install -g @stripe/mcp
# Add to settings
claude mcp add stripe -- npx -y @stripe/mcp
Create .mcp.json in your project root:
{
"mcpServers": {
"stripe": {
"command": "npx",
"args": ["-y", "@stripe/mcp"],
"env": {
"STRIPE_SECRET_KEY": "${STRIPE_SECRET_KEY}"
}
}
}
}
| Tool | Description | Example Usage |
|---|---|---|
stripe_create_customer | Create a new customer | "Create customer with email user@example.com" |
stripe_retrieve_customer | Get customer by ID | "Get customer cus_xxx" |
stripe_list_customers | List all customers | "Show my Stripe customers" |
stripe_create_product | Create a product | "Create product 'Pro Plan' for $29/month" |
stripe_list_products | List products | "Show all products" |
stripe_create_subscription | Start a subscription | "Subscribe customer to price_xxx" |
stripe_cancel_subscription | Cancel subscription | "Cancel subscription sub_xxx" |
stripe_create_invoice | Create draft invoice | "Create invoice for customer cus_xxx" |
stripe_finalize_invoice | Finalize for payment | "Finalize invoice in_xxx" |
stripe_search_documentation | Search Stripe docs | "Search Stripe docs for webhooks" |
Use these prefixes to validate IDs in your code:
| Object | Prefix | Example |
|---|---|---|
| Customer | cus_ | cus_NffrFeUfNV2Hib |
| Subscription | sub_ | sub_1MowQVLkdIwHu7ixeRlqHVzs |
| Price | price_ | price_1MowQULkdIwHu7ixspc |
| Product | prod_ | prod_NWjs8kKbJWmuuc |
| Invoice | in_ | in_1MtHbELkdIwHu7ixl4OzzPMI |
| Payment Intent | pi_ | pi_3MtwBwLkdIwHu7ix28a3tqPa |
| Event | evt_ | evt_1NG8Du2eZvKYlo2CUI79vXWy |
| Webhook Endpoint | we_ | we_1Mr5jALkdIwHu7ixNsD8AdJZ |
| Checkout Session | cs_ | cs_test_a1b2c3d4 |
| Card Number | Scenario |
|---|---|
4242424242424242 | Successful payment |
4000000000000002 | Card declined |
4000002500003155 | Requires 3D Secure |
4000000000009995 | Insufficient funds |
4000000000000341 | Attach fails |
# Install Stripe CLI
brew install stripe/stripe-cli/stripe
# Login to your account
stripe login
# Listen for webhooks locally
stripe listen --forward-to localhost:3000/api/webhooks/stripe
# Trigger test events
stripe trigger checkout.session.completed
stripe trigger customer.subscription.created
stripe trigger invoice.payment_succeeded
| Variable | Required | Description |
|---|---|---|
STRIPE_SECRET_KEY | Yes | API key (sk_test_... or sk_live_...) |
STRIPE_WEBHOOK_SECRET | For webhooks | Webhook signing secret (whsec_...) |
STRIPE_API_VERSION | No | Lock API version (e.g., 2024-12-18.acacia) |
Never commit keys to version control. Use environment variables or a secrets manager:
# Development: Use .env file (gitignored)
echo "STRIPE_SECRET_KEY=sk_test_..." >> .env
# Production: Use your platform's secrets manager
# - Cloud platforms: Environment variables or secret managers
# - AWS: Secrets Manager or Parameter Store
# - Self-hosted: HashiCorp Vault or similar
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
export async function handleWebhook(request: Request) {
const body = await request.text();
const signature = request.headers.get('stripe-signature')!;
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(
body,
signature,
process.env.STRIPE_WEBHOOK_SECRET!
);
} catch (err) {
console.error('Webhook signature verification failed:', err);
return new Response('Webhook Error', { status: 400 });
}
// Handle the event
switch (event.type) {
case 'checkout.session.completed':
const session = event.data.object as Stripe.Checkout.Session;
await fulfillOrder(session);
break;
case 'customer.subscription.updated':
const subscription = event.data.object as Stripe.Subscription;
await updateSubscriptionStatus(subscription);
break;
// ... handle other events
}
return new Response('OK', { status: 200 });
}
import Stripe from 'npm:stripe@latest';
const stripe = new Stripe(Deno.env.get('STRIPE_SECRET_KEY')!, {
apiVersion: '2024-12-18.acacia',
});
Deno.serve(async (req) => {
const body = await req.text();
const signature = req.headers.get('stripe-signature')!;
// IMPORTANT: Deno requires async verification
const event = await stripe.webhooks.constructEventAsync(
body,
signature,
Deno.env.get('STRIPE_WEBHOOK_SECRET')!
);
// Handle event...
return new Response(JSON.stringify({ received: true }));
});
Critical : Deno and edge runtimes require
constructEventAsync(), notconstructEvent().
| Event | When It Fires | Typical Action |
|---|---|---|
checkout.session.completed | Successful checkout | Grant access, send confirmation |
customer.subscription.created | New subscription | Provision account, welcome email |
customer.subscription.updated | Plan change, renewal | Update access level |
customer.subscription.deleted | Cancellation | Revoke access, send offboarding |
invoice.payment_succeeded | Successful charge | Update billing records |
invoice.payment_failed | Failed charge | Notify customer, retry logic |
StripeInvalidRequestError: No such customer: 'cus_xxx'
Cause : Customer ID doesn't exist or using test ID in live mode. Fix : Verify the ID exists in your Stripe Dashboard. Check you're using matching test/live keys.
Webhook signature verification failed
Cause : Wrong webhook secret or modified payload. Fix :
stripe listenStripeRateLimitError: Too many requests
Cause : Exceeding 100 read or 100 write requests per second. Fix : Implement exponential backoff, batch operations where possible, cache read results.
Weekly Installs
–
Repository
First Seen
–
Security Audits
通过 LiteLLM 代理让 Claude Code 对接 GitHub Copilot 运行 | 高级变通方案指南
31,600 周安装