earnrate 0.2.0 → 0.2.2
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/README.md +23 -20
- package/data/cards/amex-blue-business-plus.yaml +1 -0
- package/data/cards/amex-blue-cash-everyday.yaml +4 -3
- package/data/cards/amex-blue-cash-preferred.yaml +5 -7
- package/data/cards/amex-gold.yaml +1 -0
- package/data/cards/amex-platinum.yaml +1 -0
- package/data/cards/bank-of-america-atmos-rewards-ascent.yaml +6 -6
- package/data/cards/bank-of-america-atmos-rewards-summit.yaml +6 -6
- package/data/cards/chase-freedom-flex.yaml +5 -1
- package/data/cards/chase-southwest-plus.yaml +5 -5
- package/data/cards/chase-southwest-premier-business.yaml +8 -5
- package/data/cards/chase-southwest-premier.yaml +6 -6
- package/data/cards/chase-southwest-priority.yaml +6 -6
- package/data/cards/citi-aadvantage-business.yaml +6 -6
- package/data/cards/citi-aadvantage-platinum-select.yaml +10 -7
- package/data/cards/citi-costco-anywhere-visa-business.yaml +4 -4
- package/dist/brand.js +2 -3
- package/dist/cli/args.js +64 -51
- package/dist/cli/cheatsheet.js +9 -12
- package/dist/cli/explore.js +28 -27
- package/dist/cli/import.js +3 -8
- package/dist/cli/offers.js +7 -6
- package/dist/cli/run.js +17 -13
- package/dist/cli/wallet.js +7 -6
- package/dist/data/file-store.js +54 -15
- package/dist/data/load.js +1 -1
- package/dist/data/store.js +0 -16
- package/dist/data/wallet-edit.js +78 -3
- package/dist/engine/bonus.js +15 -12
- package/dist/engine/cheat-sheet.js +2 -2
- package/dist/engine/evaluate.js +56 -13
- package/dist/engine/explore.js +9 -22
- package/dist/engine/offers.js +10 -22
- package/dist/engine/periods.js +9 -0
- package/dist/engine/recommend.js +14 -53
- package/dist/engine/record.js +2 -7
- package/dist/engine/setup.js +2 -2
- package/dist/engine/simulate.js +12 -19
- package/dist/engine/text.js +53 -0
- package/dist/engine/transient.js +5 -0
- package/dist/engine/valuation.js +1 -1
- package/dist/engine/wallet-change.js +46 -19
- package/dist/engine/wallet-summary.js +4 -8
- package/dist/format/card-text.js +79 -0
- package/dist/format/cheat-sheet.js +1 -1
- package/dist/format/explore.js +3 -13
- package/dist/format/offers.js +15 -18
- package/dist/{cli/format.js → format/recommendation.js} +2 -6
- package/dist/format/wallet.js +57 -0
- package/dist/import/analyze.js +17 -19
- package/dist/mcp/context.js +92 -0
- package/dist/mcp/inputs.js +155 -0
- package/dist/mcp/schemas.js +2 -1
- package/dist/mcp/server.js +15 -819
- package/dist/mcp/tools/account.js +78 -0
- package/dist/mcp/tools/answers.js +338 -0
- package/dist/mcp/tools/wallet.js +128 -0
- package/dist/merchants/from-env.js +1 -1
- package/dist/merchants/resolve.js +3 -3
- package/dist/schema/card.js +4 -0
- package/package.json +3 -2
- package/dist/data/wallet-setup.js +0 -60
- package/dist/data/wallet-write.js +0 -140
- /package/dist/{cli → format}/cards.js +0 -0
package/dist/mcp/server.js
CHANGED
|
@@ -1,25 +1,10 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
import { MCP_SERVER_NAME } from "../brand.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { parseWalletYaml, walletYaml } from "../format/wallet-yaml.js";
|
|
10
|
-
import { walletProblems } from "../data/integrity.js";
|
|
11
|
-
import { catalogCheatSheet, cheatSheet } from "../engine/cheat-sheet.js";
|
|
12
|
-
import { ALL_PERSONAL_CARDS, exploreCards } from "../engine/explore.js";
|
|
13
|
-
import { walletFromCards } from "../engine/transient.js";
|
|
14
|
-
import { compareOffers } from "../engine/offers.js";
|
|
15
|
-
import { VALUATION_PROFILES } from "../engine/profiles.js";
|
|
16
|
-
import { recommend } from "../engine/recommend.js";
|
|
17
|
-
import { resolveSpendLines, simulateAdditions, simulateCatalog, TYPICAL_SPEND_NOTE, typicalSpendLines, } from "../engine/simulate.js";
|
|
18
|
-
import { knownMemberships, searchCards } from "../engine/setup.js";
|
|
19
|
-
import { walletSummary } from "../engine/wallet-summary.js";
|
|
20
|
-
import { resolveMerchant, withCallerCategory } from "../merchants/resolve.js";
|
|
21
|
-
import { IsoDate } from "../schema/common.js";
|
|
22
|
-
import { CardSearchSchema, CheatSheetSchema, ExplorationSchema, MerchantResolutionSchema, PurchaseAnswerSchema, SpendingSimulationSchema, OfferComparisonSchema, RecordResultSchema, WalletChangeSchema, WalletSummarySchema, } from "./schemas.js";
|
|
3
|
+
import { makeContext } from "./context.js";
|
|
4
|
+
import { makeInputs } from "./inputs.js";
|
|
5
|
+
import { registerAccountTools } from "./tools/account.js";
|
|
6
|
+
import { registerAnswerTools } from "./tools/answers.js";
|
|
7
|
+
import { registerWalletTools } from "./tools/wallet.js";
|
|
23
8
|
// The tools that answer without a saved wallet.
|
|
24
9
|
export const ANSWER_TOOLS = [
|
|
25
10
|
'best_card_for_purchase',
|
|
@@ -30,7 +15,7 @@ export const ANSWER_TOOLS = [
|
|
|
30
15
|
'resolve_merchant',
|
|
31
16
|
'search_cards',
|
|
32
17
|
];
|
|
33
|
-
// The tools that read or change a saved wallet. The
|
|
18
|
+
// The tools that read or change a saved wallet. The hosted server asks for
|
|
34
19
|
// sign-in before running one.
|
|
35
20
|
export const SAVED_WALLET_TOOLS = [
|
|
36
21
|
'list_wallet',
|
|
@@ -43,811 +28,22 @@ export const SAVED_WALLET_TOOLS = [
|
|
|
43
28
|
'import_wallet',
|
|
44
29
|
'delete_wallet',
|
|
45
30
|
];
|
|
46
|
-
const Merchant = z
|
|
47
|
-
.string()
|
|
48
|
-
.min(1)
|
|
49
|
-
.describe('Merchant name or web address as the user would say it or see it, e.g. "Whole Foods" or "delta.com".');
|
|
50
|
-
const ChannelInput = z
|
|
51
|
-
.enum(['online', 'in_store'])
|
|
52
|
-
.optional()
|
|
53
|
-
.describe('How the purchase is made. Omit if unknown; the answer says what it assumed.');
|
|
54
|
-
const DateInput = IsoDate.optional().describe('Purchase date, YYYY-MM-DD. Defaults to today.');
|
|
55
31
|
const SAVING = {
|
|
56
|
-
none: "This server doesn't save wallets: pass the cards each time. For a saved wallet with cap and welcome-bonus tracking, the user can install earnrate locally (earnrate.dev).",
|
|
57
32
|
file: 'Only if they want earnrate to remember their cards, track spending caps or welcome bonuses, or record purchases, save a wallet with add_card and the other wallet tools.',
|
|
58
33
|
account: "Only if they want earnrate to remember their cards, track spending caps or welcome bonuses, or record purchases, save a wallet with add_card and the other wallet tools. Saved wallets are anonymous: the first wallet tool asks the user to open an earnrate page, where they start a wallet (it shows a recovery code to keep; no email or name) or reconnect one with their code. Never ask for the recovery code in the conversation; it's typed only on that page. To change the code, the user opens https://mcp.earnrate.dev/change-code.",
|
|
59
34
|
};
|
|
60
|
-
const
|
|
35
|
+
const instructions = (savedWallets) => `earnrate answers which credit card earns the most for a purchase, from each issuer's own terms. Anyone can use it without entering anything: with no cards given, best_card_for_purchase, best_cards_for, cheat_sheet, simulate_spending and compare_welcome_offers answer from every card earnrate knows, and that's a complete answer. Never require the user's cards, and don't ask what they spend unless the answer depends on it; simulate_spending assumes typical amounts when none are given and says so.
|
|
61
36
|
|
|
62
|
-
Personalizing is optional. If the user names their cards, pass them as \`cards\` (ids from search_cards) for that answer; nothing is saved. ${SAVING[savedWallets]} When a card needs category picks, memberships like Amazon Prime, or activations, ask the user rather than guessing.
|
|
37
|
+
Personalizing is optional. If the user names their cards, pass them as \`cards\` (ids from search_cards) for that answer; nothing is saved. After answering, offer once to save those cards so earnrate remembers them, and save them with add_card only if the user says yes. ${SAVING[savedWallets]} When a card needs category picks, memberships like Amazon Prime, or activations, ask the user rather than guessing.
|
|
63
38
|
|
|
64
39
|
The wallet lists cards by product id, never card numbers; never ask for card numbers, expiry dates or security codes.`;
|
|
65
|
-
const fail = (text) => ({
|
|
66
|
-
content: [{ type: 'text', text }],
|
|
67
|
-
isError: true,
|
|
68
|
-
});
|
|
69
|
-
const dollars = (n) => `$${n.toLocaleString('en-US', { maximumFractionDigits: 2 })}`;
|
|
70
40
|
export function createEarnrateServer(deps) {
|
|
71
|
-
const server = new McpServer({ name: MCP_SERVER_NAME, version: deps.version }, { instructions:
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
let loaded;
|
|
79
|
-
try {
|
|
80
|
-
const found = await deps.store.load();
|
|
81
|
-
if (found === null)
|
|
82
|
-
return noWallet;
|
|
83
|
-
loaded = found;
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
return `Couldn't read the wallet at ${deps.store.where}: ${e instanceof Error ? e.message : String(e)}`;
|
|
87
|
-
}
|
|
88
|
-
const problems = walletProblems(loaded, catalog);
|
|
89
|
-
return problems.length > 0
|
|
90
|
-
? `The wallet at ${deps.store.where} has problems:\n${problems.map((p) => `- ${p}`).join('\n')}`
|
|
91
|
-
: loaded;
|
|
92
|
-
}
|
|
93
|
-
// No wallet yet is the first-run state, not a failure: read-only tools
|
|
94
|
-
// answer from an empty wallet and say how to start one.
|
|
95
|
-
async function readableWallet() {
|
|
96
|
-
const w = await wallet();
|
|
97
|
-
if (typeof w !== 'string')
|
|
98
|
-
return { wallet: w, start: null };
|
|
99
|
-
return w === noWallet
|
|
100
|
-
? { wallet: { valuations: {}, memberships: [], cards: [] }, start: w }
|
|
101
|
-
: w;
|
|
102
|
-
}
|
|
103
|
-
// The caller's category is free and comes before the paid Claude fallback;
|
|
104
|
-
// neither ever overrides a merchant earnrate already knows.
|
|
105
|
-
async function resolve(merchant, channel, category) {
|
|
106
|
-
const known = resolveMerchant(catalog, merchant, channel);
|
|
107
|
-
if (known.source !== 'none' || category !== null || !deps.llm) {
|
|
108
|
-
return { merchant: withCallerCategory(known, category), notices: [] };
|
|
109
|
-
}
|
|
110
|
-
return deps.llm.resolve(catalog, merchant, channel);
|
|
111
|
-
}
|
|
112
|
-
const ids = catalog.categories.map((c) => c.id);
|
|
113
|
-
const CategoryInput = z
|
|
114
|
-
.enum(ids)
|
|
115
|
-
.optional()
|
|
116
|
-
.describe(`Only for a merchant earnrate may not know, and only if you're confident what kind of business it is: its spending category, e.g. grocery.supermarket for a supermarket, dining for a restaurant, gas for a gas station. Ignored when earnrate knows the merchant. Leave it out if unsure. Categories: ${catalog.categories.map((c) => `${c.id} (${c.name})`).join(', ')}.`);
|
|
117
|
-
const namedMembershipIds = knownMemberships(catalog);
|
|
118
|
-
const NamedCardsInput = z
|
|
119
|
-
.array(z.object({
|
|
120
|
-
cardId: z.string().min(1).describe('A card id from search_cards.'),
|
|
121
|
-
picks: z
|
|
122
|
-
.record(z.string(), z.array(z.string()).min(1))
|
|
123
|
-
.optional()
|
|
124
|
-
.describe("Bonus categories the user picked, for cards that have them: choice id → option ids, from search_cards. Ask; don't guess."),
|
|
125
|
-
activated: z
|
|
126
|
-
.array(z.string())
|
|
127
|
-
.optional()
|
|
128
|
-
.describe('Bonuses the user has activated with the issuer, as rule ids from search_cards.'),
|
|
129
|
-
}))
|
|
130
|
-
.optional()
|
|
131
|
-
.describe("Cards the user named in this conversation, to answer for just those cards without saving anything. Leave out to use the user's saved wallet if they have one; with neither, the answer covers every card earnrate knows.");
|
|
132
|
-
const NamedMembershipsInput = z
|
|
133
|
-
.array(z.enum(namedMembershipIds))
|
|
134
|
-
.optional()
|
|
135
|
-
.describe("Memberships the user has, such as amazon-prime, when they're named in the conversation rather than saved.");
|
|
136
|
-
const ALL_CARDS_NOTE = "The user hasn't named their cards, so this covers every card earnrate knows. That's a complete answer. If they want the best of their own cards, they can name them (pass them as `cards`); saving a wallet is optional.";
|
|
137
|
-
// Cards named in the conversation come first, then the saved wallet; with
|
|
138
|
-
// neither, read tools answer from every card earnrate knows.
|
|
139
|
-
async function sourceFor(cards, memberships) {
|
|
140
|
-
if (cards && cards.length > 0) {
|
|
141
|
-
const w = walletFromCards(catalog, {
|
|
142
|
-
cards: cards.map((c) => ({
|
|
143
|
-
id: c.cardId,
|
|
144
|
-
...(c.picks ? { picks: c.picks } : {}),
|
|
145
|
-
...(c.activated ? { activated: c.activated } : {}),
|
|
146
|
-
})),
|
|
147
|
-
...(memberships ? { memberships } : {}),
|
|
148
|
-
}, deps.today());
|
|
149
|
-
return typeof w === 'string' ? w : { wallet: w, named: true };
|
|
150
|
-
}
|
|
151
|
-
const read = await readableWallet();
|
|
152
|
-
if (typeof read === 'string')
|
|
153
|
-
return read;
|
|
154
|
-
return read.start !== null
|
|
155
|
-
? { wallet: null }
|
|
156
|
-
: { wallet: read.wallet, named: false };
|
|
157
|
-
}
|
|
158
|
-
server.registerTool('best_card_for_purchase', {
|
|
159
|
-
title: 'Best card for a purchase',
|
|
160
|
-
description: "Which card earns the most rewards for a purchase, and why. With no cards given and no saved wallet, it ranks every card earnrate knows (in `allCards`): a complete answer for anyone. With cards named in the conversation (`cards`) or a saved wallet, it picks the best of the user's own: `decision.cardId` is the pick and `decision.checkoutLabel` is how the card appears at checkout, with every usable card ranked with reasons, cards the merchant won't take, assumptions, warnings, and when a different point valuation would change the pick. Never needs or returns card numbers.",
|
|
161
|
-
inputSchema: z.object({
|
|
162
|
-
merchant: Merchant,
|
|
163
|
-
amount: z
|
|
164
|
-
.number()
|
|
165
|
-
.positive()
|
|
166
|
-
.optional()
|
|
167
|
-
.describe('Purchase amount in US dollars. Improves cap math.'),
|
|
168
|
-
channel: ChannelInput,
|
|
169
|
-
date: DateInput,
|
|
170
|
-
category: CategoryInput,
|
|
171
|
-
cards: NamedCardsInput,
|
|
172
|
-
memberships: NamedMembershipsInput,
|
|
173
|
-
}),
|
|
174
|
-
outputSchema: PurchaseAnswerSchema,
|
|
175
|
-
annotations: {
|
|
176
|
-
readOnlyHint: true,
|
|
177
|
-
openWorldHint: deps.llm !== null,
|
|
178
|
-
},
|
|
179
|
-
}, async ({ merchant, amount, channel, date, category, cards, memberships, }) => {
|
|
180
|
-
const source = await sourceFor(cards, memberships);
|
|
181
|
-
if (typeof source === 'string')
|
|
182
|
-
return fail(source);
|
|
183
|
-
const purchase = {
|
|
184
|
-
merchant,
|
|
185
|
-
amount: amount ?? null,
|
|
186
|
-
channel: channel ?? null,
|
|
187
|
-
date: date ?? deps.today(),
|
|
188
|
-
country: 'US',
|
|
189
|
-
};
|
|
190
|
-
const resolved = await resolve(merchant, purchase.channel, category ?? null);
|
|
191
|
-
if (source.wallet === null) {
|
|
192
|
-
const explored = exploreCards(catalog, {
|
|
193
|
-
merchant,
|
|
194
|
-
category: null,
|
|
195
|
-
amount: purchase.amount,
|
|
196
|
-
channel: purchase.channel,
|
|
197
|
-
date: purchase.date,
|
|
198
|
-
}, { ...settings({}), memberships: memberships ?? [] }, resolved.merchant);
|
|
199
|
-
const allCards = { ...explored, ranked: explored.ranked.slice(0, 10) };
|
|
200
|
-
const empty = recommend(catalog, { valuations: {}, memberships: [], cards: [] }, purchase, resolved.merchant);
|
|
201
|
-
return {
|
|
202
|
-
content: [
|
|
203
|
-
{
|
|
204
|
-
type: 'text',
|
|
205
|
-
text: `${formatExploration(allCards, true)}\n${ALL_CARDS_NOTE}`,
|
|
206
|
-
},
|
|
207
|
-
],
|
|
208
|
-
structuredContent: {
|
|
209
|
-
...empty,
|
|
210
|
-
warnings: [ALL_CARDS_NOTE, ...resolved.notices],
|
|
211
|
-
allCards,
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
const rec = recommend(catalog, source.wallet, purchase, resolved.merchant);
|
|
216
|
-
const output = {
|
|
217
|
-
...rec,
|
|
218
|
-
warnings: [...rec.warnings, ...resolved.notices],
|
|
219
|
-
allCards: null,
|
|
220
|
-
};
|
|
221
|
-
return {
|
|
222
|
-
content: [
|
|
223
|
-
{ type: 'text', text: formatRecommendation(output, purchase) },
|
|
224
|
-
],
|
|
225
|
-
structuredContent: output,
|
|
226
|
-
};
|
|
227
|
-
});
|
|
228
|
-
server.registerTool('resolve_merchant', {
|
|
229
|
-
title: 'Resolve a merchant',
|
|
230
|
-
description: 'Shows how earnrate identifies a merchant: its spend category, likely MCC, which card networks it takes, confidence, and whether that came from curated data, Claude, or nowhere. Use it to explain or double-check a recommendation.',
|
|
231
|
-
inputSchema: z.object({
|
|
232
|
-
merchant: Merchant,
|
|
233
|
-
channel: ChannelInput,
|
|
234
|
-
category: CategoryInput,
|
|
235
|
-
}),
|
|
236
|
-
outputSchema: MerchantResolutionSchema,
|
|
237
|
-
annotations: { readOnlyHint: true, openWorldHint: deps.llm !== null },
|
|
238
|
-
}, async ({ merchant, channel, category }) => {
|
|
239
|
-
const resolved = await resolve(merchant, channel ?? null, category ?? null);
|
|
240
|
-
const m = resolved.merchant;
|
|
241
|
-
const text = [
|
|
242
|
-
`${m.resolvedName}: ${m.category}${m.likelyMcc === null ? '' : ` (MCC ${String(m.likelyMcc)})`}, ${m.confidence} confidence, from ${m.source}.`,
|
|
243
|
-
...(m.inference
|
|
244
|
-
? [`Claude's reasoning: ${m.inference.rationale}`]
|
|
245
|
-
: []),
|
|
246
|
-
...resolved.notices,
|
|
247
|
-
].join('\n');
|
|
248
|
-
return {
|
|
249
|
-
content: [{ type: 'text', text }],
|
|
250
|
-
structuredContent: m,
|
|
251
|
-
};
|
|
252
|
-
});
|
|
253
|
-
walletTools.push(server.registerTool('list_wallet', {
|
|
254
|
-
title: 'List wallet',
|
|
255
|
-
description: "Lists the user's cards: checkout label, network, rewards currency and its value, spending caps with how much is left this period, chosen bonus categories (and whether they're current), welcome-bonus progress, which stores a store card works at, and when each card's data was last verified.",
|
|
256
|
-
outputSchema: WalletSummarySchema,
|
|
257
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
258
|
-
}, async () => {
|
|
259
|
-
const read = await readableWallet();
|
|
260
|
-
if (typeof read === 'string')
|
|
261
|
-
return fail(read);
|
|
262
|
-
const summary = walletSummary(catalog, read.wallet, deps.today());
|
|
263
|
-
if (read.start !== null)
|
|
264
|
-
return {
|
|
265
|
-
content: [{ type: 'text', text: read.start }],
|
|
266
|
-
structuredContent: summary,
|
|
267
|
-
};
|
|
268
|
-
const lines = summary.cards.map((c) => {
|
|
269
|
-
const caps = c.caps
|
|
270
|
-
.filter((cap) => cap.remaining !== null)
|
|
271
|
-
.map((cap) => `${cap.key} ${dollars(cap.spent)} of ${dollars(cap.amount)} used for ${cap.currentPeriod ?? ''}`);
|
|
272
|
-
const chosen = c.chosen
|
|
273
|
-
? `; chosen categories for ${c.chosen.period}${c.chosen.current ? '' : ' (out of date)'}`
|
|
274
|
-
: '';
|
|
275
|
-
const onlyAt = c.onlyAt
|
|
276
|
-
? `; works only at ${c.onlyAt.join(', ')}`
|
|
277
|
-
: '';
|
|
278
|
-
const rotation = c.rotationGap === null
|
|
279
|
-
? ''
|
|
280
|
-
: `; rotating categories for ${c.rotationGap} not in earnrate yet`;
|
|
281
|
-
const b = c.bonus;
|
|
282
|
-
const bonus = b?.state === 'open' && b.spend !== null
|
|
283
|
-
? `; welcome bonus ${dollars(b.spent)} of ${dollars(b.spend)} spent, due ${b.deadline ?? ''}`
|
|
284
|
-
: b
|
|
285
|
-
? `; welcome bonus ${b.state}`
|
|
286
|
-
: '';
|
|
287
|
-
return `- ${c.checkoutLabel ?? c.cardName} (${c.cardId}): ${c.currency} at ${String(c.centsPerUnit)}¢${caps.length > 0 ? `; ${caps.join(', ')}` : ''}${chosen}${rotation}${onlyAt}${bonus}`;
|
|
288
|
-
});
|
|
289
|
-
return {
|
|
290
|
-
content: [{ type: 'text', text: lines.join('\n') }],
|
|
291
|
-
structuredContent: summary,
|
|
292
|
-
};
|
|
293
|
-
}));
|
|
294
|
-
server.registerTool('compare_welcome_offers', {
|
|
295
|
-
title: 'Compare welcome offers',
|
|
296
|
-
description: "Ranks the public welcome (sign-up) offers on cards the user doesn't have by first-year value: the bonus at the user's point values minus the first year's annual fee. Use it when the user asks which new card to get or which has the best sign-up bonus. It covers only the cards earnrate knows, offers vary by person, and each offer's note gives the issuer's eligibility rules; pass those caveats on. It doesn't account for what a card would earn on the user's spending.",
|
|
297
|
-
inputSchema: z.object({
|
|
298
|
-
kind: z
|
|
299
|
-
.enum(['any', 'cash', 'points'])
|
|
300
|
-
.optional()
|
|
301
|
-
.describe('cash: cash back cards only. points: points and miles cards only.'),
|
|
302
|
-
noAnnualFee: z
|
|
303
|
-
.boolean()
|
|
304
|
-
.optional()
|
|
305
|
-
.describe('Only cards with no annual fee.'),
|
|
306
|
-
business: z
|
|
307
|
-
.boolean()
|
|
308
|
-
.optional()
|
|
309
|
-
.describe('Business cards instead of personal ones.'),
|
|
310
|
-
includeHeld: z
|
|
311
|
-
.boolean()
|
|
312
|
-
.optional()
|
|
313
|
-
.describe('Include cards already in the wallet.'),
|
|
314
|
-
cards: NamedCardsInput,
|
|
315
|
-
}),
|
|
316
|
-
outputSchema: OfferComparisonSchema,
|
|
317
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
318
|
-
}, async (args) => {
|
|
319
|
-
const source = await sourceFor(args.cards, undefined);
|
|
320
|
-
if (typeof source === 'string')
|
|
321
|
-
return fail(source);
|
|
322
|
-
const comparison = compareOffers(catalog, source.wallet ?? { valuations: {}, memberships: [], cards: [] }, {
|
|
323
|
-
kind: args.kind ?? 'any',
|
|
324
|
-
noAnnualFee: args.noAnnualFee ?? false,
|
|
325
|
-
business: args.business ?? false,
|
|
326
|
-
includeHeld: args.includeHeld ?? false,
|
|
327
|
-
}, deps.today());
|
|
328
|
-
const currencyName = (id) => catalog.currencies.find((c) => c.id === id)?.name ?? id;
|
|
329
|
-
return {
|
|
330
|
-
content: [
|
|
331
|
-
{ type: 'text', text: formatOffers(comparison, currencyName, false) },
|
|
332
|
-
],
|
|
333
|
-
structuredContent: comparison,
|
|
334
|
-
};
|
|
335
|
-
});
|
|
336
|
-
const CatalogCategory = z
|
|
337
|
-
.enum(ids)
|
|
338
|
-
.describe(`A spending category: ${catalog.categories.map((c) => `${c.id} (${c.name})`).join(', ')}.`);
|
|
339
|
-
const issuers = [...new Set(catalog.cards.map((c) => c.issuer))].sort();
|
|
340
|
-
const membershipIds = knownMemberships(catalog);
|
|
341
|
-
const CatalogFilters = {
|
|
342
|
-
kind: z
|
|
343
|
-
.enum(['any', 'cash', 'points'])
|
|
344
|
-
.optional()
|
|
345
|
-
.describe('cash: cash back cards only. points: points and miles cards only.'),
|
|
346
|
-
noAnnualFee: z
|
|
347
|
-
.boolean()
|
|
348
|
-
.optional()
|
|
349
|
-
.describe('Only cards with no annual fee.'),
|
|
350
|
-
business: z
|
|
351
|
-
.boolean()
|
|
352
|
-
.optional()
|
|
353
|
-
.describe('Business cards instead of personal ones.'),
|
|
354
|
-
issuer: z.enum(issuers).optional().describe("Only this issuer's cards."),
|
|
355
|
-
memberships: z
|
|
356
|
-
.array(z.enum(membershipIds))
|
|
357
|
-
.optional()
|
|
358
|
-
.describe("Memberships the user has, such as amazon-prime. Rates that need one they don't have are listed separately."),
|
|
359
|
-
valuation: z
|
|
360
|
-
.enum(['flat', 'points-heavy'])
|
|
361
|
-
.optional()
|
|
362
|
-
.describe('flat (default): points at their cash-out value, about 1¢. points-heavy: Amex MR and Chase UR at 1.7¢, for people who transfer points to airlines and hotels.'),
|
|
363
|
-
};
|
|
364
|
-
const settings = (args) => ({
|
|
365
|
-
filters: {
|
|
366
|
-
...ALL_PERSONAL_CARDS,
|
|
367
|
-
kind: args.kind ?? 'any',
|
|
368
|
-
noAnnualFee: args.noAnnualFee ?? false,
|
|
369
|
-
business: args.business ?? false,
|
|
370
|
-
issuer: args.issuer ?? null,
|
|
371
|
-
},
|
|
372
|
-
memberships: args.memberships ?? [],
|
|
373
|
-
valuations: args.valuation ? VALUATION_PROFILES[args.valuation] : {},
|
|
374
|
-
});
|
|
375
|
-
server.registerTool('best_cards_for', {
|
|
376
|
-
title: 'Best cards for a purchase',
|
|
377
|
-
description: 'Ranks every card earnrate knows, not only the user\'s, for one purchase or category, each set up at its best (the right category pick, activated, cap unused), with its annual fee and what earning the rate takes. Use it for questions like "what\'s the best card for groceries?" or "which card should I get for Amazon?". It needs no wallet. For which of the user\'s own cards to use, call best_card_for_purchase instead. Mention the annual fee and any conditions alongside each card.',
|
|
378
|
-
inputSchema: z.object({
|
|
379
|
-
merchant: Merchant.optional(),
|
|
380
|
-
category: CatalogCategory.optional(),
|
|
381
|
-
amount: z
|
|
382
|
-
.number()
|
|
383
|
-
.positive()
|
|
384
|
-
.optional()
|
|
385
|
-
.describe('Purchase amount in US dollars, if known.'),
|
|
386
|
-
channel: ChannelInput,
|
|
387
|
-
...CatalogFilters,
|
|
388
|
-
}),
|
|
389
|
-
outputSchema: ExplorationSchema,
|
|
390
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
391
|
-
}, (args) => {
|
|
392
|
-
if (args.merchant === undefined && args.category === undefined)
|
|
393
|
-
return fail('Give a merchant or a category.');
|
|
394
|
-
const result = exploreCards(catalog, {
|
|
395
|
-
merchant: args.merchant ?? null,
|
|
396
|
-
category: args.merchant === undefined ? (args.category ?? null) : null,
|
|
397
|
-
amount: args.amount ?? null,
|
|
398
|
-
channel: args.channel ?? null,
|
|
399
|
-
date: deps.today(),
|
|
400
|
-
}, settings(args));
|
|
401
|
-
const trimmed = { ...result, ranked: result.ranked.slice(0, 10) };
|
|
402
|
-
return {
|
|
403
|
-
content: [{ type: 'text', text: formatExploration(trimmed, true) }],
|
|
404
|
-
structuredContent: trimmed,
|
|
405
|
-
};
|
|
406
|
-
});
|
|
407
|
-
server.registerTool('simulate_spending', {
|
|
408
|
-
title: 'Simulate a year of spending',
|
|
409
|
-
description: 'Spends monthly amounts for a year across every card earnrate knows, and ranks single cards and two-card pairs by rewards minus annual fees. Spending is optional: without it, typical U.S. household amounts are used and the answer says so. With `cards` (named in the conversation) or compareToWallet (the saved wallet), it ranks the cards that would add the most to those cards instead. Use it for "which card fits my spending?" or "is it worth adding a card?". It leaves out welcome bonuses.',
|
|
410
|
-
inputSchema: z.object({
|
|
411
|
-
spending: z
|
|
412
|
-
.array(z.object({
|
|
413
|
-
merchant: Merchant.optional(),
|
|
414
|
-
category: CatalogCategory.optional(),
|
|
415
|
-
monthly: z.number().positive().describe('US dollars a month.'),
|
|
416
|
-
}))
|
|
417
|
-
.optional()
|
|
418
|
-
.describe("Monthly spending lines, each a category (grocery.supermarket, dining, gas, other) or a merchant (Amazon, Costco). Optional: leave out to use typical amounts, and don't press the user for numbers they haven't offered."),
|
|
419
|
-
cards: NamedCardsInput,
|
|
420
|
-
compareToWallet: z
|
|
421
|
-
.boolean()
|
|
422
|
-
.optional()
|
|
423
|
-
.describe("Rank the cards that would add the most to the user's saved wallet."),
|
|
424
|
-
...CatalogFilters,
|
|
425
|
-
}),
|
|
426
|
-
outputSchema: SpendingSimulationSchema,
|
|
427
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
428
|
-
}, async (args) => {
|
|
429
|
-
const given = args.spending ?? [];
|
|
430
|
-
if (given.some((l) => l.merchant === undefined && l.category === undefined))
|
|
431
|
-
return fail('Each spending line needs a merchant or a category.');
|
|
432
|
-
const lines = given.length === 0
|
|
433
|
-
? typicalSpendLines(catalog)
|
|
434
|
-
: resolveSpendLines(catalog, given.map((l) => ({
|
|
435
|
-
merchant: l.merchant ?? null,
|
|
436
|
-
category: l.merchant === undefined ? (l.category ?? null) : null,
|
|
437
|
-
monthly: l.monthly,
|
|
438
|
-
})));
|
|
439
|
-
const unknown = lines.filter((l) => l.merchant.source === 'none');
|
|
440
|
-
if (unknown.length > 0)
|
|
441
|
-
return fail(`earnrate doesn't know ${unknown.map((l) => `"${l.merchant.input}"`).join(', ')}. Give a category for those lines instead.`);
|
|
442
|
-
const notes = given.length === 0 ? [TYPICAL_SPEND_NOTE] : [];
|
|
443
|
-
const options = { ...settings(args), start: deps.today() };
|
|
444
|
-
const wantsTheirs = (args.cards !== undefined && args.cards.length > 0) ||
|
|
445
|
-
args.compareToWallet === true;
|
|
446
|
-
const source = wantsTheirs
|
|
447
|
-
? await sourceFor(args.cards, args.memberships)
|
|
448
|
-
: null;
|
|
449
|
-
if (typeof source === 'string')
|
|
450
|
-
return fail(source);
|
|
451
|
-
if (source && source.wallet !== null) {
|
|
452
|
-
const w = source.wallet;
|
|
453
|
-
const valued = args.valuation
|
|
454
|
-
? {
|
|
455
|
-
...w,
|
|
456
|
-
valuations: {
|
|
457
|
-
...w.valuations,
|
|
458
|
-
...VALUATION_PROFILES[args.valuation],
|
|
459
|
-
},
|
|
460
|
-
}
|
|
461
|
-
: w;
|
|
462
|
-
const result = simulateAdditions(catalog, valued, lines, options);
|
|
463
|
-
const text = formatAdditions(result, catalog, false);
|
|
464
|
-
return {
|
|
465
|
-
content: [{ type: 'text', text: [...notes, text].join('\n\n') }],
|
|
466
|
-
structuredContent: {
|
|
467
|
-
notes,
|
|
468
|
-
singles: [],
|
|
469
|
-
pairs: [],
|
|
470
|
-
current: result.current,
|
|
471
|
-
additions: result.additions
|
|
472
|
-
.slice(0, 10)
|
|
473
|
-
.map(({ simulation: _, ...a }) => a),
|
|
474
|
-
},
|
|
475
|
-
};
|
|
476
|
-
}
|
|
477
|
-
if (source)
|
|
478
|
-
notes.push(ALL_CARDS_NOTE);
|
|
479
|
-
const result = simulateCatalog(catalog, lines, options);
|
|
480
|
-
const text = formatCatalogSimulation(result, catalog, false);
|
|
481
|
-
return {
|
|
482
|
-
content: [{ type: 'text', text: [...notes, text].join('\n\n') }],
|
|
483
|
-
structuredContent: {
|
|
484
|
-
notes,
|
|
485
|
-
singles: result.singles.slice(0, 10),
|
|
486
|
-
pairs: result.pairs.slice(0, 5),
|
|
487
|
-
current: null,
|
|
488
|
-
additions: [],
|
|
489
|
-
},
|
|
490
|
-
};
|
|
491
|
-
});
|
|
492
|
-
server.registerTool('cheat_sheet', {
|
|
493
|
-
title: 'Cheat sheet',
|
|
494
|
-
description: "The card to use for each everyday kind of purchase right now: groceries, dining, gas, Amazon, Costco, travel, streaming, drugstores and everything else. With no cards given and no saved wallet, it picks from every card earnrate knows (`scope: all cards`, each row noting the card's fee and conditions). With cards named in the conversation or a saved wallet, it picks from the user's own cards, with caps, picks and activations as they are. For one specific store, call best_card_for_purchase instead. Pass on the notes.",
|
|
495
|
-
inputSchema: z.object({
|
|
496
|
-
date: DateInput,
|
|
497
|
-
cards: NamedCardsInput,
|
|
498
|
-
memberships: NamedMembershipsInput,
|
|
499
|
-
}),
|
|
500
|
-
outputSchema: CheatSheetSchema,
|
|
501
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
502
|
-
}, async (args) => {
|
|
503
|
-
const source = await sourceFor(args.cards, args.memberships);
|
|
504
|
-
if (typeof source === 'string')
|
|
505
|
-
return fail(source);
|
|
506
|
-
const date = args.date ?? deps.today();
|
|
507
|
-
if (source.wallet === null) {
|
|
508
|
-
const sheet = catalogCheatSheet(catalog, date, {
|
|
509
|
-
...settings({}),
|
|
510
|
-
memberships: args.memberships ?? [],
|
|
511
|
-
});
|
|
512
|
-
const withNote = { ...sheet, notes: [ALL_CARDS_NOTE] };
|
|
513
|
-
return {
|
|
514
|
-
content: [{ type: 'text', text: formatCheatSheet(withNote) }],
|
|
515
|
-
structuredContent: withNote,
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
const sheet = cheatSheet(catalog, source.wallet, date);
|
|
519
|
-
return {
|
|
520
|
-
content: [{ type: 'text', text: formatCheatSheet(sheet) }],
|
|
521
|
-
structuredContent: sheet,
|
|
522
|
-
};
|
|
523
|
-
});
|
|
524
|
-
walletTools.push(server.registerTool('record_purchase', {
|
|
525
|
-
title: 'Record a purchase',
|
|
526
|
-
description: "Records a purchase the user has already made, so spending caps and welcome-bonus progress stay accurate for future recommendations. It updates the user's wallet file. Only call it after the purchase has happened, and only once per purchase: calling it twice counts the spend twice. Purchases with no cap and no open welcome bonus are acknowledged and nothing is written.",
|
|
527
|
-
inputSchema: z.object({
|
|
528
|
-
cardId: z
|
|
529
|
-
.string()
|
|
530
|
-
.min(1)
|
|
531
|
-
.describe('The card used, as a cardId from list_wallet or best_card_for_purchase.'),
|
|
532
|
-
merchant: Merchant,
|
|
533
|
-
amount: z.number().positive().describe('Amount spent in US dollars.'),
|
|
534
|
-
channel: ChannelInput,
|
|
535
|
-
date: DateInput,
|
|
536
|
-
category: CategoryInput,
|
|
537
|
-
}),
|
|
538
|
-
outputSchema: RecordResultSchema,
|
|
539
|
-
annotations: {
|
|
540
|
-
readOnlyHint: false,
|
|
541
|
-
destructiveHint: false,
|
|
542
|
-
idempotentHint: false,
|
|
543
|
-
openWorldHint: deps.llm !== null,
|
|
544
|
-
},
|
|
545
|
-
},
|
|
546
|
-
// Queued per wallet file: parallel calls would otherwise each read the
|
|
547
|
-
// old usage and the last write would drop the others' spend.
|
|
548
|
-
(args) => (async () => {
|
|
549
|
-
const { cardId, merchant, amount, channel, date, category } = args;
|
|
550
|
-
const w = await wallet();
|
|
551
|
-
if (typeof w === 'string')
|
|
552
|
-
return fail(w);
|
|
553
|
-
if (!w.cards.some((c) => c.id === cardId)) {
|
|
554
|
-
return fail(`"${cardId}" isn't in the wallet. Cards: ${w.cards.map((c) => c.id).join(', ')}.`);
|
|
555
|
-
}
|
|
556
|
-
const purchase = {
|
|
557
|
-
cardId,
|
|
558
|
-
merchant,
|
|
559
|
-
amount,
|
|
560
|
-
channel: channel ?? null,
|
|
561
|
-
date: date ?? deps.today(),
|
|
562
|
-
};
|
|
563
|
-
const resolved = await resolve(merchant, purchase.channel, category ?? null);
|
|
564
|
-
const result = await deps.store.record(purchase, resolved.merchant);
|
|
565
|
-
if (!result.ok)
|
|
566
|
-
return fail(`Couldn't record it: ${result.error}`);
|
|
567
|
-
const { cap: booking, bonus } = result;
|
|
568
|
-
if (!booking && !bonus) {
|
|
569
|
-
const output = {
|
|
570
|
-
recorded: false,
|
|
571
|
-
booking: null,
|
|
572
|
-
bonus: null,
|
|
573
|
-
message: `Nothing to track: ${cardId} has no spending cap or open welcome bonus for this purchase, so the wallet wasn't changed.`,
|
|
574
|
-
};
|
|
575
|
-
return {
|
|
576
|
-
content: [{ type: 'text', text: output.message }],
|
|
577
|
-
structuredContent: output,
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
const messages = [];
|
|
581
|
-
if (booking) {
|
|
582
|
-
const left = Math.max(0, booking.capAmount - booking.after);
|
|
583
|
-
messages.push(`Recorded ${dollars(amount)} on ${cardId} against "${booking.capKey}": ${dollars(booking.before)} → ${dollars(booking.after)} of ${dollars(booking.capAmount)} for ${booking.period}, ${dollars(left)} left.`);
|
|
584
|
-
}
|
|
585
|
-
if (bonus) {
|
|
586
|
-
const left = Math.max(0, bonus.spend - bonus.after);
|
|
587
|
-
messages.push(left === 0
|
|
588
|
-
? `Welcome bonus spend met on ${cardId}: ${dollars(bonus.after)} of ${dollars(bonus.spend)}.`
|
|
589
|
-
: `Welcome bonus on ${cardId}: ${dollars(bonus.after)} of ${dollars(bonus.spend)} spent, ${dollars(left)} to go by ${bonus.deadline ?? 'the deadline'}.`);
|
|
590
|
-
}
|
|
591
|
-
const output = {
|
|
592
|
-
recorded: true,
|
|
593
|
-
booking,
|
|
594
|
-
bonus,
|
|
595
|
-
message: messages.join(' '),
|
|
596
|
-
};
|
|
597
|
-
return {
|
|
598
|
-
content: [
|
|
599
|
-
{
|
|
600
|
-
type: 'text',
|
|
601
|
-
text: [output.message, ...resolved.notices].join('\n'),
|
|
602
|
-
},
|
|
603
|
-
],
|
|
604
|
-
structuredContent: output,
|
|
605
|
-
};
|
|
606
|
-
})()));
|
|
607
|
-
const CardId = z
|
|
608
|
-
.string()
|
|
609
|
-
.min(1)
|
|
610
|
-
.describe('The card id from search_cards, e.g. chase-sapphire-preferred.');
|
|
611
|
-
const cardFields = {
|
|
612
|
-
checkoutLabel: z
|
|
613
|
-
.string()
|
|
614
|
-
.min(1)
|
|
615
|
-
.optional()
|
|
616
|
-
.describe('How the card appears at checkout or in a browser wallet, e.g. "Amex Gold". Optional.'),
|
|
617
|
-
picks: z
|
|
618
|
-
.record(z.string(), z.array(z.string()).min(1))
|
|
619
|
-
.optional()
|
|
620
|
-
.describe('For cards where the cardholder picks bonus categories: choice id → option ids, from search_cards, e.g. {"five-percent": ["tv-internet-streaming", "fast-food"]}. Saved for the current period. Ask the user; don\'t guess.'),
|
|
621
|
-
anniversary: z
|
|
622
|
-
.string()
|
|
623
|
-
.regex(/^\d{2}-\d{2}$/)
|
|
624
|
-
.optional()
|
|
625
|
-
.describe("The account's anniversary as MM-DD, for cards whose cap resets on it."),
|
|
626
|
-
activated: z
|
|
627
|
-
.array(z.string())
|
|
628
|
-
.optional()
|
|
629
|
-
.describe('Rule ids the user has activated with the issuer, such as rotating categories. Replaces the current list.'),
|
|
630
|
-
bonus: z
|
|
631
|
-
.object({
|
|
632
|
-
opened: IsoDate.describe('The day the account opened, YYYY-MM-DD.'),
|
|
633
|
-
spent: z
|
|
634
|
-
.number()
|
|
635
|
-
.nonnegative()
|
|
636
|
-
.optional()
|
|
637
|
-
.describe('Dollars already spent toward the bonus. Default 0.'),
|
|
638
|
-
spend: z
|
|
639
|
-
.number()
|
|
640
|
-
.positive()
|
|
641
|
-
.optional()
|
|
642
|
-
.describe("Dollars of spending the bonus needs, only if the user's offer differs from the published one."),
|
|
643
|
-
by: IsoDate.optional().describe("The deadline, YYYY-MM-DD, only if the user's offer differs from the published one."),
|
|
644
|
-
})
|
|
645
|
-
.nullable()
|
|
646
|
-
.optional()
|
|
647
|
-
.describe("A welcome bonus the user is working toward, so purchases recorded on this card count toward it and answers can favor it. Ask when they opened the account; spending needed and the deadline default to the card's published offer. null stops tracking it."),
|
|
648
|
-
};
|
|
649
|
-
// A card change reports what that card still needs; other changes don't.
|
|
650
|
-
function changed(result, message, cardChange = true) {
|
|
651
|
-
if (!result.ok)
|
|
652
|
-
return fail(result.error);
|
|
653
|
-
const output = {
|
|
654
|
-
message,
|
|
655
|
-
created: result.created,
|
|
656
|
-
cardIds: result.wallet.cards.map((c) => c.id),
|
|
657
|
-
memberships: result.wallet.memberships,
|
|
658
|
-
notes: result.notes,
|
|
659
|
-
};
|
|
660
|
-
const text = [
|
|
661
|
-
message,
|
|
662
|
-
`Wallet: ${output.cardIds.join(', ')}.`,
|
|
663
|
-
...(cardChange ? [formatNotes(result.notes)] : []),
|
|
664
|
-
].join('\n');
|
|
665
|
-
return {
|
|
666
|
-
content: [{ type: 'text', text }],
|
|
667
|
-
structuredContent: output,
|
|
668
|
-
};
|
|
669
|
-
}
|
|
670
|
-
const cardInput = (args) => ({
|
|
671
|
-
id: args.cardId,
|
|
672
|
-
...(args.checkoutLabel === undefined
|
|
673
|
-
? {}
|
|
674
|
-
: { checkoutLabel: args.checkoutLabel }),
|
|
675
|
-
...(args.picks === undefined ? {} : { picks: args.picks }),
|
|
676
|
-
...(args.anniversary === undefined
|
|
677
|
-
? {}
|
|
678
|
-
: { anniversary: args.anniversary }),
|
|
679
|
-
...(args.activated === undefined ? {} : { activated: args.activated }),
|
|
680
|
-
...(args.bonus === undefined
|
|
681
|
-
? {}
|
|
682
|
-
: {
|
|
683
|
-
bonus: args.bonus === null
|
|
684
|
-
? null
|
|
685
|
-
: {
|
|
686
|
-
opened: args.bonus.opened,
|
|
687
|
-
...(args.bonus.spent === undefined
|
|
688
|
-
? {}
|
|
689
|
-
: { spent: args.bonus.spent }),
|
|
690
|
-
...(args.bonus.spend === undefined
|
|
691
|
-
? {}
|
|
692
|
-
: { spend: args.bonus.spend }),
|
|
693
|
-
...(args.bonus.by === undefined ? {} : { by: args.bonus.by }),
|
|
694
|
-
},
|
|
695
|
-
}),
|
|
696
|
-
});
|
|
697
|
-
const cardName = (id) => catalog.cards.find((c) => c.id === id)?.name ?? id;
|
|
698
|
-
server.registerTool('search_cards', {
|
|
699
|
-
title: 'Search cards',
|
|
700
|
-
description: 'Finds credit cards in earnrate\'s catalog by name or issuer, e.g. "sapphire", "amex gold" or "bofa". Returns each card\'s id (for add_card), network, annual fee, whether it\'s already in the wallet, and what it needs set up: category picks and their options, memberships, activations. Leave the query out to list every card. US cards only.',
|
|
701
|
-
inputSchema: z.object({
|
|
702
|
-
query: z
|
|
703
|
-
.string()
|
|
704
|
-
.optional()
|
|
705
|
-
.describe('Card name or issuer, as the user said it.'),
|
|
706
|
-
}),
|
|
707
|
-
outputSchema: CardSearchSchema,
|
|
708
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
709
|
-
}, async ({ query }) => {
|
|
710
|
-
const held = await deps.store.load().catch(() => null);
|
|
711
|
-
const result = searchCards(catalog, query ?? '', held, deps.today());
|
|
712
|
-
const header = result.exact
|
|
713
|
-
? ''
|
|
714
|
-
: result.cards.length > 0
|
|
715
|
-
? 'No card matched every word. Closest:\n'
|
|
716
|
-
: `No card matched "${query ?? ''}". earnrate covers ${String(catalog.cards.length)} US cards; list them all by leaving the query out.`;
|
|
717
|
-
return {
|
|
718
|
-
content: [
|
|
719
|
-
{
|
|
720
|
-
type: 'text',
|
|
721
|
-
text: header + result.cards.map(formatCardInfo).join('\n'),
|
|
722
|
-
},
|
|
723
|
-
],
|
|
724
|
-
structuredContent: result,
|
|
725
|
-
};
|
|
726
|
-
});
|
|
727
|
-
walletTools.push(server.registerTool('add_card', {
|
|
728
|
-
title: 'Add a card',
|
|
729
|
-
description: "Adds a card the user holds to their wallet by its id from search_cards, creating the wallet if there isn't one. The reply says what the card still needs (category picks, memberships, activations); ask the user about those. Stores only the card's product id and settings, never card numbers.",
|
|
730
|
-
inputSchema: z.object({ cardId: CardId, ...cardFields }),
|
|
731
|
-
outputSchema: WalletChangeSchema,
|
|
732
|
-
annotations: {
|
|
733
|
-
readOnlyHint: false,
|
|
734
|
-
destructiveHint: false,
|
|
735
|
-
idempotentHint: false,
|
|
736
|
-
openWorldHint: false,
|
|
737
|
-
},
|
|
738
|
-
}, async (args) => {
|
|
739
|
-
const result = await deps.store.addCard(cardInput(args), deps.today());
|
|
740
|
-
return changed(result, `Added ${cardName(args.cardId)} (${args.cardId})${result.ok && result.created ? (deps.savedWallets === 'account' ? ', the first card in your saved wallet' : `, starting a new wallet at ${deps.store.where}`) : ''}.`);
|
|
741
|
-
}));
|
|
742
|
-
walletTools.push(server.registerTool('update_card', {
|
|
743
|
-
title: 'Update a card',
|
|
744
|
-
description: 'Changes settings on a card already in the wallet: its category picks for this period, checkout label, anniversary or activated categories. Picks for the current period are merged with the ones already saved. Use it when the user picks new categories, such as each quarter on U.S. Bank Cash+.',
|
|
745
|
-
inputSchema: z.object({ cardId: CardId, ...cardFields }),
|
|
746
|
-
outputSchema: WalletChangeSchema,
|
|
747
|
-
annotations: {
|
|
748
|
-
readOnlyHint: false,
|
|
749
|
-
destructiveHint: false,
|
|
750
|
-
idempotentHint: true,
|
|
751
|
-
openWorldHint: false,
|
|
752
|
-
},
|
|
753
|
-
}, async (args) => changed(await deps.store.updateCard(cardInput(args), deps.today()), `Updated ${cardName(args.cardId)} (${args.cardId}).`)));
|
|
754
|
-
walletTools.push(server.registerTool('remove_card', {
|
|
755
|
-
title: 'Remove a card',
|
|
756
|
-
description: "Removes a card from the wallet, with its tracked cap usage and bonus progress. Only when the user says they no longer have it or don't want it considered.",
|
|
757
|
-
inputSchema: z.object({ cardId: CardId }),
|
|
758
|
-
outputSchema: WalletChangeSchema,
|
|
759
|
-
annotations: {
|
|
760
|
-
readOnlyHint: false,
|
|
761
|
-
destructiveHint: true,
|
|
762
|
-
idempotentHint: true,
|
|
763
|
-
openWorldHint: false,
|
|
764
|
-
},
|
|
765
|
-
}, async ({ cardId }) => changed(await deps.store.removeCard(cardId), `Removed ${cardName(cardId)} (${cardId}).`, false)));
|
|
766
|
-
walletTools.push(server.registerTool('set_memberships', {
|
|
767
|
-
title: 'Set memberships',
|
|
768
|
-
description: "Sets the memberships that unlock some cards' rates, such as amazon-prime for Prime Visa's 5% or a Bank of America Preferred Rewards tier. Replaces the whole list, so include the ones to keep.",
|
|
769
|
-
inputSchema: z.object({
|
|
770
|
-
memberships: z
|
|
771
|
-
.array(z.enum(membershipIds))
|
|
772
|
-
.describe(`Every membership the user has. Known: ${membershipIds.join(', ')}.`),
|
|
773
|
-
}),
|
|
774
|
-
outputSchema: WalletChangeSchema,
|
|
775
|
-
annotations: {
|
|
776
|
-
readOnlyHint: false,
|
|
777
|
-
destructiveHint: false,
|
|
778
|
-
idempotentHint: true,
|
|
779
|
-
openWorldHint: false,
|
|
780
|
-
},
|
|
781
|
-
}, async (args) => changed(await deps.store.setMemberships(args.memberships), args.memberships.length > 0
|
|
782
|
-
? `Memberships set to ${args.memberships.join(', ')}.`
|
|
783
|
-
: 'Memberships cleared.', false)));
|
|
784
|
-
if (deps.savedWallets === 'account') {
|
|
785
|
-
const store = deps.store;
|
|
786
|
-
server.registerTool('export_wallet', {
|
|
787
|
-
title: 'Export the wallet',
|
|
788
|
-
description: 'The saved wallet as a wallet.yaml file the earnrate command line and earnrate.dev can import: card ids, picks, activations, memberships, cap usage and bonus progress. Never card numbers.',
|
|
789
|
-
inputSchema: z.object({}),
|
|
790
|
-
outputSchema: z.object({ yaml: z.string() }),
|
|
791
|
-
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
792
|
-
}, async () => {
|
|
793
|
-
const w = await wallet();
|
|
794
|
-
if (typeof w === 'string')
|
|
795
|
-
return fail(w);
|
|
796
|
-
const yaml = walletYaml(w);
|
|
797
|
-
return {
|
|
798
|
-
content: [{ type: 'text', text: yaml }],
|
|
799
|
-
structuredContent: { yaml },
|
|
800
|
-
};
|
|
801
|
-
});
|
|
802
|
-
server.registerTool('import_wallet', {
|
|
803
|
-
title: 'Import a wallet',
|
|
804
|
-
description: 'Replaces the saved wallet with a wallet.yaml from the earnrate command line or earnrate.dev, when the user pastes or attaches one. Wallet files only: never statements or card numbers. Confirm with the user first if they already have cards saved.',
|
|
805
|
-
inputSchema: z.object({
|
|
806
|
-
yaml: z
|
|
807
|
-
.string()
|
|
808
|
-
.min(1)
|
|
809
|
-
.max(100_000)
|
|
810
|
-
.describe('The wallet.yaml text, as the user gave it.'),
|
|
811
|
-
}),
|
|
812
|
-
outputSchema: WalletChangeSchema,
|
|
813
|
-
annotations: {
|
|
814
|
-
readOnlyHint: false,
|
|
815
|
-
destructiveHint: true,
|
|
816
|
-
idempotentHint: true,
|
|
817
|
-
openWorldHint: false,
|
|
818
|
-
},
|
|
819
|
-
}, async ({ yaml }) => {
|
|
820
|
-
const parsed = parseWalletYaml(yaml, catalog);
|
|
821
|
-
if (typeof parsed === 'string')
|
|
822
|
-
return fail(parsed);
|
|
823
|
-
return changed(await store.replace(parsed), `Imported a wallet with ${String(parsed.cards.length)} ${parsed.cards.length === 1 ? 'card' : 'cards'}.`, false);
|
|
824
|
-
});
|
|
825
|
-
server.registerTool('delete_wallet', {
|
|
826
|
-
title: 'Delete the wallet',
|
|
827
|
-
description: 'Deletes the saved wallet now and for good, and signs out every app using it. Only when the user asks to delete it; confirm first, and offer export_wallet to keep a copy.',
|
|
828
|
-
inputSchema: z.object({}),
|
|
829
|
-
outputSchema: z.object({ deleted: z.boolean() }),
|
|
830
|
-
annotations: {
|
|
831
|
-
readOnlyHint: false,
|
|
832
|
-
destructiveHint: true,
|
|
833
|
-
idempotentHint: true,
|
|
834
|
-
openWorldHint: false,
|
|
835
|
-
},
|
|
836
|
-
}, async () => {
|
|
837
|
-
await store.erase();
|
|
838
|
-
return {
|
|
839
|
-
content: [
|
|
840
|
-
{
|
|
841
|
-
type: 'text',
|
|
842
|
-
text: 'Deleted the saved wallet. Answers now cover every card, or the cards named in the conversation.',
|
|
843
|
-
},
|
|
844
|
-
],
|
|
845
|
-
structuredContent: { deleted: true },
|
|
846
|
-
};
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
if (deps.savedWallets === 'none')
|
|
850
|
-
for (const tool of walletTools)
|
|
851
|
-
tool.remove();
|
|
41
|
+
const server = new McpServer({ name: MCP_SERVER_NAME, version: deps.version }, { instructions: instructions(deps.savedWallets) });
|
|
42
|
+
const ctx = makeContext(deps);
|
|
43
|
+
const inputs = makeInputs(deps.catalog);
|
|
44
|
+
registerAnswerTools(server, deps, ctx, inputs);
|
|
45
|
+
registerWalletTools(server, deps, ctx, inputs);
|
|
46
|
+
if (deps.savedWallets === 'account')
|
|
47
|
+
registerAccountTools(server, deps.catalog, deps.store, ctx);
|
|
852
48
|
return server;
|
|
853
49
|
}
|