Back to MCP directory
publicPublicdnsLocal runtime

stripe-mcp-client

一个轻量级的JavaScript客户端,用于与Stripe的模型上下文协议(MCP)服务器交互以创建支付链接。该客户端设计用于在自有MCP服务器内部集成Stripe支付服务。

article

README

🚀 Stripe MCP 客户端

Stripe MCP 客户端是一个轻量级的 JavaScript 客户端,旨在与 Stripe 的模型上下文协议(MCP)服务器交互,以轻松创建支付链接。该客户端专为在您自己的 MCP 服务器中使用而设计,能帮助您无缝集成 Stripe 的支付服务。

⚠️ 重要提示

此代码由 Claude 3.7 Sonnet 生成。视频

✨ 主要特性

  • 提供简单的 API,可轻松创建 Stripe 支付链接。
  • 作为 MCP 客户端的轻量级包装器,简洁高效。
  • 支持自定义选项和连接账户,满足多样化需求。
  • 自动管理 MCP 连接,使用更省心。

📦 安装指南

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)

使用指定的选项创建新的支付链接。

参数

返回值

  • 一个 Promise,解析为已创建的支付链接对象

client.close()

关闭到 Stripe MCP 服务器的连接。

🔧 测试

npm test

📄 许可证

MIT

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client