@datadive-tools/mcp 0.12.0 → 0.14.0

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/lib.js CHANGED
@@ -139,7 +139,7 @@ function extractMessage(body) {
139
139
  }
140
140
 
141
141
  // package.json
142
- var version = "0.12.0";
142
+ var version = "0.14.0";
143
143
 
144
144
  // src/http/client.ts
145
145
  var PKG_VERSION = version;
@@ -457,22 +457,33 @@ var listRankRadarsTool = {
457
457
  // src/tools/get-rank-radar-data.ts
458
458
  import { z as z7 } from "zod";
459
459
  var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
460
+ var RANK_RADAR_KEYWORDS_MAX_PAGE_SIZE = 100;
461
+ var RANK_RADAR_MAX_DATE_RANGE_DAYS = 90;
460
462
  var inputSchema7 = {
461
463
  rankRadarId: z7.string().uuid().describe("The Rank Radar UUID (from `list_rank_radars`)."),
462
464
  startDate: z7.string().regex(ISO_DATE, "startDate must be in yyyy-mm-dd format").describe("Start date for the ranking data range, yyyy-mm-dd (e.g. 2024-03-26)."),
463
- endDate: z7.string().regex(ISO_DATE, "endDate must be in yyyy-mm-dd format").describe("End date for the ranking data range, yyyy-mm-dd (e.g. 2024-04-26). Must be on or after startDate.")
465
+ endDate: z7.string().regex(ISO_DATE, "endDate must be in yyyy-mm-dd format").describe(
466
+ `End date for the ranking data range, yyyy-mm-dd (e.g. 2024-04-26). Must be on or after startDate, and at most ${RANK_RADAR_MAX_DATE_RANGE_DAYS} days after it.`
467
+ ),
468
+ currentPage: z7.number().int().min(1).optional().describe("Page of keywords, 1-indexed. Defaults to 1."),
469
+ pageSize: z7.number().int().min(1).max(RANK_RADAR_KEYWORDS_MAX_PAGE_SIZE).optional().describe(`Keywords per page (max ${RANK_RADAR_KEYWORDS_MAX_PAGE_SIZE}). Defaults to 20.`)
464
470
  };
465
471
  var getRankRadarDataTool = {
466
472
  name: "get_rank_radar_data",
467
473
  title: "Get Keyword Rankings for a Rank Radar",
468
- description: "Use this to analyze keyword ranking trends over time. Requires startDate and endDate (yyyy-mm-dd). Retrieves historical keyword ranking data for the specified Rank Radar within the date range. Returns an array of tracked keywords; each has id, keyword, searchVolume, ranks (per-day { date, organicRank, impressionRank }), and any highlight annotations. Use after `list_rank_radars` to discover a `rankRadarId`.",
474
+ description: `Use this to analyze keyword ranking trends over time. Requires startDate and endDate (yyyy-mm-dd), at most ${RANK_RADAR_MAX_DATE_RANGE_DAYS} days apart. Retrieves historical keyword ranking data for the specified Rank Radar within the date range. Results are paged by keyword: \`data\` holds one page of tracked keywords, and the response carries currentPage, pageSize, total, lastPage, hasNext and hasPrev. \`total\` is the Rank Radar's keyword count; to read every keyword, call again with \`currentPage\` + 1 while \`hasNext\` is true, using \`pageSize\` ${RANK_RADAR_KEYWORDS_MAX_PAGE_SIZE} for large Rank Radars. Each keyword has id, keyword, searchVolume, relevancy, ranks (per-day { date, organicRank, sponsoredRank, impressionRank }), and any highlight annotations. Paused keywords are not included. Use after \`list_rank_radars\` to discover a \`rankRadarId\`.`,
469
475
  inputSchema: inputSchema7,
470
476
  annotations: { readOnlyHint: true },
471
477
  handler: async (args, ctx) => {
472
478
  return await httpGet(
473
479
  { config: ctx.config, toolName: "get_rank_radar_data" },
474
480
  `/v1/niches/rank-radars/${encodeURIComponent(args.rankRadarId)}`,
475
- { startDate: args.startDate, endDate: args.endDate }
481
+ {
482
+ startDate: args.startDate,
483
+ endDate: args.endDate,
484
+ currentPage: args.currentPage,
485
+ pageSize: args.pageSize
486
+ }
476
487
  );
477
488
  }
478
489
  };
@@ -481,16 +492,24 @@ var getRankRadarDataTool = {
481
492
  import { z as z8 } from "zod";
482
493
 
483
494
  // src/tools/confirm.ts
484
- function requireConfirmation(confirm, ctx, costNote) {
485
- if (confirm === true || ctx.config.autoConfirmWrites) return null;
495
+ function needsConfirmation(confirm, ctx) {
496
+ return !(confirm === true || ctx.config.autoConfirmWrites);
497
+ }
498
+ function confirmationRequired(costNote, warnings) {
486
499
  return {
487
500
  status: "confirmation_required",
488
501
  message: "This action spends billable tokens and cannot be undone. Confirm the cost with the user, then call again with `confirm: true` to proceed.",
489
- costNote
502
+ costNote,
503
+ ...warnings && warnings.length > 0 ? { warnings } : {}
490
504
  };
491
505
  }
506
+ function requireConfirmation(confirm, ctx, costNote) {
507
+ if (!needsConfirmation(confirm, ctx)) return null;
508
+ return confirmationRequired(costNote);
509
+ }
492
510
 
493
511
  // src/tools/create-rank-radar.ts
512
+ var PATH = "/v1/niches/rank-radars";
494
513
  var inputSchema8 = {
495
514
  asin: z8.string().min(1).describe("The ASIN to track keyword rankings for."),
496
515
  numberOfKeywords: z8.number().int().min(1).describe("How many keywords to track (minimum 1). More keywords = broader tracking but more Search Term tokens."),
@@ -502,28 +521,28 @@ var inputSchema8 = {
502
521
  var createRankRadarTool = {
503
522
  name: "create_rank_radar",
504
523
  title: "Create a Rank Radar",
505
- description: "Use this to start tracking organic and sponsored keyword rankings for an ASIN within a niche. \u26A0\uFE0F Spends Search Term tokens (cost scales with `numberOfKeywords`) and cannot be undone \u2014 set `confirm: true` only after the user approves the cost. Not safe to retry: each call spends tokens again and creates a separate Rank Radar \u2014 if a call errors or times out, check `list_rank_radars` instead of re-calling. Returns the new `rankRadarId`; read its data later with `get_rank_radar_data`. Requires `asin`, `numberOfKeywords` (min 1), and a `nicheId` from `list_niches`.",
524
+ description: "Use this to start tracking organic and sponsored keyword rankings for an ASIN within a niche. \u26A0\uFE0F Spends Search Term tokens (cost scales with `numberOfKeywords`) and cannot be undone \u2014 set `confirm: true` only after the user approves the cost. Not safe to retry: each call spends tokens again and creates a separate Rank Radar \u2014 if a call errors or times out, check `list_rank_radars` instead of re-calling. The first call previews the creation and may return `warnings` alongside the cost note \u2014 for example that this product family is already tracked by another Rank Radar. Show every warning `message` to the user verbatim, before asking them to confirm; do not summarise it or decide on their behalf. A warning never blocks creation. Returns the new `rankRadarId`; read its data later with `get_rank_radar_data`. Requires `asin`, `numberOfKeywords` (min 1), and a `nicheId` from `list_niches`.",
506
525
  inputSchema: inputSchema8,
507
526
  // destructiveHint is technically "additive" here (this creates a new Rank Radar, it
508
527
  // doesn't destroy data), but we flag it destructive so clients prompt before the
509
528
  // irreversible token spend. The confirm gate enforces this server-side regardless.
510
529
  annotations: { readOnlyHint: false, destructiveHint: true, openWorldHint: false },
511
530
  handler: async (args, ctx) => {
512
- const pending = requireConfirmation(
513
- args.confirm,
514
- ctx,
515
- `Creating this Rank Radar consumes Search Term tokens \u2014 one per keyword tracked (${args.numberOfKeywords} requested).`
516
- );
517
- if (pending) return pending;
518
- return await httpPost(
519
- { config: ctx.config, toolName: "create_rank_radar" },
520
- "/v1/niches/rank-radars",
521
- {
522
- asin: args.asin,
523
- numberOfKeywords: args.numberOfKeywords,
524
- nicheId: args.nicheId
525
- }
526
- );
531
+ const request = { config: ctx.config, toolName: "create_rank_radar" };
532
+ const body = {
533
+ asin: args.asin,
534
+ numberOfKeywords: args.numberOfKeywords,
535
+ nicheId: args.nicheId
536
+ };
537
+ if (needsConfirmation(args.confirm, ctx)) {
538
+ const preview = await httpPost(request, PATH, { ...body, dryRun: true });
539
+ if (preview.rankRadarId != null) return preview;
540
+ return confirmationRequired(
541
+ `Creating this Rank Radar consumes Search Term tokens \u2014 one per keyword tracked (${args.numberOfKeywords} requested).`,
542
+ preview.warnings
543
+ );
544
+ }
545
+ return await httpPost(request, PATH, body);
527
546
  }
528
547
  };
529
548