Stripe MCP 客户端是一个轻量级的 JavaScript 客户端,旨在与 Stripe 的模型上下文协议(MCP)服务器交互,以轻松创建支付链接。该客户端专为在您自己的 MCP 服务器中使用而设计,能帮助您无缝集成 Stripe 的支付服务。
⚠️ 重要提示
此代码由 Claude 3.7 Sonnet 生成。视频
npm install stripe-mcp-client
请确保已安装 Node.js 16+。
此包依赖于以下两个库:
@modelcontextprotocol/sdk
:用于 MCP 客户端实现。@stripe/mcp
:用于 Stripe MCP 服务器(.peer 依赖)。import StripeMcpClient from 'stripe-mcp-client';
async function createPaymentLink() {
// 初始化客户端
const client = new StripeMcpClient({
apiKey: 'your_stripe_api_key', // 或设置 STRIPE_API_KEY 环境变量
debug: true, // 可选:启用调试日志
});
try {
// 连接到 Stripe MCP 服务器
await client.connect();
// 创建支付链接
const paymentLink = await client.createPaymentLink({
line_items: [
{
price: 'price_123', // 您的 Stripe 价格 ID
quantity: 1,
},
],
after_completion: {
type: 'redirect',
redirect: {
url: 'https://example.com/thank-you',
},
},
});
console.log(`支付链接已创建:${paymentLink.url}`);
return paymentLink;
} finally {
// 总是关闭连接
await client.close();
}
}
createPaymentLink().catch(console.error);
您可以使用环境变量来配置 API 密钥和 Stripe 账户:
STRIPED_API_KEY=your_stripe_api_key \
STRIPE_ACCOUNT=your_stripe_connect_account_id \
npm start
new StripeMcpClient(options)
创建一个新的客户端实例。
client.connect()
连接到 Stripe MCP 服务器。如果需要,其他方法会自动调用此方法。
client.createPaymentLink(options)
使用指定的选项创建新的支付链接。
参数:
options
:包含 Stripe 支付链接创建参数 的对象返回值:
client.close()
关闭到 Stripe MCP 服务器的连接。
npm test
MIT