@hunt-labs/bytekit-mcp 0.2.2 → 0.2.4
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 +112 -0
- package/README.md +66 -20
- package/dist/cli.d.ts +14 -9
- package/dist/cli.js +20 -16
- package/dist/client.d.ts +43 -3
- package/dist/client.js +101 -3
- package/dist/docs-bundle/docs-bundle.json +12 -12
- package/dist/lib/render-scrape.d.ts +4 -2
- package/dist/lib/render-scrape.js +102 -18
- package/dist/lib/render-screenshot.js +16 -0
- package/dist/lib/truncate.d.ts +38 -1
- package/dist/lib/truncate.js +98 -3
- package/dist/resources/account.js +7 -1
- package/dist/tools/list-docs.d.ts +10 -0
- package/dist/tools/list-docs.js +21 -0
- package/dist/tools/scrape-url.d.ts +25 -0
- package/dist/tools/scrape-url.js +35 -2
- package/dist/tools/screenshot-url.js +40 -0
- package/dist/tools/web-search.js +10 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,118 @@ today, see [README.md](./README.md), which remains the authoritative usage guide
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [0.2.4] - 2026-08-10
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Version-alignment release after the 2026-08-10 publish rescue: the published 0.2.3 artifact was built from the `main` promotion HEAD, which already contained every change documented under the 0.2.3 heading — but that commit postdates the one that introduced the 0.2.3 version string, so the `check-release-drift` gate (#2680) correctly reported shipped drift on every subsequent CI run (#2829). 0.2.4 realigns manifest ↔ registry ↔ version-introducing commit. **No consumer-visible change relative to the published 0.2.3.**
|
|
18
|
+
|
|
19
|
+
## [0.2.3] - 2026-08-07
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
- `scrape_url` / `get_result` render a zero-count `Links (0):` / `Images (0):` header for
|
|
24
|
+
a format you requested that came back empty, so "the page has none" is no longer
|
|
25
|
+
indistinguishable from "the format was not returned". A format you did not request
|
|
26
|
+
still renders nothing at all. (#2687)
|
|
27
|
+
- The queued-scrape render carries the spec-required `events` array, and the success
|
|
28
|
+
render carries `content_length` — the compressed upstream wire-byte count that is the
|
|
29
|
+
billing basis for the call, which nothing else in the output surfaced. (#2687)
|
|
30
|
+
- Screenshot renders carry `page_title` (a spec field the tool description already
|
|
31
|
+
promised as "metadata") and a note that `image_url` is a signed link with a short
|
|
32
|
+
lifetime, using the concrete `expires_at` instant when the API supplies one. (#2687)
|
|
33
|
+
- A queued scrape now gets the same "Use `get_result` with this ID to check when it
|
|
34
|
+
completes." guidance a pending screenshot got in 0.2.2. (#2687)
|
|
35
|
+
- `screenshot_url` exposes `quality`, `dark_mode`, `country` and `language`. None of them
|
|
36
|
+
can reach the queued outcome; `quality` and `dark_mode` are additionally cost-neutral (a
|
|
37
|
+
screenshot bills on the phase-1 fetch's wire bytes, never the artifact size), while
|
|
38
|
+
`country`/`language` change which page the origin serves and so can change that figure.
|
|
39
|
+
`token_budget`, `clean_markdown` and `cache_ttl` stay unexposed on `scrape_url`, each
|
|
40
|
+
for a reason recorded in `src/tools/scrape-url.ts`. (#2687)
|
|
41
|
+
- **New output contract.** `scrape_url` / `get_result` render the envelope's `warnings`
|
|
42
|
+
under a `Warnings (N):` section, one `code: message (element)` line per warning, on both
|
|
43
|
+
the success and the terminal-failure render. The `(element)` suffix is omitted for the
|
|
44
|
+
whole-extraction codes that carry no element. Nothing rendered them before, so an
|
|
45
|
+
`artifact_unavailable` — a format you requested and were billed for is missing from the
|
|
46
|
+
response — was indistinguishable from a page that simply had none of it. The block is
|
|
47
|
+
budgeted inside the same 100KB cap as the content, ahead of the links/images sections, so
|
|
48
|
+
a long links list cannot crowd a failure signal out. A `warnings` array that is empty or
|
|
49
|
+
absent renders nothing, exactly as before. (#2679)
|
|
50
|
+
|
|
51
|
+
### Fixed
|
|
52
|
+
|
|
53
|
+
- **Compile-time breaking for TypeScript consumers that read `SearchResult.snippet` or
|
|
54
|
+
`SearchResult.date` unguarded.** Both were declared required on the exported
|
|
55
|
+
`SearchResult` type, but `POST /v1/search` omits both keys for `type: 'images'`
|
|
56
|
+
results — `docs/api/openapi.yaml` declares `required: [position, title, url]` and
|
|
57
|
+
nothing else for a search result. Reading `result.snippet.length` therefore compiled
|
|
58
|
+
under strict TypeScript and threw at runtime on any images result. They are now
|
|
59
|
+
`snippet?: string` and `date?: string | null`. Runtime behaviour is unchanged — the
|
|
60
|
+
server has always passed the API's JSON through verbatim, and no MCP tool output
|
|
61
|
+
moved; what changes is that `tsc` now requires a guard (`result.snippet?.length`, or
|
|
62
|
+
an `if (result.snippet !== undefined)` narrowing) at every read site. `web`/`news`
|
|
63
|
+
results still carry both fields and `date` is still nullable there, so `null`
|
|
64
|
+
(the provider reported no date) stays distinguishable from absent (the index carries
|
|
65
|
+
no such field at all). (#2781)
|
|
66
|
+
- The hosted `/mcp` transport and a local `npx` install now render invalid-argument errors
|
|
67
|
+
identically. They had diverged — hosted returned the raw Zod issue-array JSON where
|
|
68
|
+
stdio returned the flattened `Required at url` — and the cause was neither a stale
|
|
69
|
+
deploy nor a difference in ByteKit source: both transports share one server factory, and
|
|
70
|
+
the text is produced inside `@modelcontextprotocol/sdk`. What differed was the SDK
|
|
71
|
+
version each side resolved. `@modelcontextprotocol/sdk` 1.30.0 rewrote
|
|
72
|
+
`getParseErrorMessage` to format Zod issues as `<message> at <path>`, where 1.29.0 fell
|
|
73
|
+
through to `ZodError.message` (the raw JSON array). The hosted image builds with a frozen
|
|
74
|
+
lockfile, which still pinned 1.29.0, while the unpinned `^1.12.1` range let an `npx`
|
|
75
|
+
consumer resolve 1.30.0. The lockfile is now bumped to 1.30.0 so both sides run the same
|
|
76
|
+
SDK; the declared range is deliberately left at `^1.12.1` so upstream fixes keep
|
|
77
|
+
arriving. (#2682)
|
|
78
|
+
- A truncated links or images list is cut between whole entries instead of mid-URL, and
|
|
79
|
+
each affected section is annotated with `[Links truncated: N of M entries shown]`, so
|
|
80
|
+
the section header's count stays reconcilable with what was actually returned. The
|
|
81
|
+
markers are spent from the same 100KB budget, not appended on top of it. (#2687)
|
|
82
|
+
- `web_search` no longer prints the API error code twice
|
|
83
|
+
(`validation_error: … (validation_error)`); the code is appended only when the message
|
|
84
|
+
does not already carry it. (#2687)
|
|
85
|
+
- `scrape_url` rejects `formats: []` at the schema boundary — matching the API's own
|
|
86
|
+
`minItems: 1` — instead of forwarding it and returning a server 422. Omitting the
|
|
87
|
+
parameter still yields the `["markdown"]` default. (#2687)
|
|
88
|
+
- `--timeout-ms` with a non-numeric value is rejected with an error instead of being
|
|
89
|
+
silently ignored, which had left the client running on its default budget while the
|
|
90
|
+
operator believed one was set. (#2687)
|
|
91
|
+
- Reading `bytekit://account` issues its two sub-requests serially, matching the
|
|
92
|
+
`get_account` tool — concurrent sub-requests could rate-limit a 1-rps plan against
|
|
93
|
+
itself. (#2687)
|
|
94
|
+
- `list_docs` with a `section` outside the documentation taxonomy returns an error naming
|
|
95
|
+
the valid set, rather than a silent empty list that a correctly-spelled but empty
|
|
96
|
+
section would also produce. (#2687)
|
|
97
|
+
- The Claude Desktop / `mcp-remote` bridge config in README.md now authenticates as
|
|
98
|
+
written. It previously passed `"Authorization: Bearer $BYTEKIT_API_KEY"` in `args`;
|
|
99
|
+
an MCP host launches `command`/`args` with no shell, and `mcp-remote` interpolates
|
|
100
|
+
only the braced `${VAR}` form, so the literal text was sent as the bearer token and
|
|
101
|
+
the endpoint answered `401`. The snippet now uses `"Authorization:${AUTH_HEADER}"`
|
|
102
|
+
with a matching `env` block, and the hosted-HTTP snippet carries the same
|
|
103
|
+
no-shell-expansion caveat. (#2688)
|
|
104
|
+
- The bundled documentation no longer teaches the deactivated `/v1/recordings` endpoint
|
|
105
|
+
or links its removed reference pages. (#2688)
|
|
106
|
+
- A 429 caused by the account's **concurrency** cap now says so and fails fast, instead of
|
|
107
|
+
being reported as a rate limit. HTTP 429 carries two conditions (`rate_limited` and
|
|
108
|
+
`concurrency_limit`), and the client read neither the body nor the code: every 429 got
|
|
109
|
+
one `Retry-After` retry and then `Rate limited. Try again in a moment.` with the error
|
|
110
|
+
code hardcoded to `rate_limited`. The concurrency variant does not clear on that
|
|
111
|
+
back-off — the API spec calls its `Retry-After` "a fixed small back-off" while the slots
|
|
112
|
+
free only when the in-flight jobs finish — so the retry was spent on a condition a
|
|
113
|
+
second cannot clear, and the error object named the wrong cause. A `concurrency_limit`
|
|
114
|
+
429 now throws immediately with the real wait scale and `errorCode: 'concurrency_limit'`,
|
|
115
|
+
at both 429 sites. `rate_limited` 429s, and any 429 whose body is empty, non-JSON or
|
|
116
|
+
carries no recognizable code, keep the single honored-header retry and the exact message
|
|
117
|
+
and code they had. (#2681)
|
|
118
|
+
- A screenshot that fails inside the API's sync hold now surfaces its REAL failure code
|
|
119
|
+
(`blocked`, `timeout`, …) and message. `POST /v1/screenshots` answers that case with HTTP
|
|
120
|
+
422 carrying the flat screenshot resource, not the unified error envelope, and the client
|
|
121
|
+
parsed neither — so every such failure read as the literal `Validation error.`. The
|
|
122
|
+
`(Screenshot ID: ss_…)` handle line is unchanged, and a genuine request-validation 422
|
|
123
|
+
still renders exactly as it did. (#2679)
|
|
124
|
+
|
|
13
125
|
## [0.2.2] - 2026-07-29
|
|
14
126
|
|
|
15
127
|
### Fixed
|
package/README.md
CHANGED
|
@@ -34,13 +34,18 @@ speaks Streamable HTTP directly (Cursor and most hosts accept this shape):
|
|
|
34
34
|
"bytekit": {
|
|
35
35
|
"url": "https://api.bytekit.com/mcp",
|
|
36
36
|
"headers": {
|
|
37
|
-
"Authorization": "Bearer
|
|
37
|
+
"Authorization": "Bearer sk_live_xxx"
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
**Paste your real key in place of `sk_live_xxx`.** A JSON config file is not a
|
|
45
|
+
shell: most hosts read these values verbatim and do not substitute environment
|
|
46
|
+
variables inside `headers`, so writing `Bearer $BYTEKIT_API_KEY` here sends that
|
|
47
|
+
text to the API as the token, verbatim, and the API answers `401`.
|
|
48
|
+
|
|
44
49
|
**Claude Desktop does not accept this shape.** `claude_desktop_config.json`
|
|
45
50
|
only launches local **stdio** subprocesses (`command`/`args`/`env`) — it has
|
|
46
51
|
no native `url`-based remote-server entry, so pasting the config above into
|
|
@@ -60,13 +65,33 @@ it will not connect. To reach the hosted endpoint from Claude Desktop, either:
|
|
|
60
65
|
"mcp-remote",
|
|
61
66
|
"https://api.bytekit.com/mcp",
|
|
62
67
|
"--header",
|
|
63
|
-
"Authorization
|
|
64
|
-
]
|
|
68
|
+
"Authorization:${AUTH_HEADER}"
|
|
69
|
+
],
|
|
70
|
+
"env": {
|
|
71
|
+
"AUTH_HEADER": "Bearer sk_live_xxx"
|
|
72
|
+
}
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
```
|
|
69
77
|
|
|
78
|
+
Two details in that snippet are load-bearing, and both are documented by
|
|
79
|
+
`mcp-remote` itself:
|
|
80
|
+
|
|
81
|
+
- **`${AUTH_HEADER}`, not `$AUTH_HEADER`.** Claude Desktop launches
|
|
82
|
+
`command`/`args` directly, with no shell in between, so it does not expand
|
|
83
|
+
`$VAR` anywhere in the config. `mcp-remote` does its own substitution on
|
|
84
|
+
`--header` values, but only of the braced `${VAR}` form, reading it from the
|
|
85
|
+
process environment the `env` block supplies. A bare `$BYTEKIT_API_KEY` is
|
|
86
|
+
passed through untouched and authenticates as that literal string — a
|
|
87
|
+
guaranteed `401`.
|
|
88
|
+
- **No space after the colon in `Authorization:${AUTH_HEADER}`.** The header
|
|
89
|
+
value carries the space (`Bearer sk_live_xxx`) instead. `mcp-remote`'s README
|
|
90
|
+
documents this as the workaround for a Cursor / Claude Desktop (Windows) bug
|
|
91
|
+
where spaces inside `args` are not escaped when it invokes `npx`, mangling the
|
|
92
|
+
value: `"Authorization:${AUTH_HEADER}" // note no spaces around ':'` with
|
|
93
|
+
`"AUTH_HEADER": "Bearer <auth-token>" // spaces OK in env vars`.
|
|
94
|
+
|
|
70
95
|
Or skip the hosted endpoint entirely and run the **local stdio server**
|
|
71
96
|
(Option 2 below), which Claude Desktop supports natively.
|
|
72
97
|
|
|
@@ -104,13 +129,13 @@ Client config for a stdio server (`claude_desktop_config.json` and equivalents):
|
|
|
104
129
|
|
|
105
130
|
### CLI flags
|
|
106
131
|
|
|
107
|
-
| Flag | Purpose
|
|
108
|
-
| ------------------- |
|
|
109
|
-
| `--api-key <key>` | ByteKit API key.
|
|
110
|
-
| `--base-url <url>` | API base URL (default `https://api.bytekit.com`) — point at staging or a local gateway.
|
|
111
|
-
| `--timeout-ms <ms>` | Per-request timeout budget in milliseconds (default `120000`; `0` disables it).
|
|
112
|
-
| `--verbose` | Log requests to stderr.
|
|
113
|
-
| `--help` | Show usage.
|
|
132
|
+
| Flag | Purpose |
|
|
133
|
+
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
134
|
+
| `--api-key <key>` | ByteKit API key. |
|
|
135
|
+
| `--base-url <url>` | API base URL (default `https://api.bytekit.com`) — point at staging or a local gateway. |
|
|
136
|
+
| `--timeout-ms <ms>` | Per-request timeout budget in milliseconds (default `120000`; `0` disables it). A present-but-invalid value (non-numeric, or negative) is rejected with an error rather than silently ignored. |
|
|
137
|
+
| `--verbose` | Log requests to stderr. |
|
|
138
|
+
| `--help` | Show usage. |
|
|
114
139
|
|
|
115
140
|
### API-key resolution order
|
|
116
141
|
|
|
@@ -130,16 +155,16 @@ detail — it also falls back to an environment variable:
|
|
|
130
155
|
|
|
131
156
|
## Tool inventory
|
|
132
157
|
|
|
133
|
-
| Tool | What it does
|
|
134
|
-
| ---------------- |
|
|
135
|
-
| `scrape_url` | Fetch a URL and return HTML, clean markdown, links, or images.
|
|
136
|
-
| `web_search` | Run a web search and return ranked organic results.
|
|
137
|
-
| `screenshot_url` | Capture a screenshot of a page (desktop/mobile, PNG/JPEG).
|
|
138
|
-
| `get_result` | Fetch a previously created screenshot (`ss_`) or scrape (`sc_`) by id.
|
|
139
|
-
| `get_account` | Return account details, plan, and current usage/quota.
|
|
140
|
-
| `list_docs` | List every page in the bundled ByteKit documentation.
|
|
141
|
-
| `search_docs` | Search the bundled documentation.
|
|
142
|
-
| `get_doc` | Fetch the full markdown of one documentation page.
|
|
158
|
+
| Tool | What it does |
|
|
159
|
+
| ---------------- | ----------------------------------------------------------------------------------------------------- |
|
|
160
|
+
| `scrape_url` | Fetch a URL and return HTML, clean markdown, links, or images. |
|
|
161
|
+
| `web_search` | Run a web search and return ranked organic results. |
|
|
162
|
+
| `screenshot_url` | Capture a screenshot of a page (desktop/mobile, PNG/JPEG, JPEG quality, dark mode, country/language). |
|
|
163
|
+
| `get_result` | Fetch a previously created screenshot (`ss_`) or scrape (`sc_`) by id. |
|
|
164
|
+
| `get_account` | Return account details, plan, and current usage/quota. |
|
|
165
|
+
| `list_docs` | List every page in the bundled ByteKit documentation. |
|
|
166
|
+
| `search_docs` | Search the bundled documentation. |
|
|
167
|
+
| `get_doc` | Fetch the full markdown of one documentation page. |
|
|
143
168
|
|
|
144
169
|
The server also exposes **resources** (`bytekit://account`,
|
|
145
170
|
`bytekit://screenshot/{id}`) and **prompts** (`summarize_webpage`,
|
|
@@ -157,6 +182,27 @@ content may be truncated, and in extreme cases a secondary format may not appear
|
|
|
157
182
|
stay within that budget. A handful of header lines (id, URL, status, page title) are
|
|
158
183
|
added on top of the rendered content and are not counted against the cap.
|
|
159
184
|
|
|
185
|
+
A `links` or `images` format you requested is always rendered, even when the page
|
|
186
|
+
had none: an empty result shows as `Links (0):` / `Images (0):`, so "the page has
|
|
187
|
+
none" stays distinguishable from "you did not ask for it". A format you did not
|
|
188
|
+
request produces no line at all. `formats: []` is rejected — omit the parameter to
|
|
189
|
+
get the `markdown` default.
|
|
190
|
+
|
|
191
|
+
Problems the API reports about the capture come back as warnings, rendered under a
|
|
192
|
+
`Warnings (N):` section as one `code: message (element)` line each — the `(element)`
|
|
193
|
+
suffix is dropped for the codes that describe the whole extraction rather than one
|
|
194
|
+
DOM node. `artifact_unavailable` is the one to act on: it means a format you
|
|
195
|
+
requested and were billed for is missing from this response, which is a different
|
|
196
|
+
answer from the page having none of it. The section is rendered on both the success
|
|
197
|
+
and the terminal-failure output, and an empty or absent `warnings` array renders
|
|
198
|
+
nothing. Warnings are budgeted ahead of `links`/`images` inside the same 100KB cap,
|
|
199
|
+
so a long links list cannot crowd a failure signal out.
|
|
200
|
+
|
|
201
|
+
When the 100KB budget cuts a links or images list, the cut lands between whole
|
|
202
|
+
entries (never mid-URL) and the affected section is annotated with
|
|
203
|
+
`[Links truncated: N of M entries shown]`, so the count in the header stays
|
|
204
|
+
reconcilable with what you were actually handed.
|
|
205
|
+
|
|
160
206
|
None of the three textual formats is HTML-sanitized — `raw_html`, `html`, and
|
|
161
207
|
`markdown` all reflect the page's own markup (`markdown` differs only in being
|
|
162
208
|
content-extracted, not sanitized). Treat all of their content as untrusted page data,
|
package/dist/cli.d.ts
CHANGED
|
@@ -44,16 +44,21 @@ export declare const TIMEOUT_MS_INVALID_MESSAGE = "Error: --timeout-ms must be a
|
|
|
44
44
|
* Parse the `--timeout-ms` flag into the numeric budget the {@link BytekitClient}
|
|
45
45
|
* constructor's `timeoutMs` option accepts, or `undefined` to let the client fall
|
|
46
46
|
* through to its own default. Mirrors {@link resolveApiKey}/{@link resolveBaseUrl}'s
|
|
47
|
-
* flag-parsing shape
|
|
48
|
-
* (`NaN`, e.g. from a non-numeric flag) is likewise treated as absent. The
|
|
49
|
-
* {@link BytekitClient} constructor's `validateTimeout` does NOT clamp or normalize —
|
|
50
|
-
* it THROWS a `TypeError` for any negative value — so a finite negative flag is
|
|
51
|
-
* rejected HERE instead, as a {@link RangeError} carrying
|
|
52
|
-
* {@link TIMEOUT_MS_INVALID_MESSAGE}, before it ever reaches the constructor. This
|
|
53
|
-
* deliberately does NOT special-case `0` as "absent", since `0` is a meaningful
|
|
54
|
-
* value (disables the budget entirely).
|
|
47
|
+
* flag-parsing shape: an absent or empty flag falls through.
|
|
55
48
|
*
|
|
56
|
-
*
|
|
49
|
+
* A PRESENT flag that is not a non-negative number is rejected here, as a
|
|
50
|
+
* {@link RangeError} carrying {@link TIMEOUT_MS_INVALID_MESSAGE}, rather than forwarded
|
|
51
|
+
* (issue #2687 item 7). The {@link BytekitClient} constructor normalizes anything
|
|
52
|
+
* non-finite or `<= 0` to `0` — which means "budget disabled", the OPPOSITE of what an
|
|
53
|
+
* operator who typed `--timeout-ms abc` or `--timeout-ms -5` intended — and it does so
|
|
54
|
+
* silently, so neither value would ever surface as an error. Rejecting at the flag
|
|
55
|
+
* boundary is the only place the operator's typo is still distinguishable from an
|
|
56
|
+
* omitted flag.
|
|
57
|
+
*
|
|
58
|
+
* This deliberately does NOT special-case `0` as "absent", since `0` is a meaningful
|
|
59
|
+
* value (disables the budget entirely, per the constructor's own contract).
|
|
60
|
+
*
|
|
61
|
+
* @throws {RangeError} when the flag is present but not a finite, non-negative number.
|
|
57
62
|
*/
|
|
58
63
|
export declare function resolveTimeoutMs(flag: string | undefined): number | undefined;
|
|
59
64
|
export declare const HELP_TEXT = "ByteKit MCP Server\n\nUsage:\n bytekit-mcp --api-key <key> [--base-url <url>] [--timeout-ms <ms>] [--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 --timeout-ms Per-request timeout budget in milliseconds (default: 120000;\n 0 disables it)\n --verbose Log requests to stderr\n --help Show this help message\n";
|
package/dist/cli.js
CHANGED
|
@@ -49,24 +49,27 @@ export const TIMEOUT_MS_INVALID_MESSAGE = 'Error: --timeout-ms must be a non-neg
|
|
|
49
49
|
* Parse the `--timeout-ms` flag into the numeric budget the {@link BytekitClient}
|
|
50
50
|
* constructor's `timeoutMs` option accepts, or `undefined` to let the client fall
|
|
51
51
|
* through to its own default. Mirrors {@link resolveApiKey}/{@link resolveBaseUrl}'s
|
|
52
|
-
* flag-parsing shape
|
|
53
|
-
* (`NaN`, e.g. from a non-numeric flag) is likewise treated as absent. The
|
|
54
|
-
* {@link BytekitClient} constructor's `validateTimeout` does NOT clamp or normalize —
|
|
55
|
-
* it THROWS a `TypeError` for any negative value — so a finite negative flag is
|
|
56
|
-
* rejected HERE instead, as a {@link RangeError} carrying
|
|
57
|
-
* {@link TIMEOUT_MS_INVALID_MESSAGE}, before it ever reaches the constructor. This
|
|
58
|
-
* deliberately does NOT special-case `0` as "absent", since `0` is a meaningful
|
|
59
|
-
* value (disables the budget entirely).
|
|
52
|
+
* flag-parsing shape: an absent or empty flag falls through.
|
|
60
53
|
*
|
|
61
|
-
*
|
|
54
|
+
* A PRESENT flag that is not a non-negative number is rejected here, as a
|
|
55
|
+
* {@link RangeError} carrying {@link TIMEOUT_MS_INVALID_MESSAGE}, rather than forwarded
|
|
56
|
+
* (issue #2687 item 7). The {@link BytekitClient} constructor normalizes anything
|
|
57
|
+
* non-finite or `<= 0` to `0` — which means "budget disabled", the OPPOSITE of what an
|
|
58
|
+
* operator who typed `--timeout-ms abc` or `--timeout-ms -5` intended — and it does so
|
|
59
|
+
* silently, so neither value would ever surface as an error. Rejecting at the flag
|
|
60
|
+
* boundary is the only place the operator's typo is still distinguishable from an
|
|
61
|
+
* omitted flag.
|
|
62
|
+
*
|
|
63
|
+
* This deliberately does NOT special-case `0` as "absent", since `0` is a meaningful
|
|
64
|
+
* value (disables the budget entirely, per the constructor's own contract).
|
|
65
|
+
*
|
|
66
|
+
* @throws {RangeError} when the flag is present but not a finite, non-negative number.
|
|
62
67
|
*/
|
|
63
68
|
export function resolveTimeoutMs(flag) {
|
|
64
69
|
if (flag === undefined || flag.length === 0)
|
|
65
70
|
return undefined;
|
|
66
71
|
const parsed = Number(flag);
|
|
67
|
-
if (!Number.isFinite(parsed))
|
|
68
|
-
return undefined;
|
|
69
|
-
if (parsed < 0) {
|
|
72
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
70
73
|
throw new RangeError(TIMEOUT_MS_INVALID_MESSAGE);
|
|
71
74
|
}
|
|
72
75
|
return parsed;
|
|
@@ -115,10 +118,11 @@ async function main() {
|
|
|
115
118
|
timeoutMs = resolveTimeoutMs(values['timeout-ms']);
|
|
116
119
|
}
|
|
117
120
|
catch (err) {
|
|
118
|
-
// resolveTimeoutMs throws a RangeError for
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
//
|
|
121
|
+
// resolveTimeoutMs throws a RangeError for any present-but-invalid value (a
|
|
122
|
+
// non-numeric flag or a finite negative one, issue #2687 item 7) — surface it as a
|
|
123
|
+
// graceful CLI error, mirroring the missing-API-key path above, instead of letting
|
|
124
|
+
// it reach the BytekitClient constructor, which would silently normalize it to 0
|
|
125
|
+
// and run with the timeout budget DISABLED.
|
|
122
126
|
process.stderr.write(err instanceof Error ? err.message : String(err));
|
|
123
127
|
process.exit(1);
|
|
124
128
|
}
|
package/dist/client.d.ts
CHANGED
|
@@ -34,13 +34,30 @@ export interface SearchResultImage {
|
|
|
34
34
|
thumbnail_width?: number;
|
|
35
35
|
thumbnail_height?: number;
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* A single ranked organic search result.
|
|
39
|
+
*
|
|
40
|
+
* Only `position`, `title` and `url` are guaranteed — `docs/api/openapi.yaml`
|
|
41
|
+
* (POST /v1/search → 200 → `results[]`) declares `required: [position, title, url]`
|
|
42
|
+
* and nothing else. Everything past those three is index-dependent:
|
|
43
|
+
*
|
|
44
|
+
* - `snippet` — present for `web` and `news`, **omitted for `images`** (#2781).
|
|
45
|
+
* - `date` — present (possibly `null`) for `web`/`news`, **omitted entirely for
|
|
46
|
+
* `images`** (#2781). `null` and absent are distinct: `null` means the provider
|
|
47
|
+
* reported no date; absence means the index carries no date at all.
|
|
48
|
+
* - `source` / `domain` / `image` — provider- and index-dependent.
|
|
49
|
+
*
|
|
50
|
+
* Both `snippet` and `date` were required here until #2781, which let
|
|
51
|
+
* `result.snippet.length` compile under strict TS and throw on an `images`
|
|
52
|
+
* result. Same defect `sdk-typescript` carried until #2481/#2678; `mcp-server`
|
|
53
|
+
* has no dependency on that package, so it needed its own fix.
|
|
54
|
+
*/
|
|
38
55
|
export interface SearchResult {
|
|
39
56
|
position: number;
|
|
40
57
|
title: string;
|
|
41
58
|
url: string;
|
|
42
|
-
snippet
|
|
43
|
-
date
|
|
59
|
+
snippet?: string;
|
|
60
|
+
date?: string | null;
|
|
44
61
|
source?: string;
|
|
45
62
|
domain?: string;
|
|
46
63
|
image?: SearchResultImage;
|
|
@@ -57,6 +74,14 @@ export interface ScreenshotParams {
|
|
|
57
74
|
full_page?: boolean | undefined;
|
|
58
75
|
device?: 'desktop' | 'mobile' | undefined;
|
|
59
76
|
format?: 'png' | 'jpeg' | undefined;
|
|
77
|
+
/** JPEG quality, 1-100 (API default 80). Only meaningful for `format: 'jpeg'`. */
|
|
78
|
+
quality?: number | undefined;
|
|
79
|
+
/** Render the page with `prefers-color-scheme: dark`. */
|
|
80
|
+
dark_mode?: boolean | undefined;
|
|
81
|
+
/** Uppercase two-letter country for the proxy exit (API pattern `^[A-Z]{2}$`). */
|
|
82
|
+
country?: string | undefined;
|
|
83
|
+
/** Two-letter language hint for the request's Accept-Language. */
|
|
84
|
+
language?: string | undefined;
|
|
60
85
|
}
|
|
61
86
|
/** Nested error shape carried by the #2027 failed-screenshot envelope. */
|
|
62
87
|
export interface ScreenshotError {
|
|
@@ -189,6 +214,21 @@ export declare class BytekitClient {
|
|
|
189
214
|
private request;
|
|
190
215
|
private post;
|
|
191
216
|
private get;
|
|
217
|
+
/**
|
|
218
|
+
* Read the error `code` off a 429 body, tolerating anything that is not one.
|
|
219
|
+
*
|
|
220
|
+
* The 429 branch reached this ticket having never read the body at all, so the read is
|
|
221
|
+
* additive and must stay incapable of changing the outcome for a body it cannot parse
|
|
222
|
+
* (issue #2681, E3): an empty body, an edge proxy's HTML error page, or a response
|
|
223
|
+
* object with no usable `json()` all resolve to `undefined` here, and the caller then
|
|
224
|
+
* behaves exactly as it did before. Only an aborted read is escalated — as a timeout,
|
|
225
|
+
* matching {@link handleErrorResponse} — because a body read that ran out of budget is
|
|
226
|
+
* a timeout, not an absent code.
|
|
227
|
+
*
|
|
228
|
+
* Both wire shapes are covered by {@link parseErrorEnvelope}'s `code`: the unified
|
|
229
|
+
* `{ error: { code } }` envelope and the flat vendor-masked `{ error: '<code>' }`.
|
|
230
|
+
*/
|
|
231
|
+
private read429Code;
|
|
192
232
|
/**
|
|
193
233
|
* Map a non-2xx `response` to a {@link BytekitApiError}.
|
|
194
234
|
*
|
package/dist/client.js
CHANGED
|
@@ -107,6 +107,27 @@ function abortReason(signal) {
|
|
|
107
107
|
return reason instanceof Error ? reason : new Error(String(reason));
|
|
108
108
|
}
|
|
109
109
|
// ============================================================
|
|
110
|
+
// 429 species (issue #2681)
|
|
111
|
+
// ============================================================
|
|
112
|
+
/**
|
|
113
|
+
* The envelope `code` the gateway sends when the account's concurrency cap — not its
|
|
114
|
+
* request rate — is what rejected the call. HTTP 429 carries both conditions
|
|
115
|
+
* (docs/api/openapi.yaml: "Rate limit (`rate_limited`) or concurrency limit
|
|
116
|
+
* (`concurrency_limit`) exceeded"), and they need opposite advice.
|
|
117
|
+
*/
|
|
118
|
+
const CONCURRENCY_LIMIT_CODE = 'concurrency_limit';
|
|
119
|
+
/**
|
|
120
|
+
* Advice for a `concurrency_limit` 429.
|
|
121
|
+
*
|
|
122
|
+
* It names the real wait scale deliberately. The spec describes the `Retry-After` on this
|
|
123
|
+
* variant as "a fixed small back-off", but the condition only clears when the account's
|
|
124
|
+
* in-flight jobs finish (or their slots expire, 5 min), so "try again in a moment" — the
|
|
125
|
+
* rate-limit copy every 429 used to get — is false here.
|
|
126
|
+
*/
|
|
127
|
+
const CONCURRENCY_LIMIT_MESSAGE = 'Concurrency limit reached — every concurrent slot on your plan is already in use. ' +
|
|
128
|
+
'Wait for your in-flight jobs to finish before retrying; this can take minutes, not ' +
|
|
129
|
+
'seconds. Check your plan limit with get_account.';
|
|
130
|
+
// ============================================================
|
|
110
131
|
// Client
|
|
111
132
|
// ============================================================
|
|
112
133
|
export class BytekitClient {
|
|
@@ -238,8 +259,19 @@ export class BytekitClient {
|
|
|
238
259
|
const elapsed = Date.now() - start;
|
|
239
260
|
process.stderr.write(`[mcp] ${method} ${path} -> ${response.status} (${elapsed}ms)\n`);
|
|
240
261
|
}
|
|
241
|
-
// 429:
|
|
262
|
+
// 429: two conditions share this status, and only one of them is retryable here.
|
|
242
263
|
if (response.status === 429) {
|
|
264
|
+
// Read the envelope code BEFORE deciding to retry: a `concurrency_limit` 429 does
|
|
265
|
+
// not clear on the header's back-off, so retrying it burns the one attempt and then
|
|
266
|
+
// reports the wrong thing twice over (issue #2681). Absent/unparseable code -> the
|
|
267
|
+
// pre-existing retry, unchanged.
|
|
268
|
+
const code = await this.read429Code(response, signal);
|
|
269
|
+
if (code === CONCURRENCY_LIMIT_CODE) {
|
|
270
|
+
if (this.verbose) {
|
|
271
|
+
process.stderr.write('[mcp] Concurrency limit reached, not retrying\n');
|
|
272
|
+
}
|
|
273
|
+
throw new BytekitApiError(CONCURRENCY_LIMIT_MESSAGE, 429, CONCURRENCY_LIMIT_CODE);
|
|
274
|
+
}
|
|
243
275
|
const retryAfter = response.headers.get('Retry-After');
|
|
244
276
|
const waitMs = parseRetryAfterMs(retryAfter);
|
|
245
277
|
if (this.verbose) {
|
|
@@ -279,6 +311,13 @@ export class BytekitClient {
|
|
|
279
311
|
throw new BytekitApiError('Could not reach ByteKit API. Check your connection and base URL.', 0, 'network_error');
|
|
280
312
|
}
|
|
281
313
|
if (retryResponse.status === 429) {
|
|
314
|
+
// The species can differ between the two attempts -- a rate-limit 429 whose retry,
|
|
315
|
+
// a second later, finds every slot held. This throw hardcoded `rate_limited`, so
|
|
316
|
+
// that case was mislabeled here too (issue #2681).
|
|
317
|
+
const retryCode = await this.read429Code(retryResponse, signal);
|
|
318
|
+
if (retryCode === CONCURRENCY_LIMIT_CODE) {
|
|
319
|
+
throw new BytekitApiError(CONCURRENCY_LIMIT_MESSAGE, 429, CONCURRENCY_LIMIT_CODE);
|
|
320
|
+
}
|
|
282
321
|
throw new BytekitApiError('Rate limited. Try again in a moment.', 429, 'rate_limited');
|
|
283
322
|
}
|
|
284
323
|
response = retryResponse;
|
|
@@ -305,6 +344,31 @@ export class BytekitClient {
|
|
|
305
344
|
async get(path) {
|
|
306
345
|
return this.request('GET', path);
|
|
307
346
|
}
|
|
347
|
+
/**
|
|
348
|
+
* Read the error `code` off a 429 body, tolerating anything that is not one.
|
|
349
|
+
*
|
|
350
|
+
* The 429 branch reached this ticket having never read the body at all, so the read is
|
|
351
|
+
* additive and must stay incapable of changing the outcome for a body it cannot parse
|
|
352
|
+
* (issue #2681, E3): an empty body, an edge proxy's HTML error page, or a response
|
|
353
|
+
* object with no usable `json()` all resolve to `undefined` here, and the caller then
|
|
354
|
+
* behaves exactly as it did before. Only an aborted read is escalated — as a timeout,
|
|
355
|
+
* matching {@link handleErrorResponse} — because a body read that ran out of budget is
|
|
356
|
+
* a timeout, not an absent code.
|
|
357
|
+
*
|
|
358
|
+
* Both wire shapes are covered by {@link parseErrorEnvelope}'s `code`: the unified
|
|
359
|
+
* `{ error: { code } }` envelope and the flat vendor-masked `{ error: '<code>' }`.
|
|
360
|
+
*/
|
|
361
|
+
async read429Code(response, signal) {
|
|
362
|
+
try {
|
|
363
|
+
return (await parseErrorEnvelope(response, signal)).code;
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
// `parseErrorEnvelope` swallows every parse failure and rejects only on abort.
|
|
367
|
+
if (signal?.aborted)
|
|
368
|
+
throw this.timeoutError();
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
308
372
|
/**
|
|
309
373
|
* Map a non-2xx `response` to a {@link BytekitApiError}.
|
|
310
374
|
*
|
|
@@ -357,7 +421,31 @@ export class BytekitClient {
|
|
|
357
421
|
throw new BytekitApiError('Bandwidth quota exhausted. Check usage with get_account.', 402, 'quota_exceeded');
|
|
358
422
|
}
|
|
359
423
|
if (status === 422) {
|
|
360
|
-
|
|
424
|
+
// ── The RESOURCE-body 422 (issue #2679) ──
|
|
425
|
+
// POST /v1/screenshots answers a capture that FAILED inside its sync hold with 422
|
|
426
|
+
// whose body is the flat `ScreenshotResponse` resource — `serializeScreenshot`
|
|
427
|
+
// (gateway routes/screenshots.ts:175 + :194) — carrying `error_code`/`error_message`
|
|
428
|
+
// at the top level rather than the unified `Error` envelope. That is now the
|
|
429
|
+
// documented shape (docs/api/openapi.yaml, POST /v1/screenshots 422: `oneOf` Error |
|
|
430
|
+
// ScreenshotResponse); the gateway was deliberately left untouched, because its flat
|
|
431
|
+
// body is what carries the `ss_` handle and the rest of the resource, and reshaping
|
|
432
|
+
// it would move a wire contract the SDK, CLI and dashboard already read.
|
|
433
|
+
//
|
|
434
|
+
// Rendered as `code: message`, the same spelling the generic-envelope branch below
|
|
435
|
+
// uses, so one 422 does not read differently from every other server-coded error.
|
|
436
|
+
// The code alone when `error_message` is null: the code is the half the agent acts
|
|
437
|
+
// on, and a bare `null` would be worse than terse.
|
|
438
|
+
//
|
|
439
|
+
// Precedence: this wins over `envelope.message` because a resource body cannot
|
|
440
|
+
// populate it (its `message` key does not exist), so the two are never both present
|
|
441
|
+
// — a genuine validation 422 still carries the unified envelope and renders exactly
|
|
442
|
+
// as before.
|
|
443
|
+
const resource = envelope.resource;
|
|
444
|
+
const base = resource
|
|
445
|
+
? resource.message !== undefined
|
|
446
|
+
? `${resource.code}: ${resource.message}`
|
|
447
|
+
: resource.code
|
|
448
|
+
: (envelope.message ?? 'Validation error.');
|
|
361
449
|
const detail = envelope.details !== undefined ? `${base} (${formatErrorDetails(envelope.details)})` : base;
|
|
362
450
|
// A sync-failed screenshot (POST /v1/screenshots -> 422) carries no `ss_` handle in
|
|
363
451
|
// the generic error body this branch parses (only message/details/code) -- the
|
|
@@ -369,7 +457,7 @@ export class BytekitClient {
|
|
|
369
457
|
// absent -> degrade gracefully, omit the handle line entirely (E1).
|
|
370
458
|
const screenshotId = path === '/v1/screenshots' ? response.headers.get('X-Screenshot-ID') : null;
|
|
371
459
|
const message = screenshotId ? `${detail} (Screenshot ID: ${screenshotId})` : detail;
|
|
372
|
-
throw new BytekitApiError(message, 422, envelope.code ?? 'validation_error');
|
|
460
|
+
throw new BytekitApiError(message, 422, resource?.code ?? envelope.code ?? 'validation_error');
|
|
373
461
|
}
|
|
374
462
|
// ── Flat vendor-masked shape: `{ "error": "<code>" }` (e.g. /v1/search 502,
|
|
375
463
|
// docs/api/openapi.yaml §/v1/search 502). The string IS the error code, so
|
|
@@ -445,6 +533,16 @@ async function parseErrorEnvelope(response, signal) {
|
|
|
445
533
|
parsed.message = b.message;
|
|
446
534
|
else if (typeof b.error === 'string' && b.error.length > 0)
|
|
447
535
|
parsed.code = b.error;
|
|
536
|
+
// Resource-body failure fields (issue #2679), carried alongside — never merged into
|
|
537
|
+
// `code`/`message`, so only the 422 branch can act on them. `error_message` is a
|
|
538
|
+
// nullable DB column, so a null is treated as absent and the code stands alone.
|
|
539
|
+
const r = body;
|
|
540
|
+
if (typeof r.error_code === 'string' && r.error_code.length > 0) {
|
|
541
|
+
parsed.resource =
|
|
542
|
+
typeof r.error_message === 'string' && r.error_message.length > 0
|
|
543
|
+
? { code: r.error_code, message: r.error_message }
|
|
544
|
+
: { code: r.error_code };
|
|
545
|
+
}
|
|
448
546
|
return parsed;
|
|
449
547
|
}
|
|
450
548
|
/** Render an error `details` value as a compact human-readable string. */
|