@kantadev/cli 0.1.1 → 0.1.3

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 CHANGED
@@ -38,6 +38,8 @@ npm link
38
38
  }
39
39
  ```
40
40
 
41
+ From 0.1.2, `npx -y @kantadev/cli mcp` works too (it's what the MCP registry entry runs).
42
+
41
43
  The server calls `GET /me` once at startup to learn the key scope. If the API is
42
44
  unreachable it still boots with the customer tool set (admin tools appear once
43
45
  `/me` succeeds).
@@ -184,7 +186,7 @@ See the config block at the top of this file. Admin tools appear in
184
186
 
185
187
  - Verify / Find / jobs: `kanta_verify_email`, `kanta_verify_bulk`,
186
188
  `kanta_find_email`, `kanta_find_bulk`, `kanta_jobs_list`, `kanta_job_get`,
187
- `kanta_job_results`, `kanta_job_cancel`, `kanta_job_delete`, `kanta_account`,
189
+ `kanta_job_results` (pass `output` to save every row to a CSV), `kanta_job_wait`, `kanta_job_cancel`, `kanta_job_resume`, `kanta_job_delete`, `kanta_account`,
188
190
  `kanta_credits`
189
191
  - Database: `kanta_db_count`, `kanta_db_search`, `kanta_db_facets`,
190
192
  `kanta_db_lookup`, `kanta_db_export`, `kanta_db_export_status`,
package/bin/kanta-mcp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // Kanta MCP stdio server entry point (`npx @kanta/cli kanta-mcp`).
2
+ // Kanta MCP stdio server entry point (`npx -y -p @kantadev/cli kanta-mcp`, or `npx -y @kantadev/cli mcp`).
3
3
  import { startServer } from '../src/mcp/server.js';
4
4
 
5
5
  startServer().catch((err) => {
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@kantadev/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Kanta CLI + MCP server — email verification, email finding, and the Kanta B2B contact database from your terminal or an MCP client.",
5
5
  "mcpName": "dev.kanta/cli",
6
6
  "type": "module",
7
7
  "bin": {
8
- "kanta": "./bin/kanta.js",
9
- "kanta-mcp": "./bin/kanta-mcp.js"
8
+ "cli": "bin/kanta.js",
9
+ "kanta": "bin/kanta.js",
10
+ "kanta-mcp": "bin/kanta-mcp.js"
10
11
  },
11
12
  "files": [
12
13
  "bin",
@@ -32,7 +33,7 @@
32
33
  "url": "git+https://github.com/griffinkanta/kanta-dev.git",
33
34
  "directory": "kanta-cli"
34
35
  },
35
- "homepage": "https://kanta.dev/developers",
36
+ "homepage": "https://kanta.dev/api-docs",
36
37
  "keywords": [
37
38
  "kanta",
38
39
  "email-verification",
package/server.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
3
  "name": "dev.kanta/cli",
4
- "description": "Email verification, email finding, and the Kanta B2B contact database — search, count, facet, and export contacts and companies.",
5
- "version": "0.1.1",
4
+ "description": "Kanta Verify, Find, and Database: email verification, email finding, and B2B contact search.",
5
+ "version": "0.1.3",
6
6
  "repository": {
7
7
  "url": "https://github.com/griffinkanta/kanta-dev",
8
8
  "source": "github",
@@ -12,9 +12,17 @@
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "@kantadev/cli",
15
- "version": "0.1.1",
15
+ "version": "0.1.3",
16
16
  "runtimeHint": "npx",
17
- "transport": { "type": "stdio" },
17
+ "packageArguments": [
18
+ {
19
+ "type": "positional",
20
+ "value": "mcp"
21
+ }
22
+ ],
23
+ "transport": {
24
+ "type": "stdio"
25
+ },
18
26
  "environmentVariables": [
19
27
  {
20
28
  "name": "KANTA_API_KEY",
package/src/cli/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { Command } from 'commander';
2
+ import { VERSION } from '../version.js';
3
+ import { updateNotice } from './updateNotice.js';
2
4
  import { defaultDeps } from './context.js';
3
5
  import { registerVerify } from './commands/verify.js';
4
6
  import { registerFind } from './commands/find.js';
@@ -16,7 +18,7 @@ export function createProgram(deps = {}) {
16
18
  program
17
19
  .name('kanta')
18
20
  .description('Kanta CLI — verify, find, and manage email jobs over api.kanta.dev')
19
- .version('0.1.1')
21
+ .version(VERSION)
20
22
  .option('--profile <name>', 'config profile to use')
21
23
  .option('--api-key <key>', 'API key (overrides profile/env; never persisted)')
22
24
  .option('--base-url <url>', 'API base URL override')
@@ -49,5 +51,10 @@ export function createProgram(deps = {}) {
49
51
  export async function run(argv = process.argv, deps = {}) {
50
52
  const program = createProgram(deps);
51
53
  await program.parseAsync(argv);
54
+ // The MCP server owns stdio; JSON output is for scripts. Neither gets the notice.
55
+ if (!argv.includes('--json') && !argv.includes('mcp')) {
56
+ const msg = await updateNotice({ current: VERSION }).catch(() => null);
57
+ if (msg) process.stderr.write(`\n${msg}\n`);
58
+ }
52
59
  return program;
53
60
  }
@@ -0,0 +1,49 @@
1
+ // Once-a-day "newer version on npm" notice for the CLI (never for the MCP server).
2
+ // Reads ~/.kanta/update-check.json; refreshes it from the npm registry when it is
3
+ // older than a day. Every failure is swallowed — this must never break a command.
4
+ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
5
+ import { join } from 'node:path';
6
+ import { configDir } from '../core/config.js';
7
+
8
+ const DAY_MS = 24 * 60 * 60 * 1000;
9
+ const LATEST_URL = 'https://registry.npmjs.org/@kantadev%2fcli/latest';
10
+
11
+ export function isNewer(candidate, current) {
12
+ const a = String(candidate).split('.').map(Number);
13
+ const b = String(current).split('.').map(Number);
14
+ for (let i = 0; i < 3; i += 1) {
15
+ if ((a[i] || 0) !== (b[i] || 0)) return (a[i] || 0) > (b[i] || 0);
16
+ }
17
+ return false;
18
+ }
19
+
20
+ export async function updateNotice({
21
+ current,
22
+ dir = configDir(),
23
+ env = process.env,
24
+ isTTY = Boolean(process.stderr.isTTY),
25
+ now = Date.now(),
26
+ fetchImpl = globalThis.fetch,
27
+ } = {}) {
28
+ if (env.KANTA_NO_UPDATE_NOTIFIER || env.CI || !isTTY) return null;
29
+ const file = join(dir, 'update-check.json');
30
+ let cache = {};
31
+ try { cache = JSON.parse(readFileSync(file, 'utf8')); } catch { /* no cache yet */ }
32
+
33
+ if (!cache.checked_at || now - cache.checked_at > DAY_MS) {
34
+ let latest = cache.latest || null;
35
+ try {
36
+ const res = await fetchImpl(LATEST_URL, { signal: AbortSignal.timeout(1500) });
37
+ if (res.ok) latest = (await res.json()).version || latest;
38
+ } catch { /* offline or slow: try again tomorrow */ }
39
+ cache = { checked_at: now, latest };
40
+ try {
41
+ mkdirSync(dir, { recursive: true });
42
+ writeFileSync(file, JSON.stringify(cache));
43
+ } catch { /* read-only home: skip caching */ }
44
+ }
45
+
46
+ if (!cache.latest || !isNewer(cache.latest, current)) return null;
47
+ return `A newer Kanta CLI is available: ${current} -> ${cache.latest}. ` +
48
+ 'Update with: npm install -g @kantadev/cli@latest';
49
+ }
@@ -2,7 +2,10 @@
2
2
  // One method per endpoint. Returns parsed JSON or throws KantaApiError.
3
3
  import { KantaApiError } from './errors.js';
4
4
 
5
- const RETRYABLE = new Set([429, 503]);
5
+ // 429 is deliberately not retried here — the verifier fleet's own throughput
6
+ // is the bottleneck at Kanta's real volumes, not the API's request-rate limiter,
7
+ // and retrying a rate limit on a fixed delay only compounds backlog under load.
8
+ const RETRYABLE = new Set([503]);
6
9
 
7
10
  export class KantaClient {
8
11
  constructor({
package/src/mcp/server.js CHANGED
@@ -12,6 +12,7 @@ import { KantaClient } from '../core/client.js';
12
12
  import { resolveKey } from '../core/auth.js';
13
13
  import { whoami } from '../core/identity.js';
14
14
  import { buildToolList, wrapHandler } from './register.js';
15
+ import { VERSION } from '../version.js';
15
16
 
16
17
  // Resolve the caller's scope via GET /me, but never block startup on it:
17
18
  // the server must boot offline (first-run UX, sandboxed clients). On any
@@ -20,10 +21,12 @@ export async function resolveIdentity() {
20
21
  try {
21
22
  return await whoami({});
22
23
  } catch (err) {
23
- process.stderr.write(
24
- `kanta-mcp: could not verify identity (${err?.message || err}); ` +
25
- 'starting with customer tools only. Admin tools appear once the API is reachable.\n',
26
- );
24
+ const rejected = err?.status === 401 || err?.status === 403;
25
+ process.stderr.write(rejected
26
+ ? `kanta-mcp: the API rejected your API key (${err?.code || err?.message || err}). ` +
27
+ 'Check KANTA_API_KEY (or your profile); every tool call will fail until it is fixed.\n'
28
+ : `kanta-mcp: could not verify identity (${err?.message || err}); ` +
29
+ 'starting with customer tools only. Admin tools appear once the API is reachable.\n');
27
30
  return { scope: 'user', offline: true };
28
31
  }
29
32
  }
@@ -38,7 +41,7 @@ export async function startServer() {
38
41
  const handlers = new Map(tools.map(t => [t.name, wrapHandler(t, { client })]));
39
42
 
40
43
  const server = new Server(
41
- { name: 'kanta', version: '0.1.1' },
44
+ { name: 'kanta', version: VERSION },
42
45
  { capabilities: { tools: {} } },
43
46
  );
44
47
 
@@ -1,10 +1,14 @@
1
1
  // Customer MCP tools. Each entry: { name, description, inputSchema, handler }.
2
2
  // handler(args, { client }) -> any JSON-serialisable value.
3
- import { readFileSync } from 'node:fs';
3
+ import { readFileSync, writeFileSync } from 'node:fs';
4
+ import { resolve } from 'node:path';
5
+ import { toCsv } from '../../cli/format.js';
4
6
  import { parse as csvParse } from 'csv-parse/sync';
5
7
  import { databaseTools } from './database.js';
6
8
 
7
9
  const INLINE_ROW_CAP = 100;
10
+ const FINAL_STATUSES = new Set(['complete', 'failed', 'cancelled', 'paused']);
11
+ const realSleep = (ms) => new Promise((r) => setTimeout(r, ms));
8
12
 
9
13
  function loadEmails(args) {
10
14
  if (Array.isArray(args.emails)) return args.emails.filter(Boolean);
@@ -30,7 +34,7 @@ function capResults(out) {
30
34
  return {
31
35
  job_id: out.job_id,
32
36
  total: out.total,
33
- note: `${rows.length} rows — too many to return inline. Re-run with an "output" path or use the CLI: kanta jobs results ${out.job_id} -o results.csv`,
37
+ note: `${rows.length} rows — too many to return inline. Re-run with an "output" file path to save every row, or use the CLI: kanta jobs results ${out.job_id} -o results.csv`,
34
38
  sample: rows.slice(0, INLINE_ROW_CAP),
35
39
  };
36
40
  }
@@ -40,7 +44,7 @@ function capResults(out) {
40
44
  export const customerTools = [
41
45
  {
42
46
  name: 'kanta_verify_email',
43
- description: 'Verify a single email address. Returns status (valid/invalid/risky/unknown) and signal flags.',
47
+ description: 'Verify a single email address. Returns status (valid/invalid/risky/catch_all/disposable/unknown) and signal flags.',
44
48
  inputSchema: {
45
49
  type: 'object',
46
50
  properties: { email: { type: 'string', description: 'Email address to verify' } },
@@ -129,13 +133,54 @@ export const customerTools = [
129
133
  },
130
134
  {
131
135
  name: 'kanta_job_results',
132
- description: 'Fetch job results. Inline output is capped at 100 rows; larger jobs return a sample and a CLI hint.',
136
+ description:
137
+ 'Fetch job results. Inline output is capped at 100 rows (larger jobs return a sample). ' +
138
+ 'Pass "output" (a local file path) to write every row to a CSV instead; you get back the row count.',
139
+ inputSchema: {
140
+ type: 'object',
141
+ properties: {
142
+ id: { type: 'string' },
143
+ output: { type: 'string', description: 'Local CSV path to write all rows to (overwritten if it exists)' },
144
+ },
145
+ required: ['id'],
146
+ },
147
+ handler: async (a, { client }) => {
148
+ const out = await client.getJobResults(a.id);
149
+ if (!a.output) return capResults(out);
150
+ if (!out || !Array.isArray(out.results)) {
151
+ throw new Error(`Job not complete (status: ${out?.status ?? 'unknown'}); nothing written.`);
152
+ }
153
+ const path = resolve(a.output);
154
+ writeFileSync(path, toCsv(out.results));
155
+ return { job_id: out.job_id ?? a.id, rows_written: out.results.length, output: path };
156
+ },
157
+ },
158
+ {
159
+ name: 'kanta_job_wait',
160
+ description:
161
+ 'Wait for a job to finish (complete, failed, cancelled, or paused) and return its final state. ' +
162
+ 'Use this instead of calling kanta_job_get repeatedly. Default timeout 10 minutes, max 60.',
133
163
  inputSchema: {
134
164
  type: 'object',
135
- properties: { id: { type: 'string' } },
165
+ properties: {
166
+ id: { type: 'string' },
167
+ timeout_seconds: { type: 'integer', minimum: 1, maximum: 3600, description: 'default 600' },
168
+ interval_seconds: { type: 'integer', minimum: 2, maximum: 60, description: 'poll interval, default 5' },
169
+ },
136
170
  required: ['id'],
137
171
  },
138
- handler: async (a, { client }) => capResults(await client.getJobResults(a.id)),
172
+ handler: async (a, { client, sleep = realSleep, now = Date.now }) => {
173
+ const timeoutMs = Math.min(a.timeout_seconds ?? 600, 3600) * 1000;
174
+ const intervalMs = Math.max(a.interval_seconds ?? 5, 2) * 1000;
175
+ const started = now();
176
+ for (;;) {
177
+ const job = await client.getJob(a.id);
178
+ const waited = Math.round((now() - started) / 1000);
179
+ if (FINAL_STATUSES.has(job.status)) return { ...job, waited_seconds: waited, timed_out: false };
180
+ if (now() - started + intervalMs > timeoutMs) return { ...job, waited_seconds: waited, timed_out: true };
181
+ await sleep(intervalMs);
182
+ }
183
+ },
139
184
  },
140
185
  {
141
186
  name: 'kanta_job_cancel',
@@ -143,6 +188,12 @@ export const customerTools = [
143
188
  inputSchema: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] },
144
189
  handler: (a, { client }) => client.cancelJob(a.id),
145
190
  },
191
+ {
192
+ name: 'kanta_job_resume',
193
+ description: 'Resume a paused job.',
194
+ inputSchema: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] },
195
+ handler: (a, { client }) => client.resumeJob(a.id),
196
+ },
146
197
  {
147
198
  name: 'kanta_job_delete',
148
199
  description: 'Delete a finished job.',
@@ -10,7 +10,11 @@ const FILTER_SCHEMA = {
10
10
  'Kanta DB person filter. Keys: query (free text), seniority[] (C-Suite, VP, Director, Manager, …), ' +
11
11
  'function[], title, title_exact[], person_country[], person_state[], company, company_domain[], ' +
12
12
  'industry[], employee_range[] (e.g. "51-200"), has_email, has_linkedin, has_phone. ' +
13
- 'verification_status[] is admin-only. All list keys accept a bare string too.',
13
+ 'verification_status[] is admin-only. All list keys accept a bare string too. ' +
14
+ 'Values must match the stored labels exactly (case-sensitive), and one concept often has ' +
15
+ 'several labels (e.g. "computer software", "Software Development", "custom software & it services"). ' +
16
+ 'Before filtering on industry, function, seniority, or location, call kanta_db_facets on that ' +
17
+ 'field to see the real values, then pass every relevant one as a list.',
14
18
  };
15
19
 
16
20
  const COMPANY_FILTER_SCHEMA = {
@@ -19,7 +23,8 @@ const COMPANY_FILTER_SCHEMA = {
19
23
  description:
20
24
  'Kanta DB company filter. Keys: query, domain[], industry[], employee_range[], hq_country[], ' +
21
25
  'hq_state[], funding_stage[], employees_min, employees_max, revenue_min_k, revenue_max_k, ' +
22
- 'founded_after (year), min_contacts.',
26
+ 'founded_after (year), min_contacts. Values match stored labels exactly (case-sensitive); call ' +
27
+ 'kanta_db_companies_facets on a field first to see the real values and pass every relevant one.',
23
28
  };
24
29
 
25
30
  function errResult(text) {
package/src/version.js ADDED
@@ -0,0 +1,4 @@
1
+ // Single source of truth for the package version (read from package.json, which npm ships).
2
+ import { readFileSync } from 'node:fs';
3
+
4
+ export const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;