@finchagentic/mcp 4.2.0 → 4.4.1

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.
@@ -293,7 +293,7 @@ async function handleMarketTool(name, args) {
293
293
  case "get_market_data": {
294
294
  const parsed = GetMarketDataSchema.safeParse(args ?? {});
295
295
  if (!parsed.success)
296
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
296
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
297
297
  const { token } = parsed.data;
298
298
  if (token) {
299
299
  const resolved = await resolveTokenId(token);
@@ -349,7 +349,7 @@ async function handleMarketTool(name, args) {
349
349
  case "get_token_data": {
350
350
  const parsed = GetTokenDataSchema.safeParse(args);
351
351
  if (!parsed.success)
352
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
352
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
353
353
  const q = parsed.data.question;
354
354
  // Try to extract a known symbol first, then fall back to search
355
355
  const upperQ = q.toUpperCase();
@@ -381,7 +381,7 @@ async function handleMarketTool(name, args) {
381
381
  case "compare_tokens": {
382
382
  const parsed = CompareTokensSchema.safeParse(args);
383
383
  if (!parsed.success)
384
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
384
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
385
385
  const syms = parsed.data.tokens.map(t => t.toUpperCase());
386
386
  const ids = syms.map(s => SYMBOL_TO_ID[s]).filter(Boolean);
387
387
  const unknown = syms.filter(s => !SYMBOL_TO_ID[s]);
@@ -449,7 +449,7 @@ async function handleMarketTool(name, args) {
449
449
  case "token_history": {
450
450
  const parsed = TokenHistorySchema.safeParse(args);
451
451
  if (!parsed.success)
452
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
452
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
453
453
  const days = parsed.data.days ?? 7;
454
454
  const resolved = await resolveTokenId(parsed.data.token);
455
455
  if (!resolved)
@@ -498,7 +498,7 @@ async function handleMarketTool(name, args) {
498
498
  case "get_base_token_data": {
499
499
  const parsed = GetBaseTokenDataSchema.safeParse(args);
500
500
  if (!parsed.success)
501
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
501
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
502
502
  const address = parsed.data.tokenAddress.toLowerCase();
503
503
  const [pair, coingeckoId] = await Promise.all([
504
504
  fetchDexscreenerBaseToken(address),
@@ -519,7 +519,7 @@ async function handleMemoryTool(name, args) {
519
519
  case "memory_add": {
520
520
  const parsed = AddSchema.safeParse(args);
521
521
  if (!parsed.success)
522
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
522
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
523
523
  const { content, title, tags, sourceUrl, force } = parsed.data;
524
524
  // `sourceUrl` is not stored, it is fetched and indexed — by the local
525
525
  // memory server on the user's own machine when local mode is on. An
@@ -580,7 +580,7 @@ async function handleMemoryTool(name, args) {
580
580
  case "memory_search": {
581
581
  const parsed = SearchSchema.safeParse(args);
582
582
  if (!parsed.success)
583
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
583
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
584
584
  const { query, limit = 10 } = parsed.data;
585
585
  // Over-fetch so post-decay ranking still has enough material.
586
586
  const overfetch = Math.min(50, Math.max(limit * 2, 20));
@@ -662,7 +662,7 @@ async function handleMemoryTool(name, args) {
662
662
  case "memory_context": {
663
663
  const parsed = ContextSchema.safeParse(args);
664
664
  if (!parsed.success)
665
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
665
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
666
666
  const { topic, limit = 8 } = parsed.data;
667
667
  // v3.25.1: use hybrid retrieval so context loading picks up exact-token
668
668
  // matches (env var names, model IDs, contract addresses) that semantic-
@@ -722,7 +722,7 @@ async function handleMemoryTool(name, args) {
722
722
  case "memory_list": {
723
723
  const parsed = ListSchema.safeParse(args ?? {});
724
724
  if (!parsed.success)
725
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
725
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
726
726
  const { limit = 20, tag } = parsed.data;
727
727
  const localList = (0, local_memory_js_1.getLocalMemoryConfig)();
728
728
  let results;
@@ -753,7 +753,7 @@ async function handleMemoryTool(name, args) {
753
753
  case "memory_delete": {
754
754
  const parsed = DeleteMemSchema.safeParse(args);
755
755
  if (!parsed.success)
756
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
756
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
757
757
  if (args?.confirm !== true) {
758
758
  return {
759
759
  content: [{
@@ -784,7 +784,7 @@ async function handleMemoryTool(name, args) {
784
784
  case "memory_insight": {
785
785
  const parsed = InsightSchema.safeParse(args);
786
786
  if (!parsed.success)
787
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
787
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
788
788
  const { topic, depth = "standard" } = parsed.data;
789
789
  const memLimit = depth === "deep" ? 15 : depth === "quick" ? 5 : 8;
790
790
  // v3.25.1: hybrid retrieval for memory side (was semantic-only) so the
@@ -872,7 +872,7 @@ async function handleMemoryTool(name, args) {
872
872
  case "memory_extract": {
873
873
  const parsed = ExtractSchema.safeParse(args);
874
874
  if (!parsed.success)
875
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
875
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
876
876
  const { text, facts, source = "extract" } = parsed.data;
877
877
  // ── PASS 1: hand the text back with the extraction rubric ───────────
878
878
  // Deciding what counts as a fact is judgement about *this user's*
@@ -929,7 +929,7 @@ async function handleMemoryTool(name, args) {
929
929
  case "memory_consolidate": {
930
930
  const parsed = ConsolidateSchema.safeParse(args);
931
931
  if (!parsed.success)
932
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
932
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
933
933
  const { topic, limit = 12, summary } = parsed.data;
934
934
  const localConsolidateCfg = (0, local_memory_js_1.getLocalMemoryConfig)();
935
935
  // ── PASS 2: save the caller's merged version ────────────────────────
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MIROSHARK_TOOLS = void 0;
4
4
  exports.handleMirosharkTool = handleMirosharkTool;
5
+ const config_js_1 = require("../config.js");
5
6
  const CONVEX_SITE = process.env.FINCH_CONVEX_URL ?? "https://befitting-porcupine-276.convex.site";
6
7
  exports.MIROSHARK_TOOLS = [
7
8
  {
@@ -50,7 +51,13 @@ exports.MIROSHARK_TOOLS = [
50
51
  ];
51
52
  // ── HTTP helpers ──────────────────────────────────────────────────────────────
52
53
  function authHeaders() {
53
- const key = process.env.FINCH_API_KEY ?? process.env.FINCH_SESSION_TOKEN;
54
+ // Bug fix: this used to read only process.env.FINCH_API_KEY/
55
+ // FINCH_SESSION_TOKEN directly, bypassing getSavedToken()'s env-var-then-
56
+ // saved-config fallback that every other tool goes through (via
57
+ // callConvex/callConvexRaw in convex.ts). A user authenticated via
58
+ // `finch login` (writes to ~/.finch/config.json, not an env var) got a
59
+ // silent, unauthenticated request here while every other tool worked.
60
+ const key = process.env.FINCH_API_KEY ?? (0, config_js_1.getSavedToken)();
54
61
  return key ? { Authorization: `Bearer ${key}` } : {};
55
62
  }
56
63
  async function miroJson(path, method, body, timeoutMs = 90000) {
@@ -106,7 +106,7 @@ async function handleMonitorTool(name, args) {
106
106
  if (name === "schedule_research") {
107
107
  const parsed = CreateSchema.safeParse(args);
108
108
  if (!parsed.success)
109
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
109
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
110
110
  const key = getKey();
111
111
  if (!key)
112
112
  return noKeyMsg();
@@ -284,7 +284,7 @@ async function handleMonitorTool(name, args) {
284
284
  if (name === "cancel_monitor") {
285
285
  const parsed = CancelSchema.safeParse(args);
286
286
  if (!parsed.success)
287
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
287
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
288
288
  if (args?.confirm !== true) {
289
289
  return {
290
290
  content: [{
package/dist/tools/os.js CHANGED
@@ -6,6 +6,7 @@ const convex_js_1 = require("../convex.js");
6
6
  const token_gate_js_1 = require("../token-gate.js");
7
7
  const wallet_js_1 = require("../wallet.js");
8
8
  const local_memory_js_1 = require("../local-memory.js");
9
+ const config_js_1 = require("../config.js");
9
10
  const CONVEX_SITE = process.env.FINCH_CONVEX_URL ?? "https://befitting-porcupine-276.convex.site";
10
11
  exports.OS_TOOLS = [
11
12
  {
@@ -199,13 +200,18 @@ async function handleOsTool(name, args) {
199
200
  if (!message)
200
201
  return { content: [{ type: "text", text: "Error: message is required" }] };
201
202
  try {
202
- const res = await fetch(`${CONVEX_SITE}/noel/shell/chat`, {
203
+ // Bug fix: this used to read only process.env.FINCH_SESSION_TOKEN/
204
+ // FINCH_API_KEY directly, bypassing getSavedToken()'s fallback to
205
+ // ~/.finch/config.json - a user authenticated via `finch login`
206
+ // (not an env var) silently sent an empty Authorization header here
207
+ // while every other tool (which goes through callConvex) worked.
208
+ const res = await fetch(`${CONVEX_SITE}/finch/shell/chat`, {
203
209
  method: "POST",
204
210
  headers: {
205
211
  "Content-Type": "application/json",
206
- "Authorization": `Bearer ${process.env.FINCH_SESSION_TOKEN ?? process.env.FINCH_API_KEY ?? ""}`,
212
+ "Authorization": `Bearer ${(0, config_js_1.getSavedToken)() ?? process.env.FINCH_API_KEY ?? ""}`,
207
213
  },
208
- body: JSON.stringify({ message, agentId: agent_id ?? "noel-default" }),
214
+ body: JSON.stringify({ message, agentId: agent_id ?? "finch-default" }),
209
215
  signal: AbortSignal.timeout(60000),
210
216
  });
211
217
  if (!res.ok) {
@@ -147,7 +147,7 @@ async function handleResearchChain(name, args) {
147
147
  return null;
148
148
  const parsed = InputSchema.safeParse(args);
149
149
  if (!parsed.success) {
150
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
150
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
151
151
  }
152
152
  const { startKey } = parsed.data;
153
153
  const maxDepth = parsed.data.maxDepth ?? 8;
@@ -154,7 +154,7 @@ async function handleResearchCompare(name, args) {
154
154
  return null;
155
155
  const parsed = InputSchema.safeParse(args);
156
156
  if (!parsed.success) {
157
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
157
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
158
158
  }
159
159
  const { keyA, keyB, focus, comparison } = parsed.data;
160
160
  const saveToVault = parsed.data.saveToVault ?? true;
@@ -100,7 +100,7 @@ async function handleResearchTool(name, args) {
100
100
  if (name === "web_scrape") {
101
101
  const parsed = ScrapeSchema.safeParse(args);
102
102
  if (!parsed.success)
103
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
103
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
104
104
  const { url, focus } = parsed.data;
105
105
  const unsafe = await (0, public_url_js_1.assertPublicUrl)(url);
106
106
  if (unsafe) {
@@ -120,7 +120,7 @@ async function handleResearchTool(name, args) {
120
120
  if (name === "web_search") {
121
121
  const parsed = SearchSchema.safeParse(args);
122
122
  if (!parsed.success)
123
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
123
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
124
124
  const { query, limit = 5 } = parsed.data;
125
125
  // Priority 1: user BYOK direct path. Priority 2: Finch proxy.
126
126
  // Same data shape so the formatting code below is identical for both.
@@ -94,7 +94,7 @@ async function handleBridgeTool(name, args) {
94
94
  return null;
95
95
  const parsed = Schema.safeParse(args);
96
96
  if (!parsed.success) {
97
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
97
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
98
98
  }
99
99
  const wanted = parsed.data.ticker?.trim().toUpperCase();
100
100
  const minGap = parsed.data.minGapPct ?? 0;
@@ -30,6 +30,20 @@ exports.RH_RPC = process.env.ROBINHOOD_RPC_URL ??
30
30
  process.env.RH_RPC_URL ??
31
31
  process.env.FINCH_RH_RPC_URL ??
32
32
  "https://rpc.mainnet.chain.robinhood.com";
33
+ /** Host only, for display in tool output - never the full RH_RPC. An
34
+ * operator can point ROBINHOOD_RPC_URL/RH_RPC_URL at a keyed provider
35
+ * (same pattern app/convex just fixed for its own Alchemy-key leak risk -
36
+ * a `.../v2/<key>`-style URL echoed verbatim into a tool response lands the
37
+ * key in chat transcripts/client logs). Falls back to the raw value only
38
+ * if it isn't a parseable URL, which should never happen in practice. */
39
+ function rhRpcDisplay() {
40
+ try {
41
+ return new URL(exports.RH_RPC).host;
42
+ }
43
+ catch {
44
+ return "(configured)";
45
+ }
46
+ }
33
47
  exports.RH_EXPLORER = "https://robinhoodchain.blockscout.com";
34
48
  const NATIVE_ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
35
49
  const RH_PERMIT2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
@@ -754,7 +768,7 @@ async function fetchRhBalances(address) {
754
768
  else
755
769
  for (const h of holdings)
756
770
  lines.push(`- ${h.symbol}: ${h.bal} \`${h.address}\``);
757
- lines.push(``, `_RPC: ${exports.RH_RPC}_`, `_Explorer: ${exports.RH_EXPLORER}/address/${address}_`);
771
+ lines.push(``, `_RPC: ${rhRpcDisplay()}_`, `_Explorer: ${exports.RH_EXPLORER}/address/${address}_`);
758
772
  return lines.join("\n");
759
773
  }
760
774
  // ─── Onchain safety scan (Blockscout + DexScreener; free, no LLM) ─────────────
@@ -1177,7 +1191,7 @@ async function handleRhMcpTool(name, args) {
1177
1191
  "",
1178
1192
  `**Wallet**: \`${addr ?? "(not configured — run finch login / first tool)"}\``,
1179
1193
  `**ETH on RH (gas)**: ${eth}`,
1180
- `**RPC**: ${exports.RH_RPC}`,
1194
+ `**RPC**: ${rhRpcDisplay()}`,
1181
1195
  `**Explorer**: ${exports.RH_EXPLORER}`,
1182
1196
  `**Catalog**: ${exports.RH_STOCKS.length} stocks (AAPL…USAR) + any RH-chain crypto via DexScreener`,
1183
1197
  "",
@@ -345,7 +345,7 @@ async function handleScannerTool(name, args) {
345
345
  if (name === "score_token") {
346
346
  const parsed = ScoreTokenSchema.safeParse(args);
347
347
  if (!parsed.success)
348
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
348
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
349
349
  const { address, minLiquidity = DEFAULT_MIN_LIQ } = parsed.data;
350
350
  const data = await fetchJson(`https://api.dexscreener.com/latest/dex/tokens/${address}`);
351
351
  const pair = (data.pairs ?? [])
@@ -414,7 +414,7 @@ async function handleScannerTool(name, args) {
414
414
  if (name === "check_token") {
415
415
  const parsed = CheckTokenSchema.safeParse(args);
416
416
  if (!parsed.success)
417
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
417
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
418
418
  const { address } = parsed.data;
419
419
  // GoPlusLabs - chain 8453 = Base mainnet
420
420
  const data = await fetchJson(`https://api.gopluslabs.io/api/v1/token_security/8453?contract_addresses=${address}`);
@@ -476,7 +476,7 @@ async function handleScannerTool(name, args) {
476
476
  if (name === "scan_market") {
477
477
  const parsed = ScanDipsSchema.safeParse(args ?? {});
478
478
  if (!parsed.success)
479
- return { content: [{ type: "text", text: `Invalid input: ${parsed.error.issues[0].message}` }], isError: true };
479
+ return { content: [{ type: "text", text: `${parsed.error.issues[0].message}` }], isError: true };
480
480
  const input = args;
481
481
  const mode = input?.mode === "momentum" ? "momentum" : "dips";
482
482
  const { minScore = DEFAULT_MIN_SCORE, minLiquidity = DEFAULT_MIN_LIQ, limit = 40 } = parsed.data;
@@ -134,6 +134,21 @@ exports.STAKE_TOOLS = [
134
134
  required: ["stakeId", "confirm"],
135
135
  },
136
136
  },
137
+ {
138
+ name: "claim_vested_rewards",
139
+ description: "Claim all your fully-vested USDG staking rewards to your custodial wallet. Daily rewards split " +
140
+ "50% instant / 50% vested over 3 days - this claims whatever portion has finished vesting across " +
141
+ "ALL your stakes in one call (check stake_finch_status for accrued totals; you'll also get a " +
142
+ "notification when rewards become claimable). Does nothing to the stake itself - principal stays " +
143
+ "staked and earning. Requires `finch login` and `confirm: true`.",
144
+ inputSchema: {
145
+ type: "object",
146
+ properties: {
147
+ confirm: { type: "boolean", description: "Must be true to claim - this moves real USDG into your custodial wallet." },
148
+ },
149
+ required: ["confirm"],
150
+ },
151
+ },
137
152
  {
138
153
  name: "stake_auto_restake",
139
154
  description: "Turn auto-restake on/off for one of your stakes. When ON, the moment the lock-up ends the stake " +
@@ -143,7 +158,7 @@ exports.STAKE_TOOLS = [
143
158
  "the stake is unlockable and it just sits there earning nothing until you run unstake_finch. " +
144
159
  "Does NOT auto-compound rewards into the stake - that would require signing from your custodial " +
145
160
  "wallet unattended, which this intentionally does not do; claim rewards yourself with " +
146
- "claimVestedRewards (you'll get a notification when they're ready). Requires `finch login`.",
161
+ "claim_vested_rewards (you'll get a notification when they're ready). Requires `finch login`.",
147
162
  inputSchema: {
148
163
  type: "object",
149
164
  properties: {
@@ -304,6 +319,31 @@ async function handleStakeTool(name, args) {
304
319
  }
305
320
  return { content: [{ type: "text", text: lines.join("\n") }] };
306
321
  }
322
+ if (name === "claim_vested_rewards") {
323
+ const { confirm } = (args ?? {});
324
+ if (confirm !== true) {
325
+ return {
326
+ content: [{ type: "text", text: "Refusing to claim without confirmation - pass `confirm: true`." }],
327
+ isError: true,
328
+ };
329
+ }
330
+ const login = requireLogin();
331
+ if (!login)
332
+ return { content: [{ type: "text", text: NOT_LOGGED_IN_MSG }], isError: true };
333
+ const result = await (0, convex_js_1.callConvex)("/mcp/stake/claim-rewards", "POST", {}, "claim_vested_rewards");
334
+ if (result.error)
335
+ return { content: [{ type: "text", text: `Claim failed: ${result.error}` }], isError: true };
336
+ return {
337
+ content: [{
338
+ type: "text",
339
+ text: [
340
+ `✅ Claimed ${(result.claimedAmount ?? 0).toFixed(4)} USDG vested rewards`,
341
+ `Tx: \`${result.txHash}\``,
342
+ `${rh_mcp_js_1.RH_EXPLORER}/tx/${result.txHash}`,
343
+ ].join("\n"),
344
+ }],
345
+ };
346
+ }
307
347
  if (name === "stake_auto_restake") {
308
348
  const { stakeId, enabled } = (args ?? {});
309
349
  if (!stakeId)