@agentwonderland/mcp 0.1.22 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,9 +54,10 @@ export async function pollCardSetup(token, timeoutMs = 120_000) {
54
54
  brand: status.card_brand ?? "card",
55
55
  consumerToken: status.consumer_token,
56
56
  };
57
- // Persist to config
57
+ // Persist to config (including paymentMethodId for mppx stripe charge)
58
58
  setCardConfig({
59
59
  consumerToken: card.consumerToken,
60
+ paymentMethodId: status.payment_method_id,
60
61
  last4: card.last4,
61
62
  brand: card.brand,
62
63
  });
@@ -19,6 +19,7 @@ export interface Config {
19
19
  userId: string | null;
20
20
  wallets: WalletEntry[];
21
21
  defaultWallet: string | null;
22
+ defaultPaymentMethod?: string;
22
23
  card: CardConfig | null;
23
24
  favorites: string[];
24
25
  /** Require user confirmation before spending. Default: true. Set false for headless/automated use. */
@@ -263,7 +263,12 @@ export function getCardConfig() {
263
263
  * Save card configuration after setup.
264
264
  */
265
265
  export function setCardConfig(card) {
266
- saveConfig({ card });
266
+ if (card) {
267
+ saveConfig({ card, defaultPaymentMethod: "card" });
268
+ }
269
+ else {
270
+ saveConfig({ card });
271
+ }
267
272
  }
268
273
  /**
269
274
  * Resolve a payment method string to a wallet + chain.
@@ -9,7 +9,7 @@
9
9
  * Users can configure multiple wallets with different chains and select
10
10
  * which to use per-request via `--pay-with <wallet-id|chain|card>`.
11
11
  */
12
- import { getWallets, getDefaultWallet, getCardConfig, resolveWalletAndChain, getApiUrl, } from "./config.js";
12
+ import { getConfig, getWallets, getDefaultWallet, getCardConfig, resolveWalletAndChain, getApiUrl, } from "./config.js";
13
13
  // Cache per wallet+chain combo to avoid re-initializing
14
14
  const fetchCache = new Map();
15
15
  // ── Helpers ─────────────────────────────────────────────────────
@@ -121,8 +121,9 @@ export async function getPaymentFetch(method) {
121
121
  }
122
122
  throw new Error(`Payment method "${method}" is not configured. Use the wallet_setup tool to configure a wallet`);
123
123
  }
124
- // Auto-detect: try default wallet, then card
124
+ // Auto-detect: try configured methods in order (card first if default)
125
125
  const configured = getConfiguredMethods();
126
+ const defaultMethod = getConfig().defaultPaymentMethod;
126
127
  for (const m of configured) {
127
128
  if (m === "card") {
128
129
  const ck = "card:card";
@@ -133,12 +134,23 @@ export async function getPaymentFetch(method) {
133
134
  fetchCache.set(ck, pf);
134
135
  return pf;
135
136
  }
137
+ // If the default method fails, throw instead of silently falling back
138
+ if (m === defaultMethod) {
139
+ const others = configured.filter((x) => x !== m);
140
+ const altText = others.length > 0 ? ` Available alternatives: ${others.join(", ")}` : "";
141
+ throw new Error(`Card payment failed to initialize. Check your card with wallet_status.${altText}`);
142
+ }
136
143
  continue;
137
144
  }
138
145
  // It's a chain name — resolve to wallet
139
146
  const resolved = resolveWalletAndChain(m);
140
- if (!resolved)
147
+ if (!resolved) {
148
+ if (m === defaultMethod) {
149
+ const others = configured.filter((x) => x !== m);
150
+ throw new Error(`Default payment method "${m}" is not configured.${others.length ? ` Alternatives: ${others.join(", ")}` : ""}`);
151
+ }
141
152
  continue;
153
+ }
142
154
  const ck = cacheKey(resolved.wallet.id, resolved.chain);
143
155
  if (fetchCache.has(ck))
144
156
  return fetchCache.get(ck);
@@ -182,6 +194,15 @@ export function getConfiguredMethods() {
182
194
  if (getCardConfig()) {
183
195
  methods.push("card");
184
196
  }
197
+ // Respect defaultPaymentMethod — move it to front of list
198
+ const defaultMethod = getConfig().defaultPaymentMethod;
199
+ if (defaultMethod) {
200
+ const idx = methods.indexOf(defaultMethod);
201
+ if (idx > 0) {
202
+ methods.splice(idx, 1);
203
+ methods.unshift(defaultMethod);
204
+ }
205
+ }
185
206
  return methods;
186
207
  }
187
208
  /**
package/dist/index.js CHANGED
@@ -37,10 +37,14 @@ export async function startMcpServer() {
37
37
  "5. Ask user to rate or tip after a successful run",
38
38
  "",
39
39
  "PAYMENT:",
40
- "- Credit/debit card is the easiest way to pay — just scan a QR code to connect, no funding needed.",
41
- "- Crypto wallets (Tempo USDC, Base USDC) are also supported for advanced users.",
40
+ "- Credit/debit card is the default and easiest way to pay — scan a QR code to connect, no funding needed.",
41
+ "- Crypto wallets (Tempo USDC, Base USDC) are available for advanced users.",
42
+ "- Card and crypto are SEPARATE payment methods. Card charges a credit card; crypto sends USDC on-chain.",
43
+ "- Card is set as the default payment method when configured.",
42
44
  "- Payment is automatic once configured. Users are never charged for failed runs.",
43
- "- Do NOT ask the user to set up payment before they try to run an agent. Let them explore freely — payment setup is handled inline when they're ready to pay.",
45
+ "- Do NOT ask the user to set up payment before they try to run an agent. Let them explore freely.",
46
+ "- If a specific payment method fails, report the error clearly. Do NOT silently fall back to a different method.",
47
+ "- When payment fails, suggest alternatives using wallet_status.",
44
48
  "",
45
49
  "MANAGING PAYMENT METHODS:",
46
50
  "- To remove a card: wallet_setup({ action: \"remove-card\" })",
package/dist/tools/run.js CHANGED
@@ -109,8 +109,11 @@ export function registerRunTools(server) {
109
109
  catch (err) {
110
110
  const apiErr = err;
111
111
  if (apiErr?.status === 402) {
112
- return text("Payment failed — your wallet may not have enough USDC.\n\n" +
113
- "Check your balance and fund your wallet, then try again.\n" +
112
+ const allMethods = getConfiguredMethods();
113
+ const methodName = method ?? allMethods[0] ?? "auto";
114
+ return text(`Payment failed — "${methodName}" payment was rejected.\n\n` +
115
+ "Check your payment method and try again.\n" +
116
+ (allMethods.length > 0 ? `Configured methods: ${allMethods.join(", ")}\n` : "") +
114
117
  "Use wallet_status to check your current payment methods.");
115
118
  }
116
119
  const msg = apiErr?.message ?? "Failed to run agent";
@@ -188,6 +191,8 @@ export function registerRunTools(server) {
188
191
  // surfaces it to the user as a distinct follow-up question, rather than
189
192
  // burying it inside a collapsed tool output.
190
193
  const feedbackAsk = [
194
+ `--- Job ${jobId} | ${agentName} | ${costLine} ---`,
195
+ "",
191
196
  `IMPORTANT: After presenting the result above, you MUST ask the user:`,
192
197
  `"${costLine} Was this result helpful? I can rate it (1-5 stars) or tip the builder for you."`,
193
198
  tipLine,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentwonderland/mcp",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "description": "MCP server for the Agent Wonderland AI agent marketplace",
6
6
  "bin": {
@@ -67,6 +67,7 @@ export async function pollCardSetup(
67
67
  card_last4?: string;
68
68
  card_brand?: string;
69
69
  consumer_token?: string;
70
+ payment_method_id?: string;
70
71
  }>(`/card/status?token=${token}`);
71
72
 
72
73
  if (status.status === "complete" && status.consumer_token) {
@@ -76,9 +77,10 @@ export async function pollCardSetup(
76
77
  consumerToken: status.consumer_token,
77
78
  };
78
79
 
79
- // Persist to config
80
+ // Persist to config (including paymentMethodId for mppx stripe charge)
80
81
  setCardConfig({
81
82
  consumerToken: card.consumerToken,
83
+ paymentMethodId: status.payment_method_id,
82
84
  last4: card.last4,
83
85
  brand: card.brand,
84
86
  });
@@ -27,6 +27,7 @@ export interface Config {
27
27
  userId: string | null;
28
28
  wallets: WalletEntry[];
29
29
  defaultWallet: string | null;
30
+ defaultPaymentMethod?: string;
30
31
  card: CardConfig | null;
31
32
  favorites: string[];
32
33
  /** Require user confirmation before spending. Default: true. Set false for headless/automated use. */
@@ -350,7 +351,11 @@ export function getCardConfig(): CardConfig | null {
350
351
  * Save card configuration after setup.
351
352
  */
352
353
  export function setCardConfig(card: CardConfig | null): void {
353
- saveConfig({ card });
354
+ if (card) {
355
+ saveConfig({ card, defaultPaymentMethod: "card" });
356
+ } else {
357
+ saveConfig({ card });
358
+ }
354
359
  }
355
360
 
356
361
  /**
@@ -11,6 +11,7 @@
11
11
  */
12
12
 
13
13
  import {
14
+ getConfig,
14
15
  getWallets,
15
16
  getDefaultWallet,
16
17
  getCardConfig,
@@ -141,8 +142,10 @@ export async function getPaymentFetch(method?: string): Promise<typeof fetch> {
141
142
  throw new Error(`Payment method "${method}" is not configured. Use the wallet_setup tool to configure a wallet`);
142
143
  }
143
144
 
144
- // Auto-detect: try default wallet, then card
145
+ // Auto-detect: try configured methods in order (card first if default)
145
146
  const configured = getConfiguredMethods();
147
+ const defaultMethod = getConfig().defaultPaymentMethod;
148
+
146
149
  for (const m of configured) {
147
150
  if (m === "card") {
148
151
  const ck = "card:card";
@@ -152,12 +155,24 @@ export async function getPaymentFetch(method?: string): Promise<typeof fetch> {
152
155
  fetchCache.set(ck, pf);
153
156
  return pf;
154
157
  }
158
+ // If the default method fails, throw instead of silently falling back
159
+ if (m === defaultMethod) {
160
+ const others = configured.filter((x) => x !== m);
161
+ const altText = others.length > 0 ? ` Available alternatives: ${others.join(", ")}` : "";
162
+ throw new Error(`Card payment failed to initialize. Check your card with wallet_status.${altText}`);
163
+ }
155
164
  continue;
156
165
  }
157
166
 
158
167
  // It's a chain name — resolve to wallet
159
168
  const resolved = resolveWalletAndChain(m);
160
- if (!resolved) continue;
169
+ if (!resolved) {
170
+ if (m === defaultMethod) {
171
+ const others = configured.filter((x) => x !== m);
172
+ throw new Error(`Default payment method "${m}" is not configured.${others.length ? ` Alternatives: ${others.join(", ")}` : ""}`);
173
+ }
174
+ continue;
175
+ }
161
176
  const ck = cacheKey(resolved.wallet.id, resolved.chain);
162
177
  if (fetchCache.has(ck)) return fetchCache.get(ck)!;
163
178
  const pf = await initForChain(resolved.wallet, resolved.chain);
@@ -202,6 +217,16 @@ export function getConfiguredMethods(): string[] {
202
217
  methods.push("card");
203
218
  }
204
219
 
220
+ // Respect defaultPaymentMethod — move it to front of list
221
+ const defaultMethod = getConfig().defaultPaymentMethod;
222
+ if (defaultMethod) {
223
+ const idx = methods.indexOf(defaultMethod);
224
+ if (idx > 0) {
225
+ methods.splice(idx, 1);
226
+ methods.unshift(defaultMethod);
227
+ }
228
+ }
229
+
205
230
  return methods;
206
231
  }
207
232
 
package/src/index.ts CHANGED
@@ -44,10 +44,14 @@ export async function startMcpServer(): Promise<void> {
44
44
  "5. Ask user to rate or tip after a successful run",
45
45
  "",
46
46
  "PAYMENT:",
47
- "- Credit/debit card is the easiest way to pay — just scan a QR code to connect, no funding needed.",
48
- "- Crypto wallets (Tempo USDC, Base USDC) are also supported for advanced users.",
47
+ "- Credit/debit card is the default and easiest way to pay — scan a QR code to connect, no funding needed.",
48
+ "- Crypto wallets (Tempo USDC, Base USDC) are available for advanced users.",
49
+ "- Card and crypto are SEPARATE payment methods. Card charges a credit card; crypto sends USDC on-chain.",
50
+ "- Card is set as the default payment method when configured.",
49
51
  "- Payment is automatic once configured. Users are never charged for failed runs.",
50
- "- Do NOT ask the user to set up payment before they try to run an agent. Let them explore freely — payment setup is handled inline when they're ready to pay.",
52
+ "- Do NOT ask the user to set up payment before they try to run an agent. Let them explore freely.",
53
+ "- If a specific payment method fails, report the error clearly. Do NOT silently fall back to a different method.",
54
+ "- When payment fails, suggest alternatives using wallet_status.",
51
55
  "",
52
56
  "MANAGING PAYMENT METHODS:",
53
57
  "- To remove a card: wallet_setup({ action: \"remove-card\" })",
package/src/tools/run.ts CHANGED
@@ -140,9 +140,12 @@ export function registerRunTools(server: McpServer): void {
140
140
  } catch (err: unknown) {
141
141
  const apiErr = err as { status?: number; message?: string };
142
142
  if (apiErr?.status === 402) {
143
+ const allMethods = getConfiguredMethods();
144
+ const methodName = method ?? allMethods[0] ?? "auto";
143
145
  return text(
144
- "Payment failed — your wallet may not have enough USDC.\n\n" +
145
- "Check your balance and fund your wallet, then try again.\n" +
146
+ `Payment failed — "${methodName}" payment was rejected.\n\n` +
147
+ "Check your payment method and try again.\n" +
148
+ (allMethods.length > 0 ? `Configured methods: ${allMethods.join(", ")}\n` : "") +
146
149
  "Use wallet_status to check your current payment methods."
147
150
  );
148
151
  }
@@ -243,6 +246,8 @@ export function registerRunTools(server: McpServer): void {
243
246
  // surfaces it to the user as a distinct follow-up question, rather than
244
247
  // burying it inside a collapsed tool output.
245
248
  const feedbackAsk = [
249
+ `--- Job ${jobId} | ${agentName} | ${costLine} ---`,
250
+ "",
246
251
  `IMPORTANT: After presenting the result above, you MUST ask the user:`,
247
252
  `"${costLine} Was this result helpful? I can rate it (1-5 stars) or tip the builder for you."`,
248
253
  tipLine,