From fac638915ded8a31346952ddb5591e0886b9ecb9 Mon Sep 17 00:00:00 2001 From: Kohai Date: Mon, 23 Nov 2026 15:29:01 +0000 Subject: [PATCH 1/3] feat(mcp): run every Peer Cash tool on @zkp2p/sdk 0.16.0-rc.2 and drop @zkp2p/cash - peer_cash_source_capabilities, peer_cash_quote_source and peer_cash_relay_status now call peer.sell.sourceCapabilities(), quoteSource() and relayStatus() from the SDK. - peer_cash_prepare_access_policy stays registered with the same inputs and answers accessPolicyRequired: false with no transaction; its description says the merchant group it configured was retired in @zkp2p/sdk 0.15. - PEER_CASH_RELAY_API_KEY (or config.relayApiKey) reaches the SDK's Relay client: Relay's quote endpoint now requires a key. - @zkp2p/cash leaves package.json and the bundle; every tool name stays. The lockfile is regenerated once @zkp2p/sdk 0.16.0-rc.2 is published. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- CHANGELOG.md | 18 +++++++------- README.md | 14 +++++------ llms.txt | 2 +- package.json | 3 +-- skills/peer-cash/SKILL.md | 5 ++-- src/index.ts | 2 +- src/mcp/cash.ts | 40 ++++++++++++++------------------ tests/cash-mcp-relay-key.test.ts | 27 +++++++++++++++++++++ tests/cash-mcp.test.ts | 37 ++++++++++++++++------------- tsup.config.ts | 2 +- 11 files changed, 89 insertions(+), 63 deletions(-) create mode 100644 tests/cash-mcp-relay-key.test.ts diff --git a/AGENTS.md b/AGENTS.md index 7df3dfe..7685503 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -5,7 +5,7 @@ These instructions apply to the `peer-cli` repo. ## Working Rules - Treat `src/commands/registry.ts`, `src/mcp/cash.ts`, and `src/output/errors.ts` as runtime sources of truth. The files under `agents/` are their generated agent contracts. -- `src/mcp/cash.ts` sells through `@zkp2p/sdk` `peer.sell`. Only the Relay source tools and `peer_cash_prepare_access_policy` use `@zkp2p/cash`, because the SDK has no source routing or access policies. +- `src/mcp/cash.ts` runs every Peer Cash tool on `@zkp2p/sdk` `peer.sell`, including Relay source routing. `peer_cash_prepare_access_policy` is kept for existing agents and answers that no access policy is needed (the merchant group it configured was retired in SDK 0.15). - Do not hand-edit generated catalog files. Rebuild after changing command metadata. - Prefer dry-run previews for write paths. Use the single `--yes` execution flag only when immediate broadcast is intended. - Keep `peer mcp --profile read-only` as the default. The `cash` profile may prepare unsigned transactions but must never accept signer material, sign, or broadcast. Use `full` only for the complete operator surface. diff --git a/CHANGELOG.md b/CHANGELOG.md index 788f14c..f1a88a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,16 @@ ## Unreleased -- Run the Peer Cash MCP tools on `peer.sell` from `@zkp2p/sdk` 0.16.0-rc.1. - The Relay source tools (`peer_cash_source_capabilities`, - `peer_cash_quote_source`, `peer_cash_relay_status`) and - `peer_cash_prepare_access_policy` stay on `@zkp2p/cash`, which the SDK does - not replace for source routing or access policies. -- Remove the `includeRelaySources` argument of `peer_cash_capabilities`. - `PeerCashMcpConfig.client` is now a `PeerSell`; inject the Cash-only tools' - client through `cashOnlyClient`. +- Run every Peer Cash MCP tool on `peer.sell` from `@zkp2p/sdk` 0.16.0-rc.2, + including the Relay source tools (`peer_cash_source_capabilities`, + `peer_cash_quote_source`, `peer_cash_relay_status`), and drop the + `@zkp2p/cash` dependency. Every tool name stays. +- `peer_cash_prepare_access_policy` stays registered but answers + `accessPolicyRequired: false` with no transaction: the merchant group it + configured was retired in `@zkp2p/sdk` 0.15. +- Remove the `includeRelaySources` argument of `peer_cash_capabilities`; call + `peer_cash_source_capabilities` instead. `PeerCashMcpConfig.client` is now a + `PeerSell`. - `peer intent release` sends the `releaseAmount` that `@zkp2p/sdk` 0.15+ requires: the full on-chain intent amount by default (a depositor must release all of it), or `--amount` in USDC for an arbitrator's partial release. diff --git a/README.md b/README.md index 3e6aab2..7ebdf7a 100644 --- a/README.md +++ b/README.md @@ -120,16 +120,13 @@ custody boundary are unchanged: 7. `peer_cash_order` / `peer_cash_orders` — resume and inspect orders. 8. `peer_cash_prepare_withdraw` and `peer_cash_prepare_top_up` — prepare a withdrawal or top-up. -After 0.4.1, these tools sell through `peer.sell` from `@zkp2p/sdk` -`0.16.0-rc.1`. The SDK has no source routing or access policies, so the Relay -source tools (`peer_cash_source_capabilities`, `peer_cash_quote_source`, -`peer_cash_relay_status`) and `peer_cash_prepare_access_policy` still use -`@zkp2p/cash`. `peer_cash_capabilities` no +After 0.4.1, every one of these tools runs on `peer.sell` from `@zkp2p/sdk` +`0.16.0-rc.2`, including the Relay source tools. `peer_cash_capabilities` no longer takes `includeRelaySources`; call `peer_cash_source_capabilities` instead. A payee handle that does not exist on its platform fails with `PAYEE_NOT_FOUND`, which is not retryable. -Version 0.4.1 still exposes `peer_cash_prepare_access_policy`. Skip this legacy step for new orders. Finalize the confirmed create-deposit receipt and persist the deposit ID, even when the plan reports `accessPolicyRequired`. Applying the old policy would add a retired group to the deposit. +`peer_cash_prepare_access_policy` is a retired step. After 0.4.1 it answers `accessPolicyRequired: false` with no transaction, because the merchant group it configured was retired in `@zkp2p/sdk` 0.15. Version 0.4.1 still returns a transaction from it: skip that step, finalize the confirmed create-deposit receipt and persist the deposit ID, even when the plan reports `accessPolicyRequired`. Base USDC amounts are decimal strings in 6-decimal base units: 100 USDC is `100000000`. For pricing, read the corridor’s `pricing.kind` in `peer_cash_capabilities`. In the published CLI 0.4.1, Alipay/CNY and UPI/INR fix the rate at deposit creation. Other supported corridors bind the oracle rate when a buyer signals an intent. After 0.4.1, every corridor binds the oracle rate when a buyer signals an intent. @@ -159,8 +156,9 @@ Common settings: - `PEER_PAY_API_KEY` / `PEER_PAY_BASE_URL`: hosted checkout access - `PEER_BASE_API_URL`: Curator override. Defaults follow `PEER_ENV`: `api.zkp2p.xyz`, `api-preprod.zkp2p.xyz`, or `api-staging.zkp2p.xyz`. -- `PEER_CASH_RPC_URL`, `PEER_CASH_API_KEY`, `PEER_CASH_REFERRAL_CODE`, and - `PEER_CASH_REFERRER`: cash-profile overrides +- `PEER_CASH_RPC_URL`, `PEER_CASH_API_KEY`, `PEER_CASH_REFERRAL_CODE`, + `PEER_CASH_REFERRER`, and `PEER_CASH_RELAY_API_KEY` (Relay's quote endpoint + needs a key for `peer_cash_quote_source`): cash-profile overrides Use `peer config show`, `set`, `unset`, and `reset` for persistent local settings. `peer config show` masks secret values. Prefer environment variables diff --git a/llms.txt b/llms.txt index ab3661c..31396fb 100644 --- a/llms.txt +++ b/llms.txt @@ -48,7 +48,7 @@ local stdio profiles. 5. peer_cash_finalize after the confirmed createDeposit receipt 6. persist depositId and resume with peer_cash_order. Skip the retired group policy even when the 0.4.1 plan reports accessPolicyRequired. -After 0.4.1, peer_cash_* sells through @zkp2p/sdk peer.sell. Only peer_cash_source_capabilities, peer_cash_quote_source, peer_cash_relay_status and peer_cash_prepare_access_policy still use @zkp2p/cash. +After 0.4.1, every peer_cash_* tool runs on @zkp2p/sdk peer.sell, including the Relay source tools. peer_cash_prepare_access_policy answers accessPolicyRequired: false with no transaction (the merchant group it configured was retired in @zkp2p/sdk 0.15). Base USDC uses 6 decimals. Treat estimates as approximate. Retry read failures as reads; never retry an uncertain transaction without hash, wallet, and order diff --git a/package.json b/package.json index eea6879..0c820c2 100644 --- a/package.json +++ b/package.json @@ -77,8 +77,7 @@ }, "dependencies": { "@modelcontextprotocol/sdk": "^1.30.0", - "@zkp2p/cash": "0.7.0", - "@zkp2p/sdk": "0.16.0-rc.1", + "@zkp2p/sdk": "0.16.0-rc.2", "commander": "^14.0.3", "viem": "^2.55.19", "zod": "^4.4.3" diff --git a/skills/peer-cash/SKILL.md b/skills/peer-cash/SKILL.md index b911d56..66e3b1d 100644 --- a/skills/peer-cash/SKILL.md +++ b/skills/peer-cash/SKILL.md @@ -37,8 +37,9 @@ without inspecting it and obtaining operator approval. 5. Have the host wallet submit each transaction in order and confirm the `createDeposit` receipt. 6. Call `peer_cash_finalize` with the confirmed create-deposit transaction hash. - Skip the legacy `peer_cash_prepare_access_policy` step, including when the plan - reports `accessPolicyRequired`. That transaction adds a retired group. + Skip the retired `peer_cash_prepare_access_policy` step, including when the plan + reports `accessPolicyRequired`. After 0.4.1 it answers that no policy is needed; + in 0.4.1 its transaction adds a retired group. 7. Persist the returned `depositId`; use `peer_cash_order` to resume. Use `peer_cash_orders` to list a maker's orders, diff --git a/src/index.ts b/src/index.ts index 611f892..5075bd9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,5 +6,5 @@ export { type PeerMcpOptions, type PeerMcpProfile, } from './mcp/server.js'; -export { type PeerCashMcpConfig, type PeerCashOnlyClient } from './mcp/cash.js'; +export { type PeerCashMcpConfig } from './mcp/cash.js'; export { createProgram, runCli } from './cli.js'; diff --git a/src/mcp/cash.ts b/src/mcp/cash.ts index c1a8280..a1b53a4 100644 --- a/src/mcp/cash.ts +++ b/src/mcp/cash.ts @@ -1,7 +1,5 @@ import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'; -// @zkp2p/sdk has no Relay source routing or access policy; those tools stay on Cash. -import { createCashClient, type CashClient } from '@zkp2p/cash'; import { createPeer, type CurrencyType, @@ -25,20 +23,16 @@ export interface ReceiptClient { }): Promise; } -export type PeerCashOnlyClient = Pick< - CashClient, - 'sourceCapabilities' | 'quoteSource' | 'relayStatus' | 'prepareAccessPolicy' ->; - export interface PeerCashMcpConfig { client?: PeerSell; - cashOnlyClient?: PeerCashOnlyClient; receiptClient?: ReceiptClient; environment?: PeerOptions['environment']; rpcUrl?: string; apiKey?: string; referralCode?: string; referrer?: string | string[]; + /** Relay API key for the source tools; Relay's quote endpoint requires one. */ + relayApiKey?: string; } interface RegisterPeerCashToolsOptions { @@ -129,6 +123,7 @@ function resolveConfig( referralCode: config.referralCode ?? process.env.PEER_CASH_REFERRAL_CODE, referrer: config.referrer ?? process.env.PEER_CASH_REFERRER, + relayApiKey: config.relayApiKey ?? process.env.PEER_CASH_RELAY_API_KEY, }; } @@ -139,6 +134,7 @@ function clientOptions(config: PeerCashMcpConfig): PeerOptions { ...(config.apiKey ? { apiKey: config.apiKey } : {}), ...(config.referralCode ? { referralCode: config.referralCode } : {}), ...(config.referrer ? { referrer: config.referrer } : {}), + ...(config.relayApiKey ? { relay: { apiKey: config.relayApiKey } } : {}), }; } @@ -146,9 +142,6 @@ function getSellClient(config: PeerCashMcpConfig): PeerSell { return config.client ?? createPeer(clientOptions(config)).sell; } -function getCashOnlyClient(config: PeerCashMcpConfig): PeerCashOnlyClient { - return config.cashOnlyClient ?? createCashClient(clientOptions(config)); -} function getReceiptClient(config: PeerCashMcpConfig): ReceiptClient { if (config.receiptClient) return config.receiptClient; @@ -251,7 +244,6 @@ export function registerPeerCashTools( ): void { const config = resolveConfig(options.config, options.globalOptions); const client = getSellClient(config); - const cashOnlyClient = getCashOnlyClient(config); server.registerTool( PEER_CASH_TOOL_NAMES.capabilities, @@ -286,7 +278,7 @@ export function registerPeerCashTools( inputSchema: {}, annotations: { readOnlyHint: true, idempotentHint: true }, }, - () => handleTool(() => cashOnlyClient.sourceCapabilities()), + () => handleTool(() => client.sourceCapabilities()), ); server.registerTool( @@ -310,7 +302,7 @@ export function registerPeerCashTools( }, ({ user, amount, sourceChainId, sourceCurrency, recipient, tradeType }) => handleTool(() => - cashOnlyClient.quoteSource({ + client.quoteSource({ user, amount: BigInt(amount), source: { chainId: sourceChainId, currency: sourceCurrency }, @@ -329,7 +321,7 @@ export function registerPeerCashTools( inputSchema: { requestId: z.string().min(1) }, annotations: { readOnlyHint: true, idempotentHint: true }, }, - ({ requestId }) => handleTool(() => cashOnlyClient.relayStatus(requestId)), + ({ requestId }) => handleTool(() => client.relayStatus(requestId)), ); server.registerTool( @@ -457,18 +449,20 @@ export function registerPeerCashTools( server.registerTool( PEER_CASH_TOOL_NAMES.prepareAccessPolicy, { - title: 'Prepare an order access policy', + title: 'Prepare an order access policy (retired: no policy needed)', description: - 'Prepare one unsigned verified-buyer access-policy transaction after finalization for a payment method returned by accessPolicyPaymentMethods.', + 'Retired step, kept so existing agents keep working. The merchant group this tool used to configure was retired in @zkp2p/sdk 0.15, and peer_cash_prepare never asks for an access policy. It returns accessPolicyRequired: false and no transaction, so there is nothing to sign. Finalize the confirmed create-deposit receipt with peer_cash_finalize and persist the depositId.', inputSchema: { depositId, paymentMethod }, - annotations: { - readOnlyHint: false, - destructiveHint: false, - idempotentHint: true, - }, + annotations: { readOnlyHint: true, idempotentHint: true }, }, ({ depositId: id, paymentMethod: method }) => - handleTool(() => cashOnlyClient.prepareAccessPolicy(id, method as `0x${string}`)), + handleTool(() => ({ + depositId: id, + paymentMethod: method, + accessPolicyRequired: false, + transaction: null, + reason: 'The merchant group this step configured was retired in @zkp2p/sdk 0.15; no access policy is needed.', + })), ); server.registerTool( diff --git a/tests/cash-mcp-relay-key.test.ts b/tests/cash-mcp-relay-key.test.ts new file mode 100644 index 0000000..5607483 --- /dev/null +++ b/tests/cash-mcp-relay-key.test.ts @@ -0,0 +1,27 @@ +import { afterEach, describe, expect, it, vi } from 'vitest'; + +const createPeer = vi.fn((_options: Record) => ({ sell: {} })); +vi.mock('@zkp2p/sdk', () => ({ createPeer })); + +const { registerPeerCashTools } = await import('../src/mcp/cash.js'); + +afterEach(() => { + createPeer.mockClear(); + delete process.env.PEER_CASH_RELAY_API_KEY; +}); + +// Relay's quote endpoint requires an API key, so the source tools need one. +describe('Relay API key for the source tools', () => { + it('passes PEER_CASH_RELAY_API_KEY to the SDK as relay.apiKey', () => { + process.env.PEER_CASH_RELAY_API_KEY = 'relay-test-key'; + registerPeerCashTools({ registerTool: vi.fn() } as never, { config: { environment: 'staging' }, includeWrites: false }); + expect(createPeer).toHaveBeenCalledWith( + expect.objectContaining({ environment: 'staging', relay: { apiKey: 'relay-test-key' } }), + ); + }); + + it('sends no relay options without a key', () => { + registerPeerCashTools({ registerTool: vi.fn() } as never, { config: { environment: 'staging' }, includeWrites: false }); + expect(createPeer.mock.calls[0]![0]).not.toHaveProperty('relay'); + }); +}); diff --git a/tests/cash-mcp.test.ts b/tests/cash-mcp.test.ts index fa0bedf..7ae1e6a 100644 --- a/tests/cash-mcp.test.ts +++ b/tests/cash-mcp.test.ts @@ -18,12 +18,9 @@ function createHarness(includeWrites = false) { orders: vi.fn(async () => [{ depositId }]), prepareWithdraw: vi.fn(async () => ({ transactions: [] })), prepareTopUp: vi.fn(async () => ({ transactions: [] })), - }; - const cashOnlyClient = { sourceCapabilities: vi.fn(async () => ({ chains: [] })), quoteSource: vi.fn(async () => ({ requestId: 'relay-1', txs: [] })), relayStatus: vi.fn(async () => ({ requestId: 'relay-1', status: 'pending' })), - prepareAccessPolicy: vi.fn(async () => ({ transactions: [] })), }; const receiptClient = { getTransactionReceipt: vi.fn(async () => ({ @@ -36,7 +33,6 @@ function createHarness(includeWrites = false) { registerPeerCashTools({ registerTool } as never, { config: { client: client as never, - cashOnlyClient: cashOnlyClient as never, receiptClient: receiptClient as never, }, includeWrites, @@ -45,7 +41,7 @@ function createHarness(includeWrites = false) { const handlers = new Map( registerTool.mock.calls.map(([name, _config, handler]) => [name as string, handler]), ); - return { cashOnlyClient, client, handlers, receiptClient, registerTool }; + return { client, handlers, receiptClient, registerTool }; } beforeEach(() => { @@ -109,7 +105,7 @@ describe('Peer Cash MCP tools', () => { }); it('exposes live source routing and analytics inputs without signer authority', async () => { - const { cashOnlyClient, client, handlers } = createHarness(); + const { client, handlers } = createHarness(); await handlers.get('peer_cash_fill_stats')!({}); await handlers.get('peer_cash_source_capabilities')!({}); await handlers.get('peer_cash_quote_source')!({ @@ -126,8 +122,8 @@ describe('Peer Cash MCP tools', () => { }); expect(client.fillStats).toHaveBeenCalledOnce(); - expect(cashOnlyClient.sourceCapabilities).toHaveBeenCalledOnce(); - expect(cashOnlyClient.quoteSource).toHaveBeenCalledWith({ + expect(client.sourceCapabilities).toHaveBeenCalledOnce(); + expect(client.quoteSource).toHaveBeenCalledWith({ user: '0x1111111111111111111111111111111111111111', amount: 2500000n, source: { @@ -137,7 +133,7 @@ describe('Peer Cash MCP tools', () => { recipient: '0x3333333333333333333333333333333333333333', tradeType: 'EXACT_INPUT', }); - expect(cashOnlyClient.relayStatus).toHaveBeenCalledWith('relay-1'); + expect(client.relayStatus).toHaveBeenCalledWith('relay-1'); expect(client.buyer).toHaveBeenCalledWith( '0x1111111111111111111111111111111111111111', ); @@ -157,16 +153,25 @@ describe('Peer Cash MCP tools', () => { }); }); - it('prepares the required method-scoped access policy on @zkp2p/cash', async () => { - const { cashOnlyClient, handlers, registerTool } = createHarness(true); - await handlers.get('peer_cash_prepare_access_policy')!({ depositId, paymentMethod }); - - expect(cashOnlyClient.prepareAccessPolicy).toHaveBeenCalledWith(depositId, paymentMethod); + it('answers the retired access-policy step with no transaction', async () => { + const { client, handlers, registerTool } = createHarness(true); + const result = await handlers.get('peer_cash_prepare_access_policy')!({ depositId, paymentMethod }); + + expect(result.isError).toBeFalsy(); + expect(JSON.parse(result.content[0].text)).toEqual({ + depositId, + paymentMethod, + accessPolicyRequired: false, + transaction: null, + reason: 'The merchant group this step configured was retired in @zkp2p/sdk 0.15; no access policy is needed.', + }); + // Nothing is prepared or read for it. + for (const method of Object.values(client)) expect(method).not.toHaveBeenCalled(); const registration = registerTool.mock.calls.find( ([name]) => name === 'peer_cash_prepare_access_policy', ); - expect(registration?.[1].description).toContain('accessPolicyPaymentMethods'); - expect(registration?.[1].description).not.toContain('Cash App'); + expect(registration?.[1].description).toContain('retired in @zkp2p/sdk 0.15'); + expect(registration?.[1].annotations).toMatchObject({ readOnlyHint: true }); }); it('returns structured MCP errors without throwing transport failures', async () => { diff --git a/tsup.config.ts b/tsup.config.ts index 01d578b..5b8d928 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -10,5 +10,5 @@ export default defineConfig({ splitting: false, target: 'node22', outExtension: () => ({ js: '.cjs' }), - noExternal: ['@zkp2p/sdk', '@zkp2p/cash', '@zkp2p/contracts-v2', '@zkp2p/indexer-schema', 'viem', 'ethers', 'ox'], + noExternal: ['@zkp2p/sdk', '@zkp2p/contracts-v2', '@zkp2p/indexer-schema', 'viem', 'ethers', 'ox'], }); From 75a58a9cfba6cea045023f5387f220c45cfab2ed Mon Sep 17 00:00:00 2001 From: Kohai Date: Mon, 23 Nov 2026 15:59:50 +0000 Subject: [PATCH 2/3] fix(mcp): name the missing Relay key once and let the hosted server take it - peer_cash_quote_source without a Relay key returns RELAY_API_KEY_REQUIRED (retryable: false) naming PEER_CASH_RELAY_API_KEY, instead of a retryable Relay failure an agent would repeat. An injected client skips the check. - deploy/runtime.cjs accepts PEER_CASH_RELAY_API_KEY as an optional string key (redacted from logs like other values); NODE_ENV stays required. - CHANGELOG notes the access-policy result shape and the 'relay' source label. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 6 ++++++ deploy/AWS.md | 11 ++++++----- deploy/runtime.cjs | 8 +++++--- src/mcp/cash.ts | 18 ++++++++++++++---- tests/cash-mcp-relay-key.test.ts | 13 +++++++++++++ tests/runtime.test.ts | 12 ++++++++++++ 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1a88a7..088a5a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ - `peer_cash_prepare_access_policy` stays registered but answers `accessPolicyRequired: false` with no transaction: the merchant group it configured was retired in `@zkp2p/sdk` 0.15. + Its result changes from an unsigned transaction to + `{ depositId, paymentMethod, accessPolicyRequired: false, transaction: null, reason }`. +- `peer_cash_source_capabilities` reports `source: "relay"` (was `"relay-sdk"`). +- `peer_cash_quote_source` without a Relay key returns `RELAY_API_KEY_REQUIRED` + (not retryable) naming `PEER_CASH_RELAY_API_KEY`. The hosted server's + runtime config accepts `PEER_CASH_RELAY_API_KEY` as an optional key. - Remove the `includeRelaySources` argument of `peer_cash_capabilities`; call `peer_cash_source_capabilities` instead. `PeerCashMcpConfig.client` is now a `PeerSell`. diff --git a/deploy/AWS.md b/deploy/AWS.md index 767206b..980792f 100644 --- a/deploy/AWS.md +++ b/deploy/AWS.md @@ -65,9 +65,10 @@ Each image deploy writes the snapshot to a per-attempt file under `PORT` and keys matching `*_NEXT` are excluded. Host edits do not persist across deploys. -`deploy/runtime.cjs` accepts exactly `NODE_ENV`. Adding or removing a key in -Infisical makes the reconcile deploy fail its health check and roll back; change -the loader's expected key set and deploy it first, then edit Infisical. +`deploy/runtime.cjs` requires `NODE_ENV` and accepts one optional key, +`PEER_CASH_RELAY_API_KEY`, which `peer_cash_quote_source` needs for Relay quotes. +Any other key in Infisical makes the reconcile deploy fail its health check and +roll back; change the loader's key sets and deploy it first, then edit Infisical. ## Image and local verification @@ -76,8 +77,8 @@ image uses Node 22.23.5 and UID 10001, with the HTTP entrypoint bound to `127.0.0.1` and `PORT=8080` by default. The container starts through `/opt/peer/runtime.cjs`, which reads the config-CD snapshot mounted at `/run/secrets/runtime.json`. -This file must contain exactly `NODE_ENV`, as a string, for example -`{"NODE_ENV":"production"}`. `PORT` is forbidden in the file: Peer Deploy sets it +This file must contain `NODE_ENV` and may contain `PEER_CASH_RELAY_API_KEY`, both +strings, for example `{"NODE_ENV":"production"}`. `PORT` is forbidden in the file: Peer Deploy sets it through container environment variables for each blue-green slot, and the wrapper preserves that value. The service needs no application secrets, database, Redis or persistent application volume. diff --git a/deploy/runtime.cjs b/deploy/runtime.cjs index 172f351..d3a34fa 100644 --- a/deploy/runtime.cjs +++ b/deploy/runtime.cjs @@ -7,6 +7,8 @@ function fail(message) { } const expected = ['NODE_ENV']; +// Optional: feeds Relay quotes for peer_cash_quote_source. +const optional = ['PEER_CASH_RELAY_API_KEY']; let source = '/run/secrets/runtime.json'; let config; try { @@ -15,7 +17,7 @@ try { // JSON parser errors can include the input, so never print the original error. if (error.code !== 'ENOENT') fail('Cannot read or parse runtime configuration'); source = 'container env (legacy)'; - config = Object.fromEntries(expected + config = Object.fromEntries([...expected, ...optional] .filter((name) => Object.hasOwn(process.env, name)) .map((name) => [name, process.env[name]])); } @@ -23,11 +25,11 @@ if (config === null || typeof config !== 'object' || Array.isArray(config)) { fail('Runtime configuration must be an object'); } const missing = expected.filter((name) => !Object.hasOwn(config, name)); -const extra = Object.keys(config).filter((name) => !expected.includes(name)); +const extra = Object.keys(config).filter((name) => !expected.includes(name) && !optional.includes(name)); if (missing.length || extra.length) { fail(`Invalid runtime configuration keys (missing: ${missing.join(', ') || 'none'}; unexpected: ${extra.join(', ') || 'none'})`); } -const nonStrings = expected.filter((name) => typeof config[name] !== 'string'); +const nonStrings = Object.keys(config).filter((name) => typeof config[name] !== 'string'); if (nonStrings.length) fail(`Runtime configuration must contain strings: ${nonStrings.join(', ')}`); process.stderr.write(`runtime config from ${source}\n`); diff --git a/src/mcp/cash.ts b/src/mcp/cash.ts index a1b53a4..8430d20 100644 --- a/src/mcp/cash.ts +++ b/src/mcp/cash.ts @@ -301,15 +301,25 @@ export function registerPeerCashTools( annotations: { readOnlyHint: true, idempotentHint: false }, }, ({ user, amount, sourceChainId, sourceCurrency, recipient, tradeType }) => - handleTool(() => - client.quoteSource({ + handleTool(() => { + // Relay's quote endpoint rejects keyless requests; say so once instead of + // returning a retryable failure an agent would repeat. + if (!options.config?.client && !config.relayApiKey) { + throw { + code: 'RELAY_API_KEY_REQUIRED', + retryable: false, + message: 'Relay quotes need an API key, and this server has none configured.', + remediation: 'Set PEER_CASH_RELAY_API_KEY for the peer MCP server, then retry. Do not retry before that.', + }; + } + return client.quoteSource({ user, amount: BigInt(amount), source: { chainId: sourceChainId, currency: sourceCurrency }, ...(recipient ? { recipient } : {}), ...(tradeType ? { tradeType } : {}), - }), - ), + }); + }), ); server.registerTool( diff --git a/tests/cash-mcp-relay-key.test.ts b/tests/cash-mcp-relay-key.test.ts index 5607483..b212c3c 100644 --- a/tests/cash-mcp-relay-key.test.ts +++ b/tests/cash-mcp-relay-key.test.ts @@ -20,6 +20,19 @@ describe('Relay API key for the source tools', () => { ); }); + it('answers quote_source without a key with a non-retryable error naming the env var', async () => { + const registerTool = vi.fn(); + registerPeerCashTools({ registerTool } as never, { config: { environment: 'staging' }, includeWrites: false }); + const quote = registerTool.mock.calls.find(([name]) => name === 'peer_cash_quote_source')![2]; + const result = await quote({ user: `0x${'22'.repeat(20)}`, amount: '1', sourceChainId: 10, sourceCurrency: '0x0' }); + expect(result.isError).toBe(true); + expect(JSON.parse(result.content[0].text).error).toMatchObject({ + code: 'RELAY_API_KEY_REQUIRED', + retryable: false, + }); + expect(result.content[0].text).toContain('PEER_CASH_RELAY_API_KEY'); + }); + it('sends no relay options without a key', () => { registerPeerCashTools({ registerTool: vi.fn() } as never, { config: { environment: 'staging' }, includeWrites: false }); expect(createPeer.mock.calls[0]![0]).not.toHaveProperty('relay'); diff --git a/tests/runtime.test.ts b/tests/runtime.test.ts index 03c0430..efb9e70 100644 --- a/tests/runtime.test.ts +++ b/tests/runtime.test.ts @@ -56,6 +56,18 @@ describe('MCP runtime configuration', () => { expect(result.stderr).toBe(fileSource); }); + it('accepts the optional Relay key, exposes it to the server and redacts it from output', () => { + const relayKey = 'relay-key-0123456789abcdef'; + const result = runRuntime({ NODE_ENV: 'production', PEER_CASH_RELAY_API_KEY: relayKey }, + 'console.log(process.env.PEER_CASH_RELAY_API_KEY === "relay-key-0123456789abcdef", process.env.PEER_CASH_RELAY_API_KEY)'); + expect(result.status).toBe(0); + expect(result.stdout).toBe('true [REDACTED]\n'); + }); + + it('rejects a non-string optional Relay key', () => { + expectRejected({ NODE_ENV: 'production', PEER_CASH_RELAY_API_KEY: 123 }, 'PEER_CASH_RELAY_API_KEY'); + }); + it('rejects missing keys even when container env provides them', () => { expectRejected({}, 'NODE_ENV'); }); From 4355e120687e7b40737689867c20537e92a01df6 Mon Sep 17 00:00:00 2001 From: Kohai Date: Mon, 23 Nov 2026 16:14:08 +0000 Subject: [PATCH 3/3] chore(deps): lock @zkp2p/sdk 0.16.0-rc.2 from npm and drop @zkp2p/cash Co-Authored-By: Claude Opus 5.5 --- package-lock.json | 264 +--------------------------------------------- 1 file changed, 4 insertions(+), 260 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9b88f6e..f7f1537 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,8 +10,7 @@ "license": "MIT", "dependencies": { "@modelcontextprotocol/sdk": "^1.30.0", - "@zkp2p/cash": "0.7.0", - "@zkp2p/sdk": "0.16.0-rc.1", + "@zkp2p/sdk": "0.16.0-rc.2", "commander": "^14.0.3", "viem": "^2.55.19", "zod": "^4.4.3" @@ -1130,17 +1129,6 @@ "node": ">=14" } }, - "node_modules/@relayprotocol/relay-sdk": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/@relayprotocol/relay-sdk/-/relay-sdk-7.0.2.tgz", - "integrity": "sha512-3VLRNEERcxTJnTcO1YDGsxYC8XPpGVou0cr/o3yqm1wyVuxQaScjlL99nHH7ghob08b7oZtzjrMPDIfejoSttA==", - "dependencies": { - "axios": "^1.6.5" - }, - "peerDependencies": { - "viem": ">=2.26.0" - } - }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.60.0", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.60.0.tgz", @@ -2127,94 +2115,10 @@ "url": "https://opencollective.com/vitest" } }, - "node_modules/@zkp2p/cash": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/@zkp2p/cash/-/cash-0.7.0.tgz", - "integrity": "sha512-p31oi+C4L397sFkGEngDMZHn54NrLRuVYuFlYfvhSP3kMK6vVoWIuxaE29UmkWwrfeuGAOZjTrSGqKei2XSpmA==", - "license": "MIT", - "dependencies": { - "@relayprotocol/relay-sdk": "^7.0.1", - "@zkp2p/sdk": "0.14.5", - "zod": "^4.4.3" - }, - "engines": { - "node": ">=22" - }, - "peerDependencies": { - "react": ">=18", - "viem": ">=2.37.3 <3" - }, - "peerDependenciesMeta": { - "react": { - "optional": true - } - } - }, - "node_modules/@zkp2p/cash/node_modules/@zkp2p/sdk": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/@zkp2p/sdk/-/sdk-0.14.5.tgz", - "integrity": "sha512-6sj+QrURvMT71CDokeSkznUGn8wVjCuyVl6N3CyDqUDyncFD3QQdOq8jmgN22GZO+3Rudebq1JOWG9CD5/mDMA==", - "license": "MIT", - "dependencies": { - "@zkp2p/contracts-v2": "0.4.3", - "@zkp2p/indexer-schema": "0.22.0", - "@zkp2p/zkp2p-attestation": "3.1.0", - "ethers": "^6.0.0", - "ox": "^0.11.1" - }, - "engines": { - "node": ">=22" - }, - "peerDependencies": { - "react": ">=16.8.0", - "viem": "^2.37.3" - }, - "peerDependenciesMeta": { - "react": { - "optional": true - } - } - }, - "node_modules/@zkp2p/cash/node_modules/@zkp2p/zkp2p-attestation": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@zkp2p/zkp2p-attestation/-/zkp2p-attestation-3.1.0.tgz", - "integrity": "sha512-VBjqpUrUGQGZcjVbLGALzg26z341hOun74cnBlGnAdsm9QQwm1+wAncCuIRRlszg9RcHlGaRmQKPN+mnVAY0NQ==", - "dependencies": { - "@peculiar/x509": "^1.14.0", - "ethers": "^6.13.4" - }, - "bin": { - "zkp2p-attestation-verify": "dist/cli/verify.js" - }, - "engines": { - "node": ">=20" - } - }, - "node_modules/@zkp2p/contracts-v2": { - "version": "0.4.3", - "resolved": "https://registry.npmjs.org/@zkp2p/contracts-v2/-/contracts-v2-0.4.3.tgz", - "integrity": "sha512-J+SGmJQGjlsW8Yp3BXlZ0i433Vchw0zuz7A7gEG/J9cwc00zW06NklZdLrLMk4YKa68/YQG4dNY3QcV6l/NpLg==", - "license": "MIT", - "dependencies": { - "abitype": "^1.0.0" - }, - "peerDependencies": { - "ethers": "^5.0.0 || ^6.0.0" - } - }, - "node_modules/@zkp2p/indexer-schema": { - "version": "0.22.0", - "resolved": "https://registry.npmjs.org/@zkp2p/indexer-schema/-/indexer-schema-0.22.0.tgz", - "integrity": "sha512-TJw4oRwwU+FZOJipTEYdB1flSUfnFmkCTjf8P8obfgA1k5zt/RE7kstHqJTvQKwC+P35lHjmsOln/4GHS98I0Q==", - "license": "MIT", - "engines": { - "node": ">=16" - } - }, "node_modules/@zkp2p/sdk": { - "version": "0.16.0-rc.1", - "resolved": "https://registry.npmjs.org/@zkp2p/sdk/-/sdk-0.16.0-rc.1.tgz", - "integrity": "sha512-D47z2pVdEgPDWz1MA7usDYTmWR+ceU5uuNdVj+HkyhhTAVauHXsCS1n9u8euRCnawJeWaC4QWU8ajjXt1Uw+hA==", + "version": "0.16.0-rc.2", + "resolved": "https://registry.npmjs.org/@zkp2p/sdk/-/sdk-0.16.0-rc.2.tgz", + "integrity": "sha512-UTqOlmNtG90K1yjYN/dPbV28khrZcyQAoLrGEV4DzBsY/VWQLtfp7Lq+cdKdvwpR3+ydQ3jT9BJZKh68Zm8+QQ==", "license": "MIT", "dependencies": { "@zkp2p/zkp2p-attestation": "4.0.0-rc.12", @@ -2312,18 +2216,6 @@ "integrity": "sha512-G965FqalsNyrPqgEGON7nIx1e/OVENSgiEIzyC63haUMuvNnwIgIjMs52hlTCKhkBny7A2ORNlfY9Zu+jmGk1Q==", "license": "MIT" }, - "node_modules/agent-base": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", - "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", - "license": "MIT", - "dependencies": { - "debug": "4" - }, - "engines": { - "node": ">= 6.0.0" - } - }, "node_modules/ajv": { "version": "8.18.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.18.0.tgz", @@ -2436,24 +2328,6 @@ "js-tokens": "^10.0.0" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT" - }, - "node_modules/axios": { - "version": "1.19.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.19.0.tgz", - "integrity": "sha512-ht/iuYZXEjFxLH/Hkezgd7m6JKlHHXEUSneaDz8uZe1Gj5QZtCnpyDsckvAiEnT89OEbCLmnte4R4sn7P0EKFw==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.16.0", - "form-data": "^4.0.6", - "https-proxy-agent": "^5.0.1", - "proxy-from-env": "^2.1.0" - } - }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -2663,18 +2537,6 @@ "dev": true, "license": "MIT" }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "14.0.3", "resolved": "https://registry.npmjs.org/commander/-/commander-14.0.3.tgz", @@ -2813,15 +2675,6 @@ "dev": true, "license": "MIT" }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -2911,21 +2764,6 @@ "node": ">= 0.4" } }, - "node_modules/es-set-tostringtag": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", - "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.6", - "has-tostringtag": "^1.0.2", - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/esbuild": { "version": "0.28.2", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.2.tgz", @@ -3470,26 +3308,6 @@ "dev": true, "license": "ISC" }, - "node_modules/follow-redirects": { - "version": "1.16.0", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.16.0.tgz", - "integrity": "sha512-y5rN/uOsadFT/JfYwhxRS5R7Qce+g3zG97+JrtFZlC9klX/W5hD7iiLzScI4nZqUS7DNUdhPgw4xI8W2LuXlUw==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, "node_modules/foreground-child": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", @@ -3507,43 +3325,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/form-data": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.6.tgz", - "integrity": "sha512-vKatAh4SlVfgbv+YtmhiRjhEMJsYpsG1Y2rMQtR+SVSbytsSD1YGzDIcrAJmdFec88u/+VoGmxnl+80gL1tRCQ==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "es-set-tostringtag": "^2.1.0", - "hasown": "^2.0.4", - "mime-types": "^2.1.35" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/form-data/node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/form-data/node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/forwarded": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", @@ -3744,21 +3525,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-tostringtag": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", - "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "license": "MIT", - "dependencies": { - "has-symbols": "^1.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/hasown": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", @@ -3807,19 +3573,6 @@ "url": "https://opencollective.com/express" } }, - "node_modules/https-proxy-agent": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", - "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", - "license": "MIT", - "dependencies": { - "agent-base": "6", - "debug": "4" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/iconv-lite": { "version": "0.7.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz", @@ -4772,15 +4525,6 @@ "node": ">= 0.10" } }, - "node_modules/proxy-from-env": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-2.1.0.tgz", - "integrity": "sha512-cJ+oHTW1VAEa8cJslgmUZrc+sjRKgAKl3Zyse6+PV38hZe/V6Z14TbCuXcan9F9ghlz4QrFr2c92TNF82UkYHA==", - "license": "MIT", - "engines": { - "node": ">=10" - } - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz",