stripe-link-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStripe Link CLI Skill
Stripe Link CLI Skill
Wraps @stripe/link-cli so Hermes can complete purchases on the user's behalf using one-time-use virtual cards or Shared Payment Tokens (SPT). Every spend is gated by an in-app approval in the Link mobile/web app — Hermes cannot self-approve.
US-only at the moment (Link account requirement). Windows is not supported by the upstream CLI — this skill is gated .
[linux, macos]封装@stripe/link-cli,使Hermes能够代表用户使用一次性虚拟卡或共享支付令牌(SPT)完成购买。每一笔支出都需要通过Link移动端/网页应用内的批准——Hermes无法自行批准。
目前仅支持美国地区(需Link账户)。上游CLI不支持Windows系统,因此本技能仅适用于环境。
[linux, macos]When to Use
使用场景
Trigger phrases:
- "buy X", "pay for X", "make a purchase", "complete checkout"
- "get me a card", "I need a payment method"
- "log in to Link", "connect my Link wallet"
- HTTP 402 response from a merchant API with
www-authenticate: ... method="stripe"
If the user wants a paid API call (HTTP 402, no checkout form), the path is wrong — use SPT via this same skill, or hand off to the skill.
cardmpp-agent触发短语:
- "购买X"、"为X付款"、"完成购买"、"完成结账"
- "给我一张卡"、"我需要支付方式"
- "登录Link"、"连接我的Link钱包"
- 商户API返回HTTP 402响应,且包含头信息
www-authenticate: ... method="stripe"
如果用户需要进行付费API调用(返回HTTP 402,但无结账表单),则不应使用路径——需通过本技能使用SPT,或转交至技能处理。
cardmpp-agentPrerequisites
前置条件
- Node.js 20+ available on (
PATH)node --version - US-based (Link account requirement)
The Link account, payment method, and spend-approval app do NOT need to be set up before Hermes attempts to pay — the CLI walks the user through them on first run:
- A Link account at https://app.link.com — created/linked during first auth
link-cli - At least one payment method — added during first run at https://app.link.com/wallet
- The Link mobile/web app — opened to approve the first spend request when it's made
No env vars required — auth state is stored locally by the CLI under its own config directory.
- 系统中需存在Node.js 20+版本(可通过
PATH验证)node --version - 位于美国地区(需Link账户)
在Hermes尝试支付前,无需预先设置Link账户、支付方式和支出批准应用——首次运行CLI时会引导用户完成这些步骤:
- Link账户:访问https://app.link.com,首次`link-cli`认证时创建/关联
- 至少一种支付方式:首次运行时在https://app.link.com/wallet添加
- Link移动端/网页应用:发起首次支出请求时需打开该应用进行批准
无需设置环境变量——CLI会在自身配置目录下本地存储认证状态。
Install
安装
Install once, globally:
npm install -g @stripe/link-cliOr invoke ad-hoc via . The skill below uses the installed form.
npx @stripe/link-clilink-cli全局安装一次:
npm install -g @stripe/link-cli或通过临时调用。以下技能说明使用已安装的形式。
npx @stripe/link-clilink-cliHow to Run
运行方式
All commands run through the tool. The CLI auto-detects non-TTY callers and emits compact output by default — fine for the model. Pass if a step needs structured fields.
terminaltoon--format jsonDiscover commands: .
Get a command's schema before invoking: .
link-cli --llms-fulllink-cli <command> --schema所有命令通过工具执行。CLI会自动检测非TTY调用者,默认输出简洁的格式——适合模型处理。若某步骤需要结构化字段,可传递参数。
terminaltoon--format json查看所有命令:。
调用前查看命令的 schema:。
link-cli --llms-fulllink-cli <command> --schemaProcedure
操作流程
1. Check / establish auth
1. 检查/建立认证
link-cli auth statusIf not authenticated, log in with a clear client name (this label shows in the user's Link app):
link-cli auth login --client-name "Hermes" --interval 5 --timeout 300The / form polls inline so the agent doesn't need to manage a step. Print the verification URL + phrase to the user and wait for the CLI to return.
--interval--timeout_nextBackground-polling pattern (when not using inline flags): If you run without / (or with ), it returns immediately with a , , and a like . Start that poll as a background terminal process with so you get notified when the user approves:
auth login--interval--timeoutpty=trueverification_urlphrase_next.commandauth status --interval 5 --max-attempts 60notify_on_complete=truelink-cli auth status --interval 5 --max-attempts 60link-cli auth status若未认证,使用清晰的客户端名称登录(该名称会显示在用户的Link应用中):
link-cli auth login --client-name "Hermes" --interval 5 --timeout 300--interval--timeout_next后台轮询模式(不使用内联标志时): 如果运行时未添加/参数(或使用),命令会立即返回、以及类似的。需启动该轮询作为后台终端进程,并设置,以便用户批准时收到通知:
auth login--interval--timeoutpty=trueverification_urlphraseauth status --interval 5 --max-attempts 60_next.commandnotify_on_complete=truelink-cli auth status --interval 5 --max-attempts 60→ run with: background=true, notify_on_complete=true, timeout=330
→ 运行参数:background=true, notify_on_complete=true, timeout=330
Print the verification URL and phrase to the user immediately — don't wait for them to ask. The background poll will notify you when auth succeeds.
**Do not proceed past this step until `auth status` confirms login.**
立即向用户展示验证URL和短语——不要等待用户询问。后台轮询会在认证成功时通知你。
**在`auth status`确认登录前,请勿进行下一步操作。**2. Evaluate the merchant before creating a spend request
2. 创建支出请求前评估商户
Decide the credential type:
| Merchant surface | |
|---|---|
| Standard web checkout form / Stripe Elements | |
Returns HTTP 402 with | |
Returns HTTP 402 without | unsupported — stop |
For 402 responses, do NOT decode the challenge manually. Pass the raw header:
link-cli mpp decode --challenge '<full WWW-Authenticate header>'This validates the challenge and extracts the network ID + decoded request body.
确定凭证类型:
| 商户界面 | |
|---|---|
| 标准网页结账表单 / Stripe Elements | |
返回HTTP 402响应,且 | |
返回HTTP 402响应,但 | 不支持——终止操作 |
对于402响应,请勿手动解码挑战信息。直接传递原始头信息:
link-cli mpp decode --challenge '<完整的WWW-Authenticate头内容>'该命令会验证挑战信息,并提取网络ID和解码后的请求体。
3. List payment methods + shipping
3. 列出支付方式和配送地址
link-cli payment-methods list
link-cli shipping-address listUse the first entry unless the user specifies otherwise. The from is the in the next step.
idpayment-methods list--payment-method-idlink-cli payment-methods list
link-cli shipping-address list除非用户指定,否则使用第一个条目。返回的即为下一步的参数值。
payment-methods listid--payment-method-id4. Create the spend request
4. 创建支出请求
Confirm the final total with the user before issuing this command. Amounts are in cents.
link-cli spend-request create \
--payment-method-id <pm_id> \
--merchant-name "<name>" \
--merchant-url "<url>" \
--context "<what is being purchased and why — MUST be ≥100 characters or the CLI returns VALIDATION_ERROR too_small>" \
--amount <cents> \
--line-item "name:<item>,unit_amount:<cents>,quantity:1" \
--total "type:total,display_text:Total,amount:<cents>" \
--request-approvalFor MPP merchants add .
--credential-type shared_payment_token--request-approvalstatus: "pending_approval"_next.commandspend-request retrieve <id> --interval 2 --max-attempts 300Best pattern: After returns, immediately start a background call that combines polling + card retrieval in one shot (see Section 5). This eliminates the gap between approval and retrieval that causes card expiry.
create --request-approvalretrieve在执行此命令前,需与用户确认最终金额。金额单位为美分。
link-cli spend-request create \
--payment-method-id <pm_id> \
--merchant-name "<商户名称>" \
--merchant-url "<商户网址>" \
--context "<购买内容及原因——必须≥100字符,否则CLI会返回VALIDATION_ERROR too_small错误>" \
--amount <金额(美分)> \
--line-item "name:<商品名称>,unit_amount:<单价(美分)>,quantity:1" \
--total "type:total,display_text:总计,amount:<总金额(美分)>" \
--request-approval对于MPP商户,需添加参数。
--credential-type shared_payment_token--request-approvalstatus: "pending_approval"_next.commandspend-request retrieve <id> --interval 2 --max-attempts 300最佳模式: 在返回后,立即启动后台调用,将轮询和卡片获取合并为一步(见第5节)。这样可以消除批准与获取卡片之间的时间差,避免卡片过期。
create --request-approvalretrieve5. Retrieve the credential — SECURELY
5. 安全获取凭证
Do not print card details to stdout. Use so the PAN never enters the agent's transcript or logs.
--output-fileAll five options are required by the schema even though they appear to have defaults — omitting any of , , , , or can cause a error. Always pass all five explicitly:
--timeout--interval--max-attempts--force--includeterminatedCombined poll + retrieve (preferred): Combines approval polling and card retrieval in one background call. Run this immediately after returns — it polls until the user approves, then retrieves the card in the same process, eliminating the approval-to-retrieval gap:
create --request-approvallink-cli spend-request retrieve <lsrq_id> \
--include card \
--output-file /tmp/link-card.json \
--timeout 600 \
--interval 2 \
--max-attempts 0 \
--force \
--format json请勿将卡片详情打印到标准输出。 使用参数,确保卡号(PAN)不会进入Agent的对话记录或日志。
--output-file模式中的五个选项均为schema必填项,即使它们看似有默认值——省略、、、或中的任何一个都可能导致错误。请始终显式传递这五个参数:
--timeout--interval--max-attempts--force--includeterminated合并轮询+获取(推荐): 将批准轮询和卡片获取合并为一个后台调用。在返回后立即执行——它会轮询直到用户批准,然后在同一进程中获取卡片,消除批准到获取的时间差:
create --request-approvallink-cli spend-request retrieve <lsrq_id> \
--include card \
--output-file /tmp/link-card.json \
--timeout 600 \
--interval 2 \
--max-attempts 0 \
--force \
--format json→ run with: background=true, notify_on_complete=true, timeout=660
→ 运行参数:background=true, notify_on_complete=true, timeout=660
**Post-approval retrieve (only when poll already confirmed approval):** If you already polled separately (e.g. via a background process) and confirmed `status: "approved"`, retrieve the card with zero interval:
link-cli spend-request retrieve <lsrq_id>
--include card
--output-file /tmp/link-card.json
--timeout 30
--interval 0
--max-attempts 0
--force
--format json
--include card
--output-file /tmp/link-card.json
--timeout 30
--interval 0
--max-attempts 0
--force
--format json
The file is written with `0600` perms; stdout shows only redacted fields (brand, last4, expiry) plus a `card_output_file` path.
**批准后获取(仅当已单独轮询确认批准时):** 如果已单独轮询(例如通过后台进程)并确认`status: "approved"`,则使用零间隔获取卡片:
link-cli spend-request retrieve <lsrq_id>
--include card
--output-file /tmp/link-card.json
--timeout 30
--interval 0
--max-attempts 0
--force
--format json
--include card
--output-file /tmp/link-card.json
--timeout 30
--interval 0
--max-attempts 0
--force
--format json
文件会以`0600`权限写入;标准输出仅显示脱敏字段(品牌、后四位、有效期)以及`card_output_file`路径。6. Use the credential
6. 使用凭证
-
For web checkout: hand the file path to the user, OR pass it to a browser-driving tool that fills the form directly from disk. Neveror
read_filethe card file into the agent's reasoning context.cat -
For MPP merchants:
link-cli mpp pay <merchant-url> \ --spend-request-id <lsrq_id> \ --method POST \ --data '<json body>'
-
网页结账:将文件路径交给用户,或传递给浏览器驱动工具直接从磁盘填充表单。切勿使用或
read_file命令将卡片文件内容读入Agent的推理上下文。cat -
MPP商户:
link-cli mpp pay <商户网址> \ --spend-request-id <lsrq_id> \ --method POST \ --data '<JSON请求体>'
7. Clean up
7. 清理
Delete the card file as soon as the purchase is done:
rm -f /tmp/link-card.json购买完成后立即删除卡片文件:
rm -f /tmp/link-card.jsonOptional: run as an MCP server instead
可选:作为MCP服务器运行
@stripe/link-cli --mcphermes mcp add stripe-link --command "npx" --args "@stripe/link-cli --mcp"Then should show . The same approval rules apply — MCP doesn't bypass the Link app approval step.
hermes mcp liststripe-link@stripe/link-cli --mcphermes mcp add stripe-link --command "npx" --args "@stripe/link-cli --mcp"然后运行应显示。同样的批准规则适用——MCP无法绕过Link应用的批准步骤。
hermes mcp liststripe-linkPitfalls
注意事项
- US-only. Outside the US, will fail. Tell the user, don't keep retrying.
auth login - must be ≥100 characters. The CLI returns
--contextif shorter. Write a detailed context string (what, why, who) — not a one-liner.VALIDATION_ERROR / too_small - does NOT poll. It returns immediately with
--request-approvaland apending_approval. You must separately poll via_next.command(background, notify_on_complete). The previous skill text that said it "polls until they approve or deny" was wrong.retrieve --interval 2 --max-attempts 300 - One-time cards expire ~90 seconds after approval. The window between the user approving in the Link app and you retrieving the card is very short. If the card expires, you must recreate the entire spend request and get a new approval. To avoid this: (a) use the combined poll+retrieve pattern in Section 5 so there's no gap, or (b) if you polled separately, retrieve the card immediately after seeing — do not do any other work in between.
status: "approved" - requires explicit options or it errors with
retrieve. Even though the schema shows defaults, omittingterminated,--timeout,--interval,--max-attempts, or--forcecan fail. Always pass all five. See Section 5 for exact flags.--include - Token refresh failures during retrieval. If fails with
retrieve, you need to re-auth (Token refresh failed (400)) and retry. But the card may expire during re-auth — which means recreating the spend request. This is why the combined poll+retrieve pattern is strongly preferred: it retrieves the card as part of the same process that detects approval, so no token refresh gap exists.auth login --interval 5 --timeout 300 - Card PAN must never enter agent context. Use every time. If you've already retrieved without it, immediately
--output-fileis not enough — the card is one-time-use but rotate hygiene matters.link-cli auth logout - blocks until the user acts. If the user is asleep, the CLI will hit its timeout. Set expectations.
--request-approval - Multi-step commands. Some commands return
_nextthat must be executed to continue. When in doubt, prefer the inline-polling flags (_next.command/--interval).--timeout - Output format defaults to in non-TTY mode. Fine for prose, but if a downstream step needs to parse a specific field, pass
toon.--format json - Don't default to . The merchant-evaluation step (Section 2) exists because picking the wrong credential type fails the purchase silently or leaks more data than needed.
card - only shows active requests by default. Use
spend-request listto see expired/denied/terminal-state requests. Useful for debugging.--include-history
- 仅支持美国地区。美国以外地区运行会失败。请告知用户,不要反复重试。
auth login - 必须≥100字符。如果长度不足,CLI会返回
--context错误。请编写详细的上下文字符串(内容、原因、对象)——不要用单行短句。VALIDATION_ERROR / too_small - 不会轮询。它会立即返回
--request-approval和pending_approval。必须通过_next.command单独进行轮询(后台运行,设置retrieve --interval 2 --max-attempts 300)。此前技能文档中称其“会轮询直到用户批准或拒绝”的描述有误。notify_on_complete=true - 一次性卡片在批准后约90秒过期。用户在Link应用中批准到获取卡片的时间窗口非常短。如果卡片过期,必须重新创建整个支出请求并获取新的批准。为避免这种情况:(a) 使用第5节中的合并轮询+获取模式,消除时间差;(b) 如果已单独轮询,确认后立即获取卡片——不要在此期间进行其他操作。
status: "approved" - 需要显式参数,否则会返回
retrieve错误。即使schema显示有默认值,省略terminated、--timeout、--interval、--max-attempts或--force中的任何一个都可能失败。请始终传递这五个参数。具体标志见第5节。--include - 获取过程中令牌刷新失败。如果返回
retrieve错误,需重新认证(Token refresh failed (400))并重试。但重新认证期间卡片可能过期——这意味着需要重新创建支出请求。因此强烈推荐使用合并轮询+获取模式:它在检测到批准的同一进程中获取卡片,不存在令牌刷新的时间差。auth login --interval 5 --timeout 300 - 卡片卡号(PAN)绝不能进入Agent上下文。每次都要使用参数。如果未使用该参数已获取卡片,仅执行
--output-file并不足够——虽然卡片是一次性的,但仍需注意安全卫生。link-cli auth logout - 会阻塞直到用户操作。如果用户未响应,CLI会超时。请提前告知用户预期。
--request-approval - 多步骤命令。部分命令会返回必须执行的
_next以继续操作。如有疑问,优先使用内联轮询标志(_next.command/--interval)。--timeout - 非TTY模式下默认输出格式为。适合文本处理,但如果下游步骤需要解析特定字段,需传递
toon参数。--format json - 不要默认使用类型。第2节的商户评估步骤存在的原因是,选择错误的凭证类型会导致购买失败或泄露不必要的数据。
card - 默认仅显示活跃请求。使用
spend-request list参数查看已过期/已拒绝/终端状态的请求。便于调试。--include-history
Verification
验证
link-cli --version && link-cli auth statusExit code 0 means installed and logged in.
link-cli --version && link-cli auth status退出码为0表示已安装且已登录。
Reference
参考
- — Session-verified error→fix log with exact commands: context ≥100 chars,
references/error-fixes.mderror, token refresh failure, card expiry, and the full correct end-to-end sequence.terminated
- ——经过会话验证的错误→修复日志,包含确切命令:上下文≥100字符、
references/error-fixes.md错误、令牌刷新失败、卡片过期以及完整正确的端到端流程。terminated