@agentwonderland/mcp 0.1.16 → 0.1.17
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.
- package/dist/core/card-setup.d.ts +21 -0
- package/dist/core/card-setup.js +63 -0
- package/dist/index.js +8 -8
- package/dist/tools/run.js +10 -3
- package/dist/tools/solve.js +10 -3
- package/dist/tools/wallet.js +17 -52
- package/package.json +1 -1
- package/src/core/card-setup.ts +85 -0
- package/src/index.ts +8 -8
- package/src/tools/run.ts +11 -5
- package/src/tools/solve.ts +11 -5
- package/src/tools/wallet.ts +18 -59
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initiate card setup — creates a Stripe Checkout session and returns
|
|
3
|
+
* QR code + short URL for the user to scan.
|
|
4
|
+
*/
|
|
5
|
+
export declare function initiateCardSetup(): Promise<{
|
|
6
|
+
qr: string;
|
|
7
|
+
url: string;
|
|
8
|
+
token: string;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* Format the card setup prompt shown to the user.
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatCardSetupPrompt(qr: string, url: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Poll for card setup completion. Returns the card details or null on timeout.
|
|
16
|
+
*/
|
|
17
|
+
export declare function pollCardSetup(token: string, timeoutMs?: number): Promise<{
|
|
18
|
+
last4: string;
|
|
19
|
+
brand: string;
|
|
20
|
+
consumerToken: string;
|
|
21
|
+
} | null>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import QRCode from "qrcode";
|
|
2
|
+
import { apiPost, apiGet } from "./api-client.js";
|
|
3
|
+
import { getApiUrl, setCardConfig } from "./config.js";
|
|
4
|
+
/**
|
|
5
|
+
* Initiate card setup — creates a Stripe Checkout session and returns
|
|
6
|
+
* QR code + short URL for the user to scan.
|
|
7
|
+
*/
|
|
8
|
+
export async function initiateCardSetup() {
|
|
9
|
+
const { url: _checkoutUrl, token } = await apiPost("/card/setup", {});
|
|
10
|
+
// Short redirect URL keeps the QR code small and scannable
|
|
11
|
+
const apiUrl = getApiUrl();
|
|
12
|
+
const shortUrl = `${apiUrl}/card/link/${token}`;
|
|
13
|
+
const qr = await QRCode.toString(shortUrl, {
|
|
14
|
+
type: "utf8",
|
|
15
|
+
errorCorrectionLevel: "L",
|
|
16
|
+
margin: 2,
|
|
17
|
+
});
|
|
18
|
+
return { qr, url: shortUrl, token };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Format the card setup prompt shown to the user.
|
|
22
|
+
*/
|
|
23
|
+
export function formatCardSetupPrompt(qr, url) {
|
|
24
|
+
return [
|
|
25
|
+
"Connect a payment card to get started:\n",
|
|
26
|
+
qr,
|
|
27
|
+
`Or open: ${url}`,
|
|
28
|
+
"",
|
|
29
|
+
"We also support crypto wallets (Base USDC, Tempo USDC) — use wallet_setup({ action: \"create\" }) if you prefer.",
|
|
30
|
+
"",
|
|
31
|
+
"IMPORTANT: Present the QR code and link above to the user. After they enter their card, call wallet_setup({ action: \"add-card\" }) to confirm the connection.",
|
|
32
|
+
].join("\n");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Poll for card setup completion. Returns the card details or null on timeout.
|
|
36
|
+
*/
|
|
37
|
+
export async function pollCardSetup(token, timeoutMs = 120_000) {
|
|
38
|
+
const deadline = Date.now() + timeoutMs;
|
|
39
|
+
while (Date.now() < deadline) {
|
|
40
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
41
|
+
try {
|
|
42
|
+
const status = await apiGet(`/card/status?token=${token}`);
|
|
43
|
+
if (status.status === "complete" && status.consumer_token) {
|
|
44
|
+
const card = {
|
|
45
|
+
last4: status.card_last4 ?? "????",
|
|
46
|
+
brand: status.card_brand ?? "card",
|
|
47
|
+
consumerToken: status.consumer_token,
|
|
48
|
+
};
|
|
49
|
+
// Persist to config
|
|
50
|
+
setCardConfig({
|
|
51
|
+
consumerToken: card.consumerToken,
|
|
52
|
+
last4: card.last4,
|
|
53
|
+
brand: card.brand,
|
|
54
|
+
});
|
|
55
|
+
return card;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Keep polling
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -30,17 +30,17 @@ export async function startMcpServer() {
|
|
|
30
30
|
"The MCP auto-uploads to cloud storage and replaces with a URL. Never base64-encode.",
|
|
31
31
|
"",
|
|
32
32
|
"WORKFLOW:",
|
|
33
|
-
"1.
|
|
34
|
-
"2.
|
|
35
|
-
"3.
|
|
36
|
-
"4. run_agent
|
|
33
|
+
"1. search_agents() or solve() — find agents for the task",
|
|
34
|
+
"2. get_agent() — check required input fields before running",
|
|
35
|
+
"3. run_agent() or solve() with ALL required fields",
|
|
36
|
+
"4. If no payment method is set up, run_agent returns a QR code to connect a credit card — present it to the user",
|
|
37
37
|
"5. Ask user to rate or tip after a successful run",
|
|
38
38
|
"",
|
|
39
39
|
"PAYMENT:",
|
|
40
|
-
"-
|
|
41
|
-
"-
|
|
42
|
-
"-
|
|
43
|
-
"-
|
|
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.",
|
|
42
|
+
"- 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.",
|
|
44
44
|
"",
|
|
45
45
|
"REQUIRED FIELDS:",
|
|
46
46
|
"Always check the agent's input schema (via get_agent) before calling run_agent.",
|
package/dist/tools/run.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getConfiguredMethods, hasWalletConfigured, getWalletAddress } from "../
|
|
|
5
5
|
import { requiresSpendConfirmation, getDefaultTipAmount } from "../core/config.js";
|
|
6
6
|
import { formatRunResult } from "../core/formatters.js";
|
|
7
7
|
import { storeFeedbackToken } from "./_token-cache.js";
|
|
8
|
+
import { initiateCardSetup, formatCardSetupPrompt } from "../core/card-setup.js";
|
|
8
9
|
const POLL_INTERVAL_MS = 3000;
|
|
9
10
|
const POLL_MAX_MS = 120000; // 2 minutes
|
|
10
11
|
async function pollJobUntilDone(jobId, agentName) {
|
|
@@ -45,9 +46,15 @@ export function registerRunTools(server) {
|
|
|
45
46
|
confirmed: z.boolean().optional().describe("Set to true to confirm spending after seeing the price quote."),
|
|
46
47
|
}, async ({ agent_id, input, pay_with, confirmed }) => {
|
|
47
48
|
if (!hasWalletConfigured()) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
try {
|
|
50
|
+
const { qr, url } = await initiateCardSetup();
|
|
51
|
+
return text(formatCardSetupPrompt(qr, url));
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return text("No payment method configured.\n\n" +
|
|
55
|
+
"To add a credit card: wallet_setup({ action: \"add-card\" })\n" +
|
|
56
|
+
"To use crypto: wallet_setup({ action: \"create\" })");
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
// Resolve agent and fetch details
|
|
53
60
|
let agent;
|
package/dist/tools/solve.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { apiGet, apiPost, apiPostWithPayment } from "../core/api-client.js";
|
|
3
|
+
import { initiateCardSetup, formatCardSetupPrompt } from "../core/card-setup.js";
|
|
3
4
|
import { hasWalletConfigured, getConfiguredMethods, getAcceptedPaymentMethods, getWalletAddress, } from "../core/payments.js";
|
|
4
5
|
import { requiresSpendConfirmation, getDefaultTipAmount } from "../core/config.js";
|
|
5
6
|
import { agentList, formatRunResult } from "../core/formatters.js";
|
|
@@ -93,9 +94,15 @@ export function registerSolveTools(server) {
|
|
|
93
94
|
.describe("Set to true to confirm spending after seeing the price quote."),
|
|
94
95
|
}, async ({ intent, input, budget, pay_with, confirmed }) => {
|
|
95
96
|
if (!hasWalletConfigured()) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
try {
|
|
98
|
+
const { qr, url } = await initiateCardSetup();
|
|
99
|
+
return text(formatCardSetupPrompt(qr, url));
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return text("No payment method configured.\n\n" +
|
|
103
|
+
"To add a credit card: wallet_setup({ action: \"add-card\" })\n" +
|
|
104
|
+
"To use crypto: wallet_setup({ action: \"create\" })");
|
|
105
|
+
}
|
|
99
106
|
}
|
|
100
107
|
const method = pay_with ?? getConfiguredMethods()[0];
|
|
101
108
|
// Path 1: If authenticated, use the platform /solve route
|
package/dist/tools/wallet.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import
|
|
3
|
-
import { getWallets, getCardConfig, setCardConfig, addWallet } from "../core/config.js";
|
|
4
|
-
import { getApiUrl } from "../core/config.js";
|
|
2
|
+
import { getWallets, getCardConfig, addWallet } from "../core/config.js";
|
|
5
3
|
import { getWalletAddress } from "../core/payments.js";
|
|
6
|
-
import {
|
|
4
|
+
import { initiateCardSetup, pollCardSetup } from "../core/card-setup.js";
|
|
7
5
|
import { isOwsAvailable, createOwsWallet, importKeyToOws, listOwsWallets, } from "../core/ows-adapter.js";
|
|
8
6
|
function text(t) {
|
|
9
7
|
return { content: [{ type: "text", text: t }] };
|
|
@@ -52,64 +50,31 @@ export function registerWalletTools(server) {
|
|
|
52
50
|
if (existing) {
|
|
53
51
|
return text(`Card already connected: ${existing.brand} ****${existing.last4}\n\nTo replace it, remove the current card first.`);
|
|
54
52
|
}
|
|
55
|
-
// Check if there's a pending setup to complete
|
|
53
|
+
// Check if there's a pending setup to complete (user said they're done)
|
|
56
54
|
if (pendingCardSetup) {
|
|
57
55
|
const pendingToken = pendingCardSetup.token;
|
|
58
|
-
|
|
59
|
-
const deadline = Date.now() + 120_000;
|
|
60
|
-
while (Date.now() < deadline) {
|
|
61
|
-
await new Promise((r) => setTimeout(r, 3000));
|
|
62
|
-
try {
|
|
63
|
-
const status = await apiGet(`/card/status?token=${pendingToken}`);
|
|
64
|
-
if (status.status === "complete" && status.consumer_token) {
|
|
65
|
-
setCardConfig({
|
|
66
|
-
consumerToken: status.consumer_token,
|
|
67
|
-
last4: status.card_last4 ?? "????",
|
|
68
|
-
brand: status.card_brand ?? "card",
|
|
69
|
-
});
|
|
70
|
-
pendingCardSetup = null;
|
|
71
|
-
return text(`Connected! ${status.card_brand ?? "Card"} ****${status.card_last4} is ready for payments.`);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
// Keep polling
|
|
76
|
-
}
|
|
77
|
-
}
|
|
56
|
+
const result = await pollCardSetup(pendingToken);
|
|
78
57
|
pendingCardSetup = null;
|
|
58
|
+
if (result) {
|
|
59
|
+
return text(`Connected! ${result.brand} ****${result.last4} is ready for payments.`);
|
|
60
|
+
}
|
|
79
61
|
return text("Card setup timed out. Run wallet_setup({ action: \"add-card\" }) to try again.");
|
|
80
62
|
}
|
|
81
|
-
// Create new card setup session
|
|
82
|
-
let setupResult;
|
|
63
|
+
// Create new card setup session with QR code
|
|
83
64
|
try {
|
|
84
|
-
|
|
65
|
+
const { qr, url, token } = await initiateCardSetup();
|
|
66
|
+
pendingCardSetup = { token };
|
|
67
|
+
return text([
|
|
68
|
+
"Scan to connect a payment card:\n",
|
|
69
|
+
qr,
|
|
70
|
+
`Or open: ${url}`,
|
|
71
|
+
"",
|
|
72
|
+
"After entering your card, tell me and I'll confirm the connection.",
|
|
73
|
+
].join("\n"));
|
|
85
74
|
}
|
|
86
75
|
catch {
|
|
87
76
|
return text("Error: Could not create card setup session. Try again later.");
|
|
88
77
|
}
|
|
89
|
-
// Store for the follow-up poll call
|
|
90
|
-
pendingCardSetup = { token: setupResult.token };
|
|
91
|
-
// Build a short link URL for a compact QR code
|
|
92
|
-
const apiUrl = getApiUrl();
|
|
93
|
-
const shortUrl = `${apiUrl}/card/link/${setupResult.token}`;
|
|
94
|
-
// Generate QR code
|
|
95
|
-
let qr;
|
|
96
|
-
try {
|
|
97
|
-
qr = await QRCode.toString(shortUrl, {
|
|
98
|
-
type: "utf8",
|
|
99
|
-
errorCorrectionLevel: "L",
|
|
100
|
-
margin: 2,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
qr = "";
|
|
105
|
-
}
|
|
106
|
-
return text([
|
|
107
|
-
"Scan to connect a payment card:\n",
|
|
108
|
-
qr,
|
|
109
|
-
`Or open: ${shortUrl}`,
|
|
110
|
-
"",
|
|
111
|
-
"After entering your card, tell me and I'll confirm the connection.",
|
|
112
|
-
].join("\n"));
|
|
113
78
|
}
|
|
114
79
|
// ── Crypto wallet setup ──────────────────────────────────
|
|
115
80
|
if (action === "import" && !key) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import QRCode from "qrcode";
|
|
2
|
+
import { apiPost, apiGet } from "./api-client.js";
|
|
3
|
+
import { getApiUrl, getCardConfig, setCardConfig } from "./config.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initiate card setup — creates a Stripe Checkout session and returns
|
|
7
|
+
* QR code + short URL for the user to scan.
|
|
8
|
+
*/
|
|
9
|
+
export async function initiateCardSetup(): Promise<{
|
|
10
|
+
qr: string;
|
|
11
|
+
url: string;
|
|
12
|
+
token: string;
|
|
13
|
+
}> {
|
|
14
|
+
const { url: _checkoutUrl, token } = await apiPost<{ url: string; token: string }>("/card/setup", {});
|
|
15
|
+
|
|
16
|
+
// Short redirect URL keeps the QR code small and scannable
|
|
17
|
+
const apiUrl = getApiUrl();
|
|
18
|
+
const shortUrl = `${apiUrl}/card/link/${token}`;
|
|
19
|
+
|
|
20
|
+
const qr = await QRCode.toString(shortUrl, {
|
|
21
|
+
type: "utf8",
|
|
22
|
+
errorCorrectionLevel: "L",
|
|
23
|
+
margin: 2,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return { qr, url: shortUrl, token };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Format the card setup prompt shown to the user.
|
|
31
|
+
*/
|
|
32
|
+
export function formatCardSetupPrompt(qr: string, url: string): string {
|
|
33
|
+
return [
|
|
34
|
+
"Connect a payment card to get started:\n",
|
|
35
|
+
qr,
|
|
36
|
+
`Or open: ${url}`,
|
|
37
|
+
"",
|
|
38
|
+
"We also support crypto wallets (Base USDC, Tempo USDC) — use wallet_setup({ action: \"create\" }) if you prefer.",
|
|
39
|
+
"",
|
|
40
|
+
"IMPORTANT: Present the QR code and link above to the user. After they enter their card, call wallet_setup({ action: \"add-card\" }) to confirm the connection.",
|
|
41
|
+
].join("\n");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Poll for card setup completion. Returns the card details or null on timeout.
|
|
46
|
+
*/
|
|
47
|
+
export async function pollCardSetup(
|
|
48
|
+
token: string,
|
|
49
|
+
timeoutMs = 120_000,
|
|
50
|
+
): Promise<{ last4: string; brand: string; consumerToken: string } | null> {
|
|
51
|
+
const deadline = Date.now() + timeoutMs;
|
|
52
|
+
|
|
53
|
+
while (Date.now() < deadline) {
|
|
54
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
55
|
+
try {
|
|
56
|
+
const status = await apiGet<{
|
|
57
|
+
status: string;
|
|
58
|
+
card_last4?: string;
|
|
59
|
+
card_brand?: string;
|
|
60
|
+
consumer_token?: string;
|
|
61
|
+
}>(`/card/status?token=${token}`);
|
|
62
|
+
|
|
63
|
+
if (status.status === "complete" && status.consumer_token) {
|
|
64
|
+
const card = {
|
|
65
|
+
last4: status.card_last4 ?? "????",
|
|
66
|
+
brand: status.card_brand ?? "card",
|
|
67
|
+
consumerToken: status.consumer_token,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Persist to config
|
|
71
|
+
setCardConfig({
|
|
72
|
+
consumerToken: card.consumerToken,
|
|
73
|
+
last4: card.last4,
|
|
74
|
+
brand: card.brand,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return card;
|
|
78
|
+
}
|
|
79
|
+
} catch {
|
|
80
|
+
// Keep polling
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -37,17 +37,17 @@ export async function startMcpServer(): Promise<void> {
|
|
|
37
37
|
"The MCP auto-uploads to cloud storage and replaces with a URL. Never base64-encode.",
|
|
38
38
|
"",
|
|
39
39
|
"WORKFLOW:",
|
|
40
|
-
"1.
|
|
41
|
-
"2.
|
|
42
|
-
"3.
|
|
43
|
-
"4. run_agent
|
|
40
|
+
"1. search_agents() or solve() — find agents for the task",
|
|
41
|
+
"2. get_agent() — check required input fields before running",
|
|
42
|
+
"3. run_agent() or solve() with ALL required fields",
|
|
43
|
+
"4. If no payment method is set up, run_agent returns a QR code to connect a credit card — present it to the user",
|
|
44
44
|
"5. Ask user to rate or tip after a successful run",
|
|
45
45
|
"",
|
|
46
46
|
"PAYMENT:",
|
|
47
|
-
"-
|
|
48
|
-
"-
|
|
49
|
-
"-
|
|
50
|
-
"-
|
|
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.",
|
|
49
|
+
"- 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.",
|
|
51
51
|
"",
|
|
52
52
|
"REQUIRED FIELDS:",
|
|
53
53
|
"Always check the agent's input schema (via get_agent) before calling run_agent.",
|
package/src/tools/run.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { getConfiguredMethods, hasWalletConfigured, getWalletAddress } from "../
|
|
|
6
6
|
import { requiresSpendConfirmation, getDefaultTipAmount } from "../core/config.js";
|
|
7
7
|
import { formatRunResult } from "../core/formatters.js";
|
|
8
8
|
import { storeFeedbackToken, getFeedbackToken } from "./_token-cache.js";
|
|
9
|
+
import { initiateCardSetup, formatCardSetupPrompt } from "../core/card-setup.js";
|
|
9
10
|
|
|
10
11
|
const POLL_INTERVAL_MS = 3000;
|
|
11
12
|
const POLL_MAX_MS = 120000; // 2 minutes
|
|
@@ -69,11 +70,16 @@ export function registerRunTools(server: McpServer): void {
|
|
|
69
70
|
},
|
|
70
71
|
async ({ agent_id, input, pay_with, confirmed }) => {
|
|
71
72
|
if (!hasWalletConfigured()) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
73
|
+
try {
|
|
74
|
+
const { qr, url } = await initiateCardSetup();
|
|
75
|
+
return text(formatCardSetupPrompt(qr, url));
|
|
76
|
+
} catch {
|
|
77
|
+
return text(
|
|
78
|
+
"No payment method configured.\n\n" +
|
|
79
|
+
"To add a credit card: wallet_setup({ action: \"add-card\" })\n" +
|
|
80
|
+
"To use crypto: wallet_setup({ action: \"create\" })"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
// Resolve agent and fetch details
|
package/src/tools/solve.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { apiGet, apiPost, apiPostWithPayment } from "../core/api-client.js";
|
|
4
|
+
import { initiateCardSetup, formatCardSetupPrompt } from "../core/card-setup.js";
|
|
4
5
|
import {
|
|
5
6
|
hasWalletConfigured,
|
|
6
7
|
getConfiguredMethods,
|
|
@@ -119,11 +120,16 @@ export function registerSolveTools(server: McpServer): void {
|
|
|
119
120
|
},
|
|
120
121
|
async ({ intent, input, budget, pay_with, confirmed }) => {
|
|
121
122
|
if (!hasWalletConfigured()) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
try {
|
|
124
|
+
const { qr, url } = await initiateCardSetup();
|
|
125
|
+
return text(formatCardSetupPrompt(qr, url));
|
|
126
|
+
} catch {
|
|
127
|
+
return text(
|
|
128
|
+
"No payment method configured.\n\n" +
|
|
129
|
+
"To add a credit card: wallet_setup({ action: \"add-card\" })\n" +
|
|
130
|
+
"To use crypto: wallet_setup({ action: \"create\" })"
|
|
131
|
+
);
|
|
132
|
+
}
|
|
127
133
|
}
|
|
128
134
|
|
|
129
135
|
const method = pay_with ?? getConfiguredMethods()[0];
|
package/src/tools/wallet.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import QRCode from "qrcode";
|
|
4
3
|
import { getWallets, getCardConfig, setCardConfig, addWallet } from "../core/config.js";
|
|
5
|
-
import { getApiUrl } from "../core/config.js";
|
|
6
4
|
import { getWalletAddress } from "../core/payments.js";
|
|
7
|
-
import {
|
|
5
|
+
import { initiateCardSetup, pollCardSetup } from "../core/card-setup.js";
|
|
8
6
|
import {
|
|
9
7
|
isOwsAvailable,
|
|
10
8
|
createOwsWallet,
|
|
@@ -84,72 +82,33 @@ export function registerWalletTools(server: McpServer): void {
|
|
|
84
82
|
return text(`Card already connected: ${existing.brand} ****${existing.last4}\n\nTo replace it, remove the current card first.`);
|
|
85
83
|
}
|
|
86
84
|
|
|
87
|
-
// Check if there's a pending setup to complete
|
|
85
|
+
// Check if there's a pending setup to complete (user said they're done)
|
|
88
86
|
if (pendingCardSetup) {
|
|
89
87
|
const pendingToken = pendingCardSetup.token;
|
|
90
|
-
|
|
91
|
-
const deadline = Date.now() + 120_000;
|
|
92
|
-
while (Date.now() < deadline) {
|
|
93
|
-
await new Promise((r) => setTimeout(r, 3000));
|
|
94
|
-
try {
|
|
95
|
-
const status = await apiGet<{
|
|
96
|
-
status: string;
|
|
97
|
-
card_last4?: string;
|
|
98
|
-
card_brand?: string;
|
|
99
|
-
consumer_token?: string;
|
|
100
|
-
}>(`/card/status?token=${pendingToken}`);
|
|
101
|
-
|
|
102
|
-
if (status.status === "complete" && status.consumer_token) {
|
|
103
|
-
setCardConfig({
|
|
104
|
-
consumerToken: status.consumer_token,
|
|
105
|
-
last4: status.card_last4 ?? "????",
|
|
106
|
-
brand: status.card_brand ?? "card",
|
|
107
|
-
});
|
|
108
|
-
pendingCardSetup = null;
|
|
109
|
-
return text(`Connected! ${status.card_brand ?? "Card"} ****${status.card_last4} is ready for payments.`);
|
|
110
|
-
}
|
|
111
|
-
} catch {
|
|
112
|
-
// Keep polling
|
|
113
|
-
}
|
|
114
|
-
}
|
|
88
|
+
const result = await pollCardSetup(pendingToken);
|
|
115
89
|
pendingCardSetup = null;
|
|
90
|
+
|
|
91
|
+
if (result) {
|
|
92
|
+
return text(`Connected! ${result.brand} ****${result.last4} is ready for payments.`);
|
|
93
|
+
}
|
|
116
94
|
return text("Card setup timed out. Run wallet_setup({ action: \"add-card\" }) to try again.");
|
|
117
95
|
}
|
|
118
96
|
|
|
119
|
-
// Create new card setup session
|
|
120
|
-
let setupResult: { url: string; token: string };
|
|
97
|
+
// Create new card setup session with QR code
|
|
121
98
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return text("Error: Could not create card setup session. Try again later.");
|
|
125
|
-
}
|
|
99
|
+
const { qr, url, token } = await initiateCardSetup();
|
|
100
|
+
pendingCardSetup = { token };
|
|
126
101
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
// Generate QR code
|
|
135
|
-
let qr: string;
|
|
136
|
-
try {
|
|
137
|
-
qr = await QRCode.toString(shortUrl, {
|
|
138
|
-
type: "utf8",
|
|
139
|
-
errorCorrectionLevel: "L",
|
|
140
|
-
margin: 2,
|
|
141
|
-
});
|
|
102
|
+
return text([
|
|
103
|
+
"Scan to connect a payment card:\n",
|
|
104
|
+
qr,
|
|
105
|
+
`Or open: ${url}`,
|
|
106
|
+
"",
|
|
107
|
+
"After entering your card, tell me and I'll confirm the connection.",
|
|
108
|
+
].join("\n"));
|
|
142
109
|
} catch {
|
|
143
|
-
|
|
110
|
+
return text("Error: Could not create card setup session. Try again later.");
|
|
144
111
|
}
|
|
145
|
-
|
|
146
|
-
return text([
|
|
147
|
-
"Scan to connect a payment card:\n",
|
|
148
|
-
qr,
|
|
149
|
-
`Or open: ${shortUrl}`,
|
|
150
|
-
"",
|
|
151
|
-
"After entering your card, tell me and I'll confirm the connection.",
|
|
152
|
-
].join("\n"));
|
|
153
112
|
}
|
|
154
113
|
|
|
155
114
|
// ── Crypto wallet setup ──────────────────────────────────
|