Skip to content

PayPal

PayPal MCP 服务器将你的 ADK 智能体连接到 PayPal 生态系统。此集成使你的智能体能够使用自然语言管理支付、发票、订阅和争议,实现自动化的商业工作流和业务洞察。

使用场景

  • 简化财务操作:直接通过聊天创建订单、发送发票和处理退款,无需切换上下文。你可以指示你的智能体“向客户 X 开票”或“退款订单 Y”。
  • 管理订阅和产品:通过创建产品、设置订阅计划和管理订阅者详细信息,使用自然语言处理周期性计费的完整生命周期。

  • 解决问题和跟踪性能:总结并接受争议索赔,跟踪运输状态,并检索商家洞察以快速做出数据驱动的决策。

前置条件

与智能体一起使用

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

PAYPAL_ENVIRONMENT = "SANDBOX"  # 选项:"SANDBOX" 或 "PRODUCTION"
PAYPAL_ACCESS_TOKEN = "YOUR_PAYPAL_ACCESS_TOKEN"

root_agent = Agent(
    model="gemini-2.5-pro",
    name="paypal_agent",
    instruction="帮助用户管理他们的 PayPal 账户",
    tools=[
        McpToolset(
            connection_params=StdioConnectionParams(
                server_params=StdioServerParameters(
                    command="npx",
                    args=[
                        "-y",
                        "@paypal/mcp",
                        "--tools=all",
                        # (可选)指定要启用的工具
                        # "--tools=subscriptionPlans.list,subscriptionPlans.show",
                    ],
                    env={
                        "PAYPAL_ACCESS_TOKEN": PAYPAL_ACCESS_TOKEN,
                        "PAYPAL_ENVIRONMENT": PAYPAL_ENVIRONMENT,
                    }
                ),
                timeout=300,
            ),
        )
    ],
)
from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams

PAYPAL_MCP_ENDPOINT = "https://mcp.sandbox.paypal.com/sse"  # 生产环境:https://mcp.paypal.com/sse
PAYPAL_ACCESS_TOKEN = "YOUR_PAYPAL_ACCESS_TOKEN"

root_agent = Agent(
    model="gemini-2.5-pro",
    name="paypal_agent",
    instruction="帮助用户管理他们的 PayPal 账户",
    tools=[
        McpToolset(
            connection_params=SseConnectionParams(
                url=PAYPAL_MCP_ENDPOINT,
                headers={
                    "Authorization": f"Bearer {PAYPAL_ACCESS_TOKEN}",
                },
            ),
        )
    ],
)

注意

令牌过期:PayPal 访问令牌的有效期为 3-8 小时。如果你的智能体停止工作,请确保你的令牌未过期,如有必要请生成新令牌。你应该实现令牌刷新逻辑来处理令牌过期。

可用工具

目录管理

工具 描述
create_product 在 PayPal 目录中创建新产品
list_products 从 PayPal 目录列出产品
show_product_details 显示 PayPal 目录中特定产品的详细信息
update_product 更新 PayPal 目录中的现有产品

争议管理

工具 描述
list_disputes 检索所有争议的摘要,可选过滤
get_dispute 检索有关特定争议的详细信息
accept_dispute_claim 接受争议索赔,以利于买家的方式解决

发票

工具 描述
create_invoice 在 PayPal 系统中创建新发票
list_invoices 列出发票
get_invoice 检索有关特定发票的详细信息
send_invoice 将现有发票发送给指定收件人
send_invoice_reminder 发送现有发票的提醒
cancel_sent_invoice 取消已发送的发票
generate_invoice_qr_code 为发票生成二维码

支付

工具 描述
create_order 根据提供的详细信息在 PayPal 系统中创建订单
create_refund 处理已捕获支付的退款
get_order 获取特定支付的详细信息
get_refund 获取特定退款的详细信息
pay_order 捕获已授权订单的支付

报告和洞察

工具 描述
get_merchant_insights 检索商家的商业智能指标和分析
list_transactions 列出所有交易

运输跟踪

工具 描述
create_shipment_tracking 为 PayPal 交易创建运输跟踪信息
get_shipment_tracking 获取特定运输的运输跟踪信息
update_shipment_tracking 更新特定运输的运输跟踪信息

订阅管理

工具 描述
cancel_subscription 取消活跃订阅
create_subscription 创建新订阅
create_subscription_plan 创建新订阅计划
update_subscription 更新现有订阅
list_subscription_plans 列出订阅计划
show_subscription_details 显示特定订阅的详细信息
show_subscription_plan_details 显示特定订阅计划的详细信息

配置

你可以使用 --tools 命令行参数控制启用哪些工具。这对于限制智能体的权限范围很有用。

你可以使用 --tools=all 启用所有工具,或指定逗号分隔的特定工具标识符列表。

注意:下面的配置标识符使用点记法(例如 invoices.create), 与暴露给智能体的工具名称(例如 create_invoice)不同。

产品products.create, products.list, products.update, products.show

争议disputes.list, disputes.get, disputes.create

发票invoices.create, invoices.list, invoices.get, invoices.send, invoices.sendReminder, invoices.cancel, invoices.generateQRC

订单和支付orders.create, orders.get, orders.capture, payments.createRefund, payments.getRefunds

交易transactions.list

运输shipment.create, shipment.get

订阅subscriptionPlans.create, subscriptionPlans.list, subscriptionPlans.show, subscriptions.create, subscriptions.show, subscriptions.cancel

额外资源