跳转到内容

用于 ADK 的 Stripe MCP 工具

在 ADK 中得到支持。PythonTypeScript

The Stripe MCP Server 将您的 ADK 代理连接到…… Stripe 这个集成功能使您的代理能够通过自然语言来管理支付、客户信息、订阅服务以及发票,从而实现自动化商业流程和财务操作。

使用场景

  • 自动化支付操作:通过对话指令创建支付链接、处理退款,并列出支付相关的操作选项。

  • 简化开票流程无需离开开发环境,即可生成并完成发票、添加商品明细(即发票中的各项交易记录),并跟踪未支付的款项。

  • 访问 Business Insights(商业洞察工具):查询账户余额、列出产品及其价格,并在 Stripe 的各种资源中搜索相关信息,以便做出基于数据的决策。

先决条件

  • 创建一个…… Stripe 账户
  • 生成一个……(请根据具体需求填写“……”的内容)。 受限制的 API 密钥 来自 Stripe 控制面板(Stripe Dashboard)

与代理程序(agent)一起使用。

from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters

STRIPE_SECRET_KEY = "YOUR_STRIPE_SECRET_KEY"

root_agent = Agent(
    model="gemini-flash-latest",
    name="stripe_agent",
    instruction="Help users manage their Stripe account",
    tools=[
        McpToolset(
            connection_params=StdioConnectionParams(
                server_params=StdioServerParameters(
                    command="npx",
                    args=[
                        "-y",
                        "@stripe/mcp",
                        "--tools=all",
                        # (Optional) Specify which tools to enable
                        # "--tools=customers.read,invoices.read,products.read",
                    ],
                    env={
                        "STRIPE_SECRET_KEY": STRIPE_SECRET_KEY,
                    }
                ),
                timeout=30,
            ),
        )
    ],
)
from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams

STRIPE_SECRET_KEY = "YOUR_STRIPE_SECRET_KEY"

root_agent = Agent(
    model="gemini-flash-latest",
    name="stripe_agent",
    instruction="Help users manage their Stripe account",
    tools=[
        McpToolset(
            connection_params=StreamableHTTPConnectionParams(
                url="https://mcp.stripe.com",
                headers={
                    "Authorization": f"Bearer {STRIPE_SECRET_KEY}",
                },
            ),
        )
    ],
)
import { LlmAgent, MCPToolset } from "@google/adk";

const STRIPE_SECRET_KEY = "YOUR_STRIPE_SECRET_KEY";

const rootAgent = new LlmAgent({
    model: "gemini-flash-latest",
    name: "stripe_agent",
    instruction: "Help users manage their Stripe account",
    tools: [
        new MCPToolset({
            type: "StdioConnectionParams",
            serverParams: {
                command: "npx",
                args: [
                    "-y",
                    "@stripe/mcp",
                    "--tools=all",
                    // (Optional) Specify which tools to enable
                    // "--tools=customers.read,invoices.read,products.read",
                ],
                env: {
                    STRIPE_SECRET_KEY: STRIPE_SECRET_KEY,
                },
            },
        }),
    ],
});

export { rootAgent };
import { LlmAgent, MCPToolset } from "@google/adk";

const STRIPE_SECRET_KEY = "YOUR_STRIPE_SECRET_KEY";

const rootAgent = new LlmAgent({
    model: "gemini-flash-latest",
    name: "stripe_agent",
    instruction: "Help users manage their Stripe account",
    tools: [
        new MCPToolset({
            type: "StreamableHTTPConnectionParams",
            url: "https://mcp.stripe.com",
            transportOptions: {
                requestInit: {
                    headers: {
                        Authorization: `Bearer ${STRIPE_SECRET_KEY}`,
                    },
                },
            },
        }),
    ],
});

export { rootAgent };

最佳实践

在使用 Stripe MCP 服务器时,应启用人工确认机制来验证工具的操作;同时,在与其他 MCP 服务器配合使用时需格外谨慎,以降低被恶意代码注入的风险。

可用的工具

资源 工具 API
账户 API 标识符:`account_api` 占位符:`${account_id}` get_stripe_account_info “Retrieve account” 的中文翻译是“找回账户信息”或“恢复账户访问权限”。这个功能通常用于帮助用户重新获取被遗忘的账户密码、用户名或其他账户相关数据。
余额 retrieve_balance 查询账户余额
优惠券 create_coupon 创建优惠券
优惠券 list_coupons 列出优惠券
客户 create_customer 创建客户
客户 list_customers 列出所有客户
争议;纠纷 list_disputes 列出所有争议(disputes)
争议;纠纷 update_dispute 更新争议处理流程(或:更新与争议相关的处理措施)
发票 create_invoice 创建发票
发票 create_invoice_item 创建发票项目
发票 finalize_invoice 完成发票处理(即最终确认发票信息并完成支付流程)。
发票 list_invoices 列出所有发票
支付链接(Payment Link) create_payment_link 创建支付链接
PaymentIntent list_payment_intents List PaymentIntents
价格 create_price 创建价格
价格 list_prices 标价(List prices)
产品 API 标识符 占位符 create_product 创建产品
产品 API 标识符 占位符 list_products 列出产品
退款 create_refund 创建退款申请
订阅服务 cancel_subscription 取消订阅
订阅服务 list_subscriptions 列出所有订阅信息
订阅服务 update_subscription 更新订阅信息
其他 search_stripe_resources 搜索 Stripe 的相关资源
其他 fetch_stripe_resources 获取 Stripe 对象
其他 search_stripe_documentation 搜索关于 Stripe 的相关信息(知识库内容)。

其他资源