@hunt-labs/bytekit-mcp 0.1.3 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,69 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  This file records only the delta between versions. For how to use the package
9
9
  today, see [README.md](./README.md), which remains the authoritative usage guide.
10
10
 
11
+ ## [0.2.1] - 2026-07-24
12
+
13
+ ### Fixed
14
+
15
+ - The spec'd flat `/v1/search` 502 error body (`{"error":"search_provider_error"}`)
16
+ now surfaces its code in the tool error text instead of collapsing to a generic
17
+ "ByteKit API error (HTTP 502)". Flat `{error: "<string>"}` bodies on any status
18
+ parse the same way; envelope-shaped bodies keep winning when both shapes are
19
+ present. (#2541)
20
+
21
+ ### Added
22
+
23
+ - `BytekitClient` accepts a `timeoutMs` constructor option — a per-request budget in
24
+ milliseconds, defaulting to `120000`. Set `0` to disable it entirely. Values that are
25
+ negative or non-finite normalize to disabled rather than throwing. Previously a hung
26
+ upstream hung a stdio MCP tool call forever. (#2568)
27
+ - The budget covers an **entire** `request()` call rather than each await separately:
28
+ the initial fetch, the 429 `Retry-After` sleep, the retry fetch, **and both** the
29
+ success and error body reads (`response.json()` in `request()` and in
30
+ `parseErrorEnvelope`). Two of those previously swallowed an abort outright — the
31
+ `Retry-After` sleep observed no signal, and a failed error-body read was downgraded to
32
+ "no envelope", surfacing a misleading status-line message instead of the timeout.
33
+ Exhausting the budget now produces a `BytekitApiError` with
34
+ `errorCode: 'timeout'`, distinct from `'network_error'`. (#2568)
35
+ - Note the semantics are **client-side only**: aborting does not cancel or refund
36
+ server-side work already in progress, so an account may still be billed for a result
37
+ the caller never reads. The `120000` default is deliberately well above the server-side
38
+ screenshot ceiling so it never truncates a legitimate billable operation. (#2568)
39
+
40
+ ## [0.2.0] - 2026-07-21
41
+
42
+ ### Removed (**BREAKING**)
43
+
44
+ - The legacy `RAPIDCRAWL_API_KEY` environment-variable fallback (kept as a
45
+ one-minor-version bridge in #2421) is removed. Use `BYTEKIT_API_KEY` (or the
46
+ `--api-key` flag). (#2473)
47
+
48
+ ### Fixed
49
+
50
+ - Tool-surface drift against the live API (#2477):
51
+ - `screenshot_url`'s `device` enum is now `desktop` / `mobile` — `tablet` was
52
+ 422-rejected by the API.
53
+ - Screenshot results render the spec field names (`image_width`,
54
+ `image_height`, `file_size_bytes`); the removed `format` field is gone.
55
+ - `get_result` renders a failed job's envelope (`Status: failed` +
56
+ `error.code`/`error.message`) instead of `undefined` lines, and omits
57
+ `Credits: null` for pending rows.
58
+ - `get_account` no longer renders `Account: null` when the account has no
59
+ name.
60
+ - `get_doc`'s description example uses a real bundle key.
61
+ - Server errors now surface diagnostics instead of a generic failure: any
62
+ non-2xx with a parseable API envelope renders its `code` + `message`
63
+ (e.g. 503 `blocked`, 400 `invalid_url`), 422 includes `error.details`, and
64
+ `Retry-After` (including HTTP-date or garbage values) is parsed to a bounded
65
+ retry delay instead of `setTimeout(NaN)`. Specific 401/402/429 mappings still
66
+ win. (#2478)
67
+
68
+ ### Changed
69
+
70
+ - The bundled offline docs (`get_doc`/`list_docs`/`search_docs`) are
71
+ regenerated: 96 pages, now including the TypeScript SDK `usage` and
72
+ `webhooks` reference pages and dropping removed content. (#2469)
73
+
11
74
  ## [0.1.3] - 2026-07-16
12
75
 
13
76
  ### Changed (**BREAKING**)
@@ -59,6 +122,7 @@ today, see [README.md](./README.md), which remains the authoritative usage guide
59
122
  (scrape, screenshot, search, docs) to AI agents over the Model Context Protocol,
60
123
  as a local stdio server or hosted.
61
124
 
125
+ [0.2.0]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
62
126
  [0.1.3]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
63
127
  [0.1.2]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
64
128
  [0.1.1]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
package/README.md CHANGED
@@ -84,25 +84,23 @@ Client config for a stdio server (`claude_desktop_config.json` and equivalents):
84
84
 
85
85
  ### API-key resolution order
86
86
 
87
- The local server resolves the key in this order, so a legacy setup keeps
88
- working:
87
+ The local server resolves the key in this order:
89
88
 
90
89
  1. `--api-key <key>` flag
91
90
  2. `BYTEKIT_API_KEY` environment variable
92
- 3. `RAPIDCRAWL_API_KEY` environment variable (legacy fallback)
93
91
 
94
92
  ## Tool inventory
95
93
 
96
- | Tool | What it does |
97
- | ---------------- | -------------------------------------------------------------- |
98
- | `scrape_url` | Fetch a URL and return HTML, clean markdown, links, or images. |
99
- | `web-search` | Run a web search and return ranked organic results. |
100
- | `screenshot_url` | Capture a screenshot of a page (desktop/mobile, PNG/JPEG). |
101
- | `get_result` | Fetch a previously created screenshot by id. |
102
- | `get_account` | Return account details, plan, and current usage/quota. |
103
- | `list_docs` | List every page in the bundled ByteKit documentation. |
104
- | `search_docs` | Search the bundled documentation. |
105
- | `get_doc` | Fetch the full markdown of one documentation page. |
94
+ | Tool | What it does |
95
+ | ---------------- | ---------------------------------------------------------------------- |
96
+ | `scrape_url` | Fetch a URL and return HTML, clean markdown, links, or images. |
97
+ | `web_search` | Run a web search and return ranked organic results. |
98
+ | `screenshot_url` | Capture a screenshot of a page (desktop/mobile, PNG/JPEG). |
99
+ | `get_result` | Fetch a previously created screenshot (`ss_`) or scrape (`sc_`) by id. |
100
+ | `get_account` | Return account details, plan, and current usage/quota. |
101
+ | `list_docs` | List every page in the bundled ByteKit documentation. |
102
+ | `search_docs` | Search the bundled documentation. |
103
+ | `get_doc` | Fetch the full markdown of one documentation page. |
106
104
 
107
105
  The server also exposes **resources** (`bytekit://account`,
108
106
  `bytekit://screenshot/{id}`) and **prompts** (`summarize_webpage`,
package/dist/cli.d.ts CHANGED
@@ -9,10 +9,9 @@
9
9
  /**
10
10
  * Resolve the API key from, in precedence order:
11
11
  * 1. the `--api-key` flag
12
- * 2. the `BYTEKIT_API_KEY` env var (the current signal)
13
- * 3. the `RAPIDCRAWL_API_KEY` env var (legacy fallback, kept working)
12
+ * 2. the `BYTEKIT_API_KEY` env var
14
13
  *
15
- * An empty-string / absent flag falls through to the env vars. Returns
14
+ * An empty-string / absent flag falls through to the env var. Returns
16
15
  * `undefined` when no usable key is present.
17
16
  *
18
17
  * Exported (and factored out of the CLI bootstrap) so the precedence contract
@@ -35,13 +34,12 @@ export declare const DEFAULT_BASE_URL = "https://api.bytekit.com";
35
34
  * Mirrors {@link resolveApiKey}'s shape (empty/absent flag falls through). This is the single
36
35
  * base-URL resolution site for the binary; the `parseArgs` option deliberately carries NO
37
36
  * `default:` so an absent flag yields `undefined` here rather than shadowing the env fallback.
38
- * The MCP server never had a legacy `RAPIDCRAWL_BASE_URL` var, so none is honored.
39
37
  */
40
38
  export declare function resolveBaseUrl(opts: {
41
39
  flag?: string | undefined;
42
40
  env: Record<string, string | undefined>;
43
41
  }): string;
44
- export declare const HELP_TEXT = "ByteKit MCP Server\n\nUsage:\n bytekit-mcp --api-key <key> [--base-url <url>] [--verbose]\n\nOptions:\n --api-key ByteKit API key. Resolution order: --api-key flag, then\n BYTEKIT_API_KEY, then RAPIDCRAWL_API_KEY (legacy fallback).\n --base-url API base URL. Resolution order: --base-url flag, then\n BYTEKIT_BASE_URL (default: https://api.bytekit.com)\n --verbose Log requests to stderr\n --help Show this help message\n";
42
+ export declare const HELP_TEXT = "ByteKit MCP Server\n\nUsage:\n bytekit-mcp --api-key <key> [--base-url <url>] [--verbose]\n\nOptions:\n --api-key ByteKit API key. Resolution order: --api-key flag, then\n BYTEKIT_API_KEY.\n --base-url API base URL. Resolution order: --base-url flag, then\n BYTEKIT_BASE_URL (default: https://api.bytekit.com)\n --verbose Log requests to stderr\n --help Show this help message\n";
45
43
  /**
46
44
  * True when this module is the process entrypoint (run directly or via its bin),
47
45
  * false when it is merely imported (e.g. the test suite exercising resolveApiKey).
package/dist/cli.js CHANGED
@@ -14,10 +14,9 @@ import { createServer, BytekitClient } from './index.js';
14
14
  /**
15
15
  * Resolve the API key from, in precedence order:
16
16
  * 1. the `--api-key` flag
17
- * 2. the `BYTEKIT_API_KEY` env var (the current signal)
18
- * 3. the `RAPIDCRAWL_API_KEY` env var (legacy fallback, kept working)
17
+ * 2. the `BYTEKIT_API_KEY` env var
19
18
  *
20
- * An empty-string / absent flag falls through to the env vars. Returns
19
+ * An empty-string / absent flag falls through to the env var. Returns
21
20
  * `undefined` when no usable key is present.
22
21
  *
23
22
  * Exported (and factored out of the CLI bootstrap) so the precedence contract
@@ -26,7 +25,7 @@ import { createServer, BytekitClient } from './index.js';
26
25
  */
27
26
  export function resolveApiKey(opts) {
28
27
  const flag = opts.flag && opts.flag.length > 0 ? opts.flag : undefined;
29
- return flag ?? opts.env['BYTEKIT_API_KEY'] ?? opts.env['RAPIDCRAWL_API_KEY'];
28
+ return flag ?? opts.env['BYTEKIT_API_KEY'];
30
29
  }
31
30
  export const API_KEY_REQUIRED_MESSAGE = 'Error: API key required. Use --api-key or set the BYTEKIT_API_KEY environment variable.\n';
32
31
  /** The API host the server defaults to when no flag and no env var resolve a base URL. */
@@ -40,7 +39,6 @@ export const DEFAULT_BASE_URL = 'https://api.bytekit.com';
40
39
  * Mirrors {@link resolveApiKey}'s shape (empty/absent flag falls through). This is the single
41
40
  * base-URL resolution site for the binary; the `parseArgs` option deliberately carries NO
42
41
  * `default:` so an absent flag yields `undefined` here rather than shadowing the env fallback.
43
- * The MCP server never had a legacy `RAPIDCRAWL_BASE_URL` var, so none is honored.
44
42
  */
45
43
  export function resolveBaseUrl(opts) {
46
44
  const flag = opts.flag && opts.flag.length > 0 ? opts.flag : undefined;
@@ -53,7 +51,7 @@ Usage:
53
51
 
54
52
  Options:
55
53
  --api-key ByteKit API key. Resolution order: --api-key flag, then
56
- BYTEKIT_API_KEY, then RAPIDCRAWL_API_KEY (legacy fallback).
54
+ BYTEKIT_API_KEY.
57
55
  --base-url API base URL. Resolution order: --base-url flag, then
58
56
  BYTEKIT_BASE_URL (default: https://api.bytekit.com)
59
57
  --verbose Log requests to stderr
package/dist/client.d.ts CHANGED
@@ -55,27 +55,36 @@ export interface SearchResponse {
55
55
  export interface ScreenshotParams {
56
56
  url: string;
57
57
  full_page?: boolean | undefined;
58
- device?: 'desktop' | 'mobile' | 'tablet' | undefined;
58
+ device?: 'desktop' | 'mobile' | undefined;
59
59
  format?: 'png' | 'jpeg' | undefined;
60
60
  }
61
+ /** Nested error shape carried by the #2027 failed-screenshot envelope. */
62
+ export interface ScreenshotError {
63
+ code?: string;
64
+ message?: string;
65
+ http_status?: number;
66
+ failed_at?: string;
67
+ }
61
68
  export interface ScreenshotResult {
62
- id: string;
63
- url: string;
69
+ id?: string;
70
+ url?: string;
64
71
  status: string;
65
- image_url?: string;
66
- width?: number;
67
- height?: number;
68
- format?: string;
69
- file_size?: number;
70
- credits_charged?: number;
72
+ image_url?: string | null;
73
+ page_title?: string | null;
74
+ image_width?: number | null;
75
+ image_height?: number | null;
76
+ file_size_bytes?: number | null;
77
+ credits_charged?: number | null;
78
+ /** Present only on the #2027 failed envelope. */
79
+ error?: ScreenshotError;
71
80
  created_at?: string;
72
- completed_at?: string;
73
- expires_at?: string;
81
+ completed_at?: string | null;
82
+ expires_at?: string | null;
74
83
  }
75
84
  export interface AccountResult {
76
85
  id: string;
77
86
  email: string;
78
- name: string;
87
+ name: string | null;
79
88
  plan: {
80
89
  id: string;
81
90
  slug: string;
@@ -107,6 +116,19 @@ export declare class BytekitApiError extends Error {
107
116
  readonly errorCode?: string | undefined;
108
117
  constructor(message: string, statusCode: number, errorCode?: string | undefined);
109
118
  }
119
+ /**
120
+ * Parse an HTTP `Retry-After` header into a bounded delay in milliseconds.
121
+ *
122
+ * Handles all three real-world forms without ever producing `NaN`:
123
+ * - delta-seconds (e.g. `"120"`) → seconds × 1000
124
+ * - HTTP-date (e.g. `"Wed, 21 Oct 2026 07:28:00 GMT"`) → milliseconds until that instant
125
+ * - absent / garbage → {@link DEFAULT_RETRY_AFTER_MS}
126
+ *
127
+ * The result is always clamped to `[0, MAX_RETRY_AFTER_MS]`. Before this guard,
128
+ * an HTTP-date header flowed through `parseInt` → `NaN` → `setTimeout(NaN)`,
129
+ * collapsing the backoff to an immediate retry (issue #2478).
130
+ */
131
+ export declare function parseRetryAfterMs(headerValue: string | null | undefined): number;
110
132
  export declare class BytekitClient {
111
133
  private readonly baseUrl;
112
134
  private readonly apiKey;
@@ -118,13 +140,47 @@ export declare class BytekitClient {
118
140
  * call time so tests can stub `globalThis.fetch` without constructing a new client.
119
141
  */
120
142
  private readonly fetchFn;
143
+ /**
144
+ * Normalized per-request budget in milliseconds; `0` means disabled. Resolved once
145
+ * here so every `request()` reads a value already known to be safe to hand to
146
+ * `AbortSignal.timeout`.
147
+ */
148
+ private readonly timeoutMs;
121
149
  constructor(options: {
122
150
  apiKey: string;
123
151
  baseUrl?: string;
124
152
  verbose?: boolean;
153
+ /**
154
+ * Budget (ms) for an ENTIRE `request()` call -- the initial fetch, the 429
155
+ * `Retry-After` sleep, the retry fetch, and both the success and error body reads.
156
+ * Not per-await. Defaults to {@link DEFAULT_TIMEOUT_MS}; `0` disables it entirely.
157
+ * Values `<= 0` or non-finite normalize to disabled; oversized values are clamped
158
+ * to {@link MAX_TIMEOUT_MS}.
159
+ */
160
+ timeoutMs?: number;
125
161
  fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
126
162
  });
163
+ /**
164
+ * The distinct error a budget exhaustion produces. `statusCode: 0` mirrors the
165
+ * existing `network_error` convention for failures that never produced an HTTP
166
+ * status, and `timeout` keeps the two classes distinguishable to callers.
167
+ *
168
+ * The message interpolates only the numeric budget -- no URL, header, body, or API
169
+ * key -- because every tool's catch block renders this text straight to the agent.
170
+ */
171
+ private timeoutError;
127
172
  scrape(params: ScrapeParams): Promise<ScrapeResult>;
173
+ /**
174
+ * Retrieve a previously created scrape by its `sc_` id
175
+ * (openapi.yaml `GET /v1/scrape/{id}`, operationId `getScrape`).
176
+ *
177
+ * Always answers HTTP 200 on an existing job — the `status` discriminator carries the
178
+ * state, so a still-running scrape arrives as a {@link ScrapeQueuedEnvelope} rather than
179
+ * a non-2xx. This is the redemption half of the async `scrape` handle: POST /v1/scrape
180
+ * may answer 202 with a queued envelope, and without this method that `sc_` id had no
181
+ * MCP-side retrieval path at all (issue #2538).
182
+ */
183
+ getScrape(id: string): Promise<ScrapeResult>;
128
184
  search(params: SearchParams): Promise<SearchResponse>;
129
185
  screenshot(params: ScreenshotParams): Promise<ScreenshotResult>;
130
186
  getScreenshot(id: string): Promise<ScreenshotResult>;
@@ -133,5 +189,16 @@ export declare class BytekitClient {
133
189
  private request;
134
190
  private post;
135
191
  private get;
192
+ /**
193
+ * Map a non-2xx `response` to a {@link BytekitApiError}.
194
+ *
195
+ * `path` is the request path (the caller's second `request` argument). It is threaded in
196
+ * so status mappings can be endpoint-aware: the 402 message differs between the
197
+ * bandwidth-billed capture endpoints and the credit-billed `/v1/search` (issue #2571).
198
+ *
199
+ * `signal` is the per-request timeout signal (#2568); it is forwarded into
200
+ * `parseErrorEnvelope` so an aborted error-body read surfaces as a timeout rather than a
201
+ * misleading status-line message.
202
+ */
136
203
  private handleErrorResponse;
137
204
  }