@agentwonderland/mcp 0.1.22 → 0.1.24
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/__tests__/card-setup.test.d.ts +1 -0
- package/dist/core/__tests__/card-setup.test.js +99 -0
- package/dist/core/__tests__/formatters.test.d.ts +1 -0
- package/dist/core/__tests__/formatters.test.js +15 -0
- package/dist/core/__tests__/passes.test.d.ts +1 -0
- package/dist/core/__tests__/passes.test.js +82 -0
- package/dist/core/__tests__/payments.test.d.ts +1 -0
- package/dist/core/__tests__/payments.test.js +52 -0
- package/dist/core/__tests__/principal.test.d.ts +1 -0
- package/dist/core/__tests__/principal.test.js +67 -0
- package/dist/core/api-client.d.ts +9 -4
- package/dist/core/api-client.js +52 -22
- package/dist/core/card-setup.d.ts +20 -13
- package/dist/core/card-setup.js +87 -30
- package/dist/core/config.d.ts +4 -0
- package/dist/core/config.js +28 -1
- package/dist/core/formatters.d.ts +2 -0
- package/dist/core/formatters.js +5 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.js +2 -0
- package/dist/core/ows-adapter.d.ts +10 -2
- package/dist/core/ows-adapter.js +54 -10
- package/dist/core/passes.d.ts +40 -0
- package/dist/core/passes.js +32 -0
- package/dist/core/payments.d.ts +8 -0
- package/dist/core/payments.js +121 -16
- package/dist/core/principal.d.ts +2 -0
- package/dist/core/principal.js +109 -0
- package/dist/core/solana-charge.d.ts +9 -0
- package/dist/core/solana-charge.js +95 -0
- package/dist/core/types.d.ts +10 -0
- package/dist/index.js +13 -4
- package/dist/prompts/index.js +1 -1
- package/dist/resources/wallet.js +8 -1
- package/dist/tools/__tests__/_payment-confirmation.test.d.ts +1 -0
- package/dist/tools/__tests__/_payment-confirmation.test.js +30 -0
- package/dist/tools/_payment-confirmation.d.ts +6 -0
- package/dist/tools/_payment-confirmation.js +28 -0
- package/dist/tools/agent-info.js +14 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/passes.d.ts +2 -0
- package/dist/tools/passes.js +157 -0
- package/dist/tools/run.js +116 -49
- package/dist/tools/solve.js +102 -44
- package/dist/tools/wallet.js +85 -50
- package/package.json +3 -1
- package/src/core/__tests__/card-setup.test.ts +118 -0
- package/src/core/__tests__/formatters.test.ts +17 -0
- package/src/core/__tests__/passes.test.ts +94 -0
- package/src/core/__tests__/payments.test.ts +60 -0
- package/src/core/__tests__/principal.test.ts +87 -0
- package/src/core/api-client.ts +70 -23
- package/src/core/card-setup.ts +112 -35
- package/src/core/config.ts +33 -2
- package/src/core/formatters.ts +7 -1
- package/src/core/index.ts +2 -0
- package/src/core/ows-adapter.ts +74 -8
- package/src/core/passes.ts +74 -0
- package/src/core/payments.ts +140 -15
- package/src/core/principal.ts +128 -0
- package/src/core/solana-charge.ts +149 -0
- package/src/core/types.ts +10 -0
- package/src/index.ts +13 -4
- package/src/prompts/index.ts +1 -1
- package/src/resources/wallet.ts +8 -1
- package/src/tools/__tests__/_payment-confirmation.test.ts +45 -0
- package/src/tools/_payment-confirmation.ts +52 -0
- package/src/tools/agent-info.ts +23 -0
- package/src/tools/index.ts +1 -0
- package/src/tools/passes.ts +234 -0
- package/src/tools/run.ts +174 -53
- package/src/tools/solve.ts +149 -56
- package/src/tools/wallet.ts +102 -52
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export function resolveConfirmationMethod(
|
|
2
|
+
requestedMethod: string | undefined,
|
|
3
|
+
pendingMethod: string | undefined,
|
|
4
|
+
compatibleMethods: string[],
|
|
5
|
+
): string | undefined {
|
|
6
|
+
return requestedMethod ?? pendingMethod ?? compatibleMethods[0];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function formatPaymentLabel(method: string | undefined): string {
|
|
10
|
+
return method ?? "auto";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function formatRunConfirmationCommand(
|
|
14
|
+
agentId: string,
|
|
15
|
+
method: string | undefined,
|
|
16
|
+
): string {
|
|
17
|
+
const payWith = method ? `, pay_with: "${method}"` : "";
|
|
18
|
+
return ` run_agent({ agent_id: "${agentId}", input: <same>${payWith}, confirmed: true })`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function formatSolveConfirmationCommand(
|
|
22
|
+
intent: string,
|
|
23
|
+
budget: number,
|
|
24
|
+
method: string | undefined,
|
|
25
|
+
): string {
|
|
26
|
+
const payWith = method ? `, pay_with: "${method}"` : "";
|
|
27
|
+
return ` solve({ intent: "${intent}", input: <same>, budget: ${budget}${payWith}, confirmed: true })`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function makeSolvePendingKey(
|
|
31
|
+
intent: string,
|
|
32
|
+
input: Record<string, unknown>,
|
|
33
|
+
budget: number,
|
|
34
|
+
): string {
|
|
35
|
+
return JSON.stringify({ intent, input, budget });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function formatPaymentChoicePrompt(
|
|
39
|
+
subject: string,
|
|
40
|
+
methods: string[],
|
|
41
|
+
commands: string[],
|
|
42
|
+
): string {
|
|
43
|
+
return [
|
|
44
|
+
`Multiple payment methods are available for ${subject}.`,
|
|
45
|
+
"",
|
|
46
|
+
"Ask the user which payment method they want to use, then call one of:",
|
|
47
|
+
...commands,
|
|
48
|
+
"",
|
|
49
|
+
`Available methods: ${methods.map((method) => `"${method}"`).join(", ")}`,
|
|
50
|
+
"For fully agentic execution, include pay_with explicitly.",
|
|
51
|
+
].join("\n");
|
|
52
|
+
}
|
package/src/tools/agent-info.ts
CHANGED
|
@@ -21,6 +21,15 @@ export function registerAgentInfoTools(server: McpServer): void {
|
|
|
21
21
|
const s = (a.stats ?? {}) as Record<string, unknown>;
|
|
22
22
|
const payment = (a.payment ?? {}) as Record<string, unknown>;
|
|
23
23
|
const _pricing = (payment.pricing ?? {}) as Record<string, unknown>;
|
|
24
|
+
const creditPacks = payment.credit_packs as {
|
|
25
|
+
unit_type?: string;
|
|
26
|
+
packs?: Array<{
|
|
27
|
+
key?: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
included_units?: number;
|
|
30
|
+
price_usd?: string;
|
|
31
|
+
}>;
|
|
32
|
+
} | null | undefined;
|
|
24
33
|
|
|
25
34
|
const lines = [
|
|
26
35
|
`${a.name}`,
|
|
@@ -41,6 +50,20 @@ export function registerAgentInfoTools(server: McpServer): void {
|
|
|
41
50
|
const hint = outputTypeHint(a.tags as string[]);
|
|
42
51
|
return hint ? [`Output: ${hint}`] : [];
|
|
43
52
|
})(),
|
|
53
|
+
...(() => {
|
|
54
|
+
if (!creditPacks?.packs?.length) return [];
|
|
55
|
+
const packLines = [
|
|
56
|
+
"",
|
|
57
|
+
`Discounted credit packs: ${creditPacks.unit_type ?? "run"}s`,
|
|
58
|
+
];
|
|
59
|
+
for (const pack of creditPacks.packs) {
|
|
60
|
+
packLines.push(
|
|
61
|
+
` ${pack.name ?? pack.key}: ${pack.included_units ?? 0} units for $${pack.price_usd ?? "0.00"}`,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
packLines.push(" Use buy_agent_credit_pack to purchase one.");
|
|
65
|
+
return packLines;
|
|
66
|
+
})(),
|
|
44
67
|
];
|
|
45
68
|
|
|
46
69
|
// Feedback summary (rating + tips)
|
package/src/tools/index.ts
CHANGED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { apiGet, apiPostWithPayment } from "../core/api-client.js";
|
|
4
|
+
import {
|
|
5
|
+
formatCreditPack,
|
|
6
|
+
formatCreditPackOffer,
|
|
7
|
+
getCreditPackProgram,
|
|
8
|
+
} from "../core/passes.js";
|
|
9
|
+
import {
|
|
10
|
+
getCompatiblePaymentMethods,
|
|
11
|
+
getConfiguredMethods,
|
|
12
|
+
hasWalletConfigured,
|
|
13
|
+
normalizePaymentMethod,
|
|
14
|
+
} from "../core/payments.js";
|
|
15
|
+
import { requiresSpendConfirmation } from "../core/config.js";
|
|
16
|
+
import { ensureConsumerPrincipal } from "../core/principal.js";
|
|
17
|
+
import { getOrCreatePendingCardSetup, formatCardSetupBlocks } from "../core/card-setup.js";
|
|
18
|
+
import {
|
|
19
|
+
formatPaymentChoicePrompt,
|
|
20
|
+
formatPaymentLabel,
|
|
21
|
+
resolveConfirmationMethod,
|
|
22
|
+
} from "./_payment-confirmation.js";
|
|
23
|
+
import type { AgentRecord } from "../core/types.js";
|
|
24
|
+
import type { CreditPackInventory, CreditPackOffer, CreditPackRecord } from "../core/passes.js";
|
|
25
|
+
|
|
26
|
+
const pendingCreditPackPurchases = new Map<string, {
|
|
27
|
+
agentId: string;
|
|
28
|
+
agentName: string;
|
|
29
|
+
offer: CreditPackOffer;
|
|
30
|
+
method?: string;
|
|
31
|
+
}>();
|
|
32
|
+
|
|
33
|
+
function text(t: string) {
|
|
34
|
+
return { content: [{ type: "text" as const, text: t }] };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function multiText(...blocks: string[]) {
|
|
38
|
+
return { content: blocks.map((t) => ({ type: "text" as const, text: t })) };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function getAgent(agentId: string): Promise<AgentRecord> {
|
|
42
|
+
return apiGet<AgentRecord>(`/agents/${agentId}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function findOffer(agent: AgentRecord, packId: string): CreditPackOffer | null {
|
|
46
|
+
const program = getCreditPackProgram(agent);
|
|
47
|
+
const pack = program?.packs?.find((candidate) => candidate.key === packId);
|
|
48
|
+
if (!pack) return null;
|
|
49
|
+
|
|
50
|
+
const price = Number(pack.price_usd ?? "0");
|
|
51
|
+
const units = pack.included_units ?? 0;
|
|
52
|
+
return {
|
|
53
|
+
pack_id: packId,
|
|
54
|
+
label: pack.name ?? pack.key ?? "Credit Pack",
|
|
55
|
+
included_units: units,
|
|
56
|
+
price_usd: price.toFixed(2),
|
|
57
|
+
effective_price_per_unit_usd: units > 0 ? (price / units).toFixed(6) : undefined,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function registerPassTools(server: McpServer): void {
|
|
62
|
+
server.tool(
|
|
63
|
+
"buy_agent_credit_pack",
|
|
64
|
+
"Purchase a discounted prepaid credit pack for an agent. Credit packs are agent-specific and automatically cover future runs until the included units run out.",
|
|
65
|
+
{
|
|
66
|
+
agent_id: z.string().describe("Agent ID (UUID, slug, or name)"),
|
|
67
|
+
pack_id: z.string().optional().describe("Specific pack key to buy, like 'starter' or 'growth'. If omitted and only one pack exists, it is selected automatically."),
|
|
68
|
+
pay_with: z.string().optional().describe("Payment method — wallet ID, chain name, or 'card'. Auto-detected if omitted."),
|
|
69
|
+
confirmed: z.boolean().optional().describe("Set to true to confirm the purchase after seeing the quote."),
|
|
70
|
+
},
|
|
71
|
+
async ({ agent_id, pack_id, pay_with, confirmed }) => {
|
|
72
|
+
if (!hasWalletConfigured()) {
|
|
73
|
+
try {
|
|
74
|
+
const { url } = await getOrCreatePendingCardSetup();
|
|
75
|
+
return multiText(...formatCardSetupBlocks(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
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const agent = await getAgent(agent_id);
|
|
86
|
+
const agentName = agent.name ?? agent_id;
|
|
87
|
+
const principal = await ensureConsumerPrincipal();
|
|
88
|
+
const program = getCreditPackProgram(agent);
|
|
89
|
+
const offers = (program?.packs ?? [])
|
|
90
|
+
.map((pack) => findOffer(agent, pack.key ?? ""))
|
|
91
|
+
.filter((offer): offer is CreditPackOffer => !!offer);
|
|
92
|
+
|
|
93
|
+
if (offers.length === 0) {
|
|
94
|
+
return text(`${agentName} does not currently offer discounted credit packs.`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const configuredMethods = getConfiguredMethods();
|
|
98
|
+
const compatibleMethods = getCompatiblePaymentMethods(agent, configuredMethods);
|
|
99
|
+
const pending = pendingCreditPackPurchases.get(agent.id);
|
|
100
|
+
const requestedMethod = pay_with ?? pending?.method;
|
|
101
|
+
const normalizedRequestedMethod = requestedMethod ? normalizePaymentMethod(requestedMethod) : null;
|
|
102
|
+
|
|
103
|
+
if (requestedMethod && !normalizedRequestedMethod) {
|
|
104
|
+
return text(
|
|
105
|
+
`Payment method "${requestedMethod}" is not configured.\n\n` +
|
|
106
|
+
"Use wallet_status to review your current payment methods.",
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (normalizedRequestedMethod && !compatibleMethods.includes(normalizedRequestedMethod)) {
|
|
111
|
+
return text(
|
|
112
|
+
`This agent cannot be paid with "${requestedMethod}".\n\n` +
|
|
113
|
+
`Available payment methods for this agent: ${compatibleMethods.join(", ") || "none"}.`,
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!requestedMethod && compatibleMethods.length === 0) {
|
|
118
|
+
return text(
|
|
119
|
+
`No compatible payment methods are configured for ${agentName}.\n\n` +
|
|
120
|
+
`Your configured methods: ${configuredMethods.join(", ") || "none"}`,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!requestedMethod && compatibleMethods.length > 1) {
|
|
125
|
+
return text(
|
|
126
|
+
formatPaymentChoicePrompt(
|
|
127
|
+
`${agentName} credit-pack purchase`,
|
|
128
|
+
compatibleMethods,
|
|
129
|
+
compatibleMethods.map((method) => ` buy_agent_credit_pack({ agent_id: "${agent.id}"${pack_id ? `, pack_id: "${pack_id}"` : ""}, pay_with: "${method}" })`),
|
|
130
|
+
),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
let resolvedOffer: CreditPackOffer;
|
|
135
|
+
if (pack_id) {
|
|
136
|
+
const offer = offers.find((candidate) => candidate.pack_id === pack_id);
|
|
137
|
+
if (!offer) {
|
|
138
|
+
return text(
|
|
139
|
+
`Unknown credit pack "${pack_id}" for ${agentName}.\n\n` +
|
|
140
|
+
`Available packs:\n${offers.map((offer) => ` ${formatCreditPackOffer(offer)}`).join("\n")}`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
resolvedOffer = offer;
|
|
144
|
+
} else if (offers.length === 1) {
|
|
145
|
+
resolvedOffer = offers[0]!;
|
|
146
|
+
} else {
|
|
147
|
+
return text([
|
|
148
|
+
`Multiple credit packs are available for ${agentName}.`,
|
|
149
|
+
"",
|
|
150
|
+
...offers.map((offer) => ` ${offer.pack_id}: ${formatCreditPackOffer(offer)}`),
|
|
151
|
+
"",
|
|
152
|
+
"Choose one by calling:",
|
|
153
|
+
` buy_agent_credit_pack({ agent_id: "${agent.id}", pack_id: "${offers[0]!.pack_id}" })`,
|
|
154
|
+
].join("\n"));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const method = resolveConfirmationMethod(pay_with, pending?.method, compatibleMethods);
|
|
158
|
+
|
|
159
|
+
if (requiresSpendConfirmation() && !confirmed) {
|
|
160
|
+
pendingCreditPackPurchases.set(agent.id, {
|
|
161
|
+
agentId: agent.id,
|
|
162
|
+
agentName,
|
|
163
|
+
offer: resolvedOffer,
|
|
164
|
+
method,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return text([
|
|
168
|
+
`Ready to buy a credit pack for ${agentName}`,
|
|
169
|
+
"",
|
|
170
|
+
formatCreditPackOffer(resolvedOffer),
|
|
171
|
+
`Payment: ${formatPaymentLabel(method)}`,
|
|
172
|
+
`Consumer principal: ${principal}`,
|
|
173
|
+
"",
|
|
174
|
+
"To proceed, call:",
|
|
175
|
+
` buy_agent_credit_pack({ agent_id: "${agent.id}", pack_id: "${resolvedOffer.pack_id}", pay_with: "${method}", confirmed: true })`,
|
|
176
|
+
"",
|
|
177
|
+
"To cancel, do nothing.",
|
|
178
|
+
].join("\n"));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const result = await apiPostWithPayment<{
|
|
182
|
+
consumer_principal: string;
|
|
183
|
+
offer: CreditPackOffer;
|
|
184
|
+
credit_pack: CreditPackRecord;
|
|
185
|
+
}>(
|
|
186
|
+
`/agents/${agent.id}/credit-packs/purchase`,
|
|
187
|
+
{ pack_id: resolvedOffer.pack_id },
|
|
188
|
+
method,
|
|
189
|
+
{ ensureConsumerPrincipal: true },
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
pendingCreditPackPurchases.delete(agent.id);
|
|
193
|
+
|
|
194
|
+
return text([
|
|
195
|
+
`Credit pack purchased for ${agentName}`,
|
|
196
|
+
"",
|
|
197
|
+
formatCreditPackOffer(result.offer),
|
|
198
|
+
formatCreditPack(result.credit_pack),
|
|
199
|
+
`Consumer principal: ${result.consumer_principal}`,
|
|
200
|
+
"",
|
|
201
|
+
"Future runs through run_agent will automatically use this credit pack while units remain.",
|
|
202
|
+
].join("\n"));
|
|
203
|
+
},
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
server.tool(
|
|
207
|
+
"list_agent_credit_packs",
|
|
208
|
+
"Show discounted credit-pack offers for an agent plus any balances available under the current consumer principal.",
|
|
209
|
+
{
|
|
210
|
+
agent_id: z.string().describe("Agent ID (UUID, slug, or name)"),
|
|
211
|
+
},
|
|
212
|
+
async ({ agent_id }) => {
|
|
213
|
+
const agent = await getAgent(agent_id);
|
|
214
|
+
const result = await apiGet<CreditPackInventory>(`/agents/${agent.id}/credit-packs`, { ensureConsumerPrincipal: true });
|
|
215
|
+
|
|
216
|
+
const lines = [
|
|
217
|
+
`Credit packs for ${agent.name}`,
|
|
218
|
+
...(result.consumer_principal ? [`Consumer principal: ${result.consumer_principal}`] : []),
|
|
219
|
+
];
|
|
220
|
+
|
|
221
|
+
if (result.offers.length > 0) {
|
|
222
|
+
lines.push("", "Available packs:", ...result.offers.map((offer) => ` ${offer.pack_id}: ${formatCreditPackOffer(offer)}`));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (result.balances.length > 0) {
|
|
226
|
+
lines.push("", "Your balances:", ...result.balances.map((pack) => ` ${formatCreditPack(pack)}`));
|
|
227
|
+
} else {
|
|
228
|
+
lines.push("", "No purchased credit packs found for this agent.");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return text(lines.join("\n"));
|
|
232
|
+
},
|
|
233
|
+
);
|
|
234
|
+
}
|