@hunt-labs/bytekit-mcp 0.2.0 → 0.2.2
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 +86 -0
- package/README.md +74 -18
- package/dist/cli.d.ts +18 -1
- package/dist/cli.js +54 -7
- package/dist/client.d.ts +45 -0
- package/dist/client.js +225 -22
- package/dist/docs-bundle/docs-bundle.json +220 -210
- package/dist/docs-bundle/helpers.d.ts +33 -1
- package/dist/docs-bundle/helpers.js +47 -0
- package/dist/lib/render-scrape.d.ts +34 -0
- package/dist/lib/render-scrape.js +116 -0
- package/dist/lib/render-screenshot.js +6 -0
- package/dist/lib/truncate.d.ts +1 -1
- package/dist/lib/truncate.js +85 -12
- package/dist/scrape-contract.generated.d.ts +7 -2
- package/dist/tools/get-account.js +11 -3
- package/dist/tools/get-result.js +17 -3
- package/dist/tools/list-docs.d.ts +6 -0
- package/dist/tools/list-docs.js +8 -4
- package/dist/tools/scrape-url.js +31 -71
- package/dist/tools/search-docs.js +15 -1
- package/dist/tools/web-search.js +19 -3
- package/package.json +1 -1
- package/dist/docs-bundle/load-bundle.test.d.ts +0 -9
- package/dist/docs-bundle/load-bundle.test.js +0 -50
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,90 @@ 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
|
+
## [Unreleased]
|
|
12
|
+
|
|
13
|
+
## [0.2.2] - 2026-07-29
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
|
|
17
|
+
- `scrape_url` / `get_result` render every returned textual format
|
|
18
|
+
(`markdown`/`html`/`raw_html`), not just the first present — a multi-format call
|
|
19
|
+
previously dropped every secondary format silently despite it being billed. Secondary
|
|
20
|
+
formats are rendered under a `--- format: <name> ---` delimiter, in canonical order
|
|
21
|
+
after the unlabeled primary. (#2589)
|
|
22
|
+
- The 100KB output truncation budget now covers the links/images blocks too — they were
|
|
23
|
+
previously appended AFTER truncation, so a combined output could exceed the budget.
|
|
24
|
+
The whole assembled payload is now truncated exactly once, with the links/images
|
|
25
|
+
block reserved its own share of the budget so it is never dropped in full just
|
|
26
|
+
because the textual formats alone already fill the budget. (#2589)
|
|
27
|
+
- `scrape_url` / `get_result` descriptions no longer advertise a queued `sc_` outcome
|
|
28
|
+
that the MCP input schema (`url`/`formats`/`country`) cannot produce — that outcome
|
|
29
|
+
was only reachable via `body.async` or fields `can-fast-path.ts` gates on, none of
|
|
30
|
+
which this tool's schema exposes. (#2589)
|
|
31
|
+
- `web_search` now renders `credits_used` and `related_searches`, both spec-required
|
|
32
|
+
fields that were previously dropped silently. (#2591)
|
|
33
|
+
- A sync-failed screenshot's `ss_` handle — absent from the 422 error body — is now
|
|
34
|
+
read from the `X-Screenshot-ID` response header and included in the error text, so
|
|
35
|
+
it can still be redeemed via `get_result`. Degrades gracefully when the header is
|
|
36
|
+
absent. (#2591)
|
|
37
|
+
- The 402 message on `/v1/screenshots` no longer says "Bandwidth quota exhausted"
|
|
38
|
+
(screenshot quotas are credit/count-based) and no longer points at `get_account`,
|
|
39
|
+
which is rate-limit-fragile immediately after a quota failure. Every other endpoint's
|
|
40
|
+
402 wording is unchanged. (#2591)
|
|
41
|
+
- `get_result`'s invalid-id-prefix message no longer truncates the offending id to 3
|
|
42
|
+
characters. (#2591)
|
|
43
|
+
- `get_result` now gives the same "poll with get_result" guidance `screenshot_url`'s
|
|
44
|
+
queued branch gives when a screenshot is still `pending`/`processing`. (#2591)
|
|
45
|
+
- `get_account` no longer renders a duplicate email (`Account: foo@bar.com
|
|
46
|
+
(foo@bar.com)`) when the account has no name. (#2591)
|
|
47
|
+
- `search_docs` snippets no longer duplicate the page title when the match falls near
|
|
48
|
+
the body's own leading `# <Title>` heading. (#2591)
|
|
49
|
+
- `ScrapeErrorEnvelope.id` is now modeled as nullable, matching
|
|
50
|
+
`docs/api/openapi.yaml` (`id` is null when a scrape was never queued, e.g. a
|
|
51
|
+
validation failure) — `get_result`/`scrape_url` render `ID: —` instead of the
|
|
52
|
+
literal `ID: null`. (#2591)
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- `get_account` now issues its `getAccount`/`getUsage` requests serially instead of
|
|
57
|
+
via `Promise.all`, so it no longer doubles the concurrent request rate against
|
|
58
|
+
1-rps plans. (#2591)
|
|
59
|
+
- Regenerated the bundled `src/docs-bundle/docs-bundle.json` against the current
|
|
60
|
+
`packages/docs/content` tree. Every guarded endpoint's docs page now states its
|
|
61
|
+
request-body byte ceiling and the `request_too_large` error code (#2640), and the
|
|
62
|
+
`/v1/bulk` pages document `defaults.type` inheritance plus the 422 on unrecognized
|
|
63
|
+
keys (#2643). Content only — no tool surface, schema, or runtime behavior changed.
|
|
64
|
+
(#2640, #2643)
|
|
65
|
+
|
|
66
|
+
## [0.2.1] - 2026-07-24
|
|
67
|
+
|
|
68
|
+
### Fixed
|
|
69
|
+
|
|
70
|
+
- The spec'd flat `/v1/search` 502 error body (`{"error":"search_provider_error"}`)
|
|
71
|
+
now surfaces its code in the tool error text instead of collapsing to a generic
|
|
72
|
+
"ByteKit API error (HTTP 502)". Flat `{error: "<string>"}` bodies on any status
|
|
73
|
+
parse the same way; envelope-shaped bodies keep winning when both shapes are
|
|
74
|
+
present. (#2541)
|
|
75
|
+
|
|
76
|
+
### Added
|
|
77
|
+
|
|
78
|
+
- `BytekitClient` accepts a `timeoutMs` constructor option — a per-request budget in
|
|
79
|
+
milliseconds, defaulting to `120000`. Set `0` to disable it entirely. Values that are
|
|
80
|
+
negative or non-finite normalize to disabled rather than throwing. Previously a hung
|
|
81
|
+
upstream hung a stdio MCP tool call forever. (#2568)
|
|
82
|
+
- The budget covers an **entire** `request()` call rather than each await separately:
|
|
83
|
+
the initial fetch, the 429 `Retry-After` sleep, the retry fetch, **and both** the
|
|
84
|
+
success and error body reads (`response.json()` in `request()` and in
|
|
85
|
+
`parseErrorEnvelope`). Two of those previously swallowed an abort outright — the
|
|
86
|
+
`Retry-After` sleep observed no signal, and a failed error-body read was downgraded to
|
|
87
|
+
"no envelope", surfacing a misleading status-line message instead of the timeout.
|
|
88
|
+
Exhausting the budget now produces a `BytekitApiError` with
|
|
89
|
+
`errorCode: 'timeout'`, distinct from `'network_error'`. (#2568)
|
|
90
|
+
- Note the semantics are **client-side only**: aborting does not cancel or refund
|
|
91
|
+
server-side work already in progress, so an account may still be billed for a result
|
|
92
|
+
the caller never reads. The `120000` default is deliberately well above the server-side
|
|
93
|
+
screenshot ceiling so it never truncates a legitimate billable operation. (#2568)
|
|
94
|
+
|
|
11
95
|
## [0.2.0] - 2026-07-21
|
|
12
96
|
|
|
13
97
|
### Removed (**BREAKING**)
|
|
@@ -93,6 +177,8 @@ today, see [README.md](./README.md), which remains the authoritative usage guide
|
|
|
93
177
|
(scrape, screenshot, search, docs) to AI agents over the Model Context Protocol,
|
|
94
178
|
as a local stdio server or hosted.
|
|
95
179
|
|
|
180
|
+
[0.2.2]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
181
|
+
[0.2.1]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
96
182
|
[0.2.0]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
97
183
|
[0.1.3]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
98
184
|
[0.1.2]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
package/README.md
CHANGED
|
@@ -25,8 +25,8 @@ Point any MCP client that speaks the Streamable HTTP transport at:
|
|
|
25
25
|
https://api.bytekit.com/mcp
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
Send your API key as a bearer token. Example client config
|
|
29
|
-
Cursor
|
|
28
|
+
Send your API key as a bearer token. Example client config for a host that
|
|
29
|
+
speaks Streamable HTTP directly (Cursor and most hosts accept this shape):
|
|
30
30
|
|
|
31
31
|
```json
|
|
32
32
|
{
|
|
@@ -41,6 +41,35 @@ Cursor, and most hosts accept this shape):
|
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
+
**Claude Desktop does not accept this shape.** `claude_desktop_config.json`
|
|
45
|
+
only launches local **stdio** subprocesses (`command`/`args`/`env`) — it has
|
|
46
|
+
no native `url`-based remote-server entry, so pasting the config above into
|
|
47
|
+
it will not connect. To reach the hosted endpoint from Claude Desktop, either:
|
|
48
|
+
|
|
49
|
+
- add ByteKit as a [Connector](https://claude.com/connectors) (Settings →
|
|
50
|
+
Connectors → Add custom connector), or
|
|
51
|
+
- bridge it locally with [`mcp-remote`](https://www.npmjs.com/package/mcp-remote):
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"mcpServers": {
|
|
56
|
+
"bytekit": {
|
|
57
|
+
"command": "npx",
|
|
58
|
+
"args": [
|
|
59
|
+
"-y",
|
|
60
|
+
"mcp-remote",
|
|
61
|
+
"https://api.bytekit.com/mcp",
|
|
62
|
+
"--header",
|
|
63
|
+
"Authorization: Bearer $BYTEKIT_API_KEY"
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Or skip the hosted endpoint entirely and run the **local stdio server**
|
|
71
|
+
(Option 2 below), which Claude Desktop supports natively.
|
|
72
|
+
|
|
44
73
|
## Option 2 — Local stdio (`npx`)
|
|
45
74
|
|
|
46
75
|
Run the server as a local subprocess over stdio. Nothing to install globally —
|
|
@@ -75,12 +104,13 @@ Client config for a stdio server (`claude_desktop_config.json` and equivalents):
|
|
|
75
104
|
|
|
76
105
|
### CLI flags
|
|
77
106
|
|
|
78
|
-
| Flag
|
|
79
|
-
|
|
|
80
|
-
| `--api-key <key>`
|
|
81
|
-
| `--base-url <url>`
|
|
82
|
-
| `--
|
|
83
|
-
| `--
|
|
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. |
|
|
84
114
|
|
|
85
115
|
### API-key resolution order
|
|
86
116
|
|
|
@@ -89,23 +119,49 @@ The local server resolves the key in this order:
|
|
|
89
119
|
1. `--api-key <key>` flag
|
|
90
120
|
2. `BYTEKIT_API_KEY` environment variable
|
|
91
121
|
|
|
122
|
+
### Base-URL resolution order
|
|
123
|
+
|
|
124
|
+
The base URL resolves the same way, and it is not just an `--help`-only
|
|
125
|
+
detail — it also falls back to an environment variable:
|
|
126
|
+
|
|
127
|
+
1. `--base-url <url>` flag
|
|
128
|
+
2. `BYTEKIT_BASE_URL` environment variable
|
|
129
|
+
3. `https://api.bytekit.com` (built-in default)
|
|
130
|
+
|
|
92
131
|
## Tool inventory
|
|
93
132
|
|
|
94
|
-
| Tool | What it does
|
|
95
|
-
| ---------------- |
|
|
96
|
-
| `scrape_url` | Fetch a URL and return HTML, clean markdown, links, or images.
|
|
97
|
-
| `
|
|
98
|
-
| `screenshot_url` | Capture a screenshot of a page (desktop/mobile, PNG/JPEG).
|
|
99
|
-
| `get_result` | Fetch a previously created screenshot 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.
|
|
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. |
|
|
104
143
|
|
|
105
144
|
The server also exposes **resources** (`bytekit://account`,
|
|
106
145
|
`bytekit://screenshot/{id}`) and **prompts** (`summarize_webpage`,
|
|
107
146
|
`extract_structured_data`, `research_topic`) that MCP hosts can surface directly.
|
|
108
147
|
|
|
148
|
+
### `scrape_url` output shape
|
|
149
|
+
|
|
150
|
+
`scrape_url` (and `get_result` redeeming a scrape's `sc_` handle) render every
|
|
151
|
+
requested format present in the response: the first present format (default
|
|
152
|
+
`markdown`) is unlabeled, and each additional one (`html`, `raw_html`) follows under
|
|
153
|
+
its own `--- format: <name> ---` delimiter, with `links`/`images` blocks appended
|
|
154
|
+
after. That rendered content (the requested formats plus any `links`/`images`
|
|
155
|
+
blocks) is capped at a single 100KB budget — on very large pages a requested format's
|
|
156
|
+
content may be truncated, and in extreme cases a secondary format may not appear, to
|
|
157
|
+
stay within that budget. A handful of header lines (id, URL, status, page title) are
|
|
158
|
+
added on top of the rendered content and are not counted against the cap.
|
|
159
|
+
|
|
160
|
+
None of the three textual formats is HTML-sanitized — `raw_html`, `html`, and
|
|
161
|
+
`markdown` all reflect the page's own markup (`markdown` differs only in being
|
|
162
|
+
content-extracted, not sanitized). Treat all of their content as untrusted page data,
|
|
163
|
+
the same as fetching the page directly.
|
|
164
|
+
|
|
109
165
|
## Documentation
|
|
110
166
|
|
|
111
167
|
Full MCP guide: [bytekit.com/docs/mcp](https://bytekit.com/docs/mcp).
|
package/dist/cli.d.ts
CHANGED
|
@@ -39,7 +39,24 @@ export declare function resolveBaseUrl(opts: {
|
|
|
39
39
|
flag?: string | undefined;
|
|
40
40
|
env: Record<string, string | undefined>;
|
|
41
41
|
}): string;
|
|
42
|
-
export declare const
|
|
42
|
+
export declare const TIMEOUT_MS_INVALID_MESSAGE = "Error: --timeout-ms must be a non-negative number.\n";
|
|
43
|
+
/**
|
|
44
|
+
* Parse the `--timeout-ms` flag into the numeric budget the {@link BytekitClient}
|
|
45
|
+
* constructor's `timeoutMs` option accepts, or `undefined` to let the client fall
|
|
46
|
+
* through to its own default. Mirrors {@link resolveApiKey}/{@link resolveBaseUrl}'s
|
|
47
|
+
* flag-parsing shape (empty/absent flag falls through); a non-finite parse result
|
|
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).
|
|
55
|
+
*
|
|
56
|
+
* @throws {RangeError} when the flag parses to a finite negative number.
|
|
57
|
+
*/
|
|
58
|
+
export declare function resolveTimeoutMs(flag: string | undefined): number | undefined;
|
|
59
|
+
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";
|
|
43
60
|
/**
|
|
44
61
|
* True when this module is the process entrypoint (run directly or via its bin),
|
|
45
62
|
* false when it is merely imported (e.g. the test suite exercising resolveApiKey).
|
package/dist/cli.js
CHANGED
|
@@ -44,24 +44,54 @@ export function resolveBaseUrl(opts) {
|
|
|
44
44
|
const flag = opts.flag && opts.flag.length > 0 ? opts.flag : undefined;
|
|
45
45
|
return flag ?? opts.env['BYTEKIT_BASE_URL'] ?? DEFAULT_BASE_URL;
|
|
46
46
|
}
|
|
47
|
+
export const TIMEOUT_MS_INVALID_MESSAGE = 'Error: --timeout-ms must be a non-negative number.\n';
|
|
48
|
+
/**
|
|
49
|
+
* Parse the `--timeout-ms` flag into the numeric budget the {@link BytekitClient}
|
|
50
|
+
* constructor's `timeoutMs` option accepts, or `undefined` to let the client fall
|
|
51
|
+
* through to its own default. Mirrors {@link resolveApiKey}/{@link resolveBaseUrl}'s
|
|
52
|
+
* flag-parsing shape (empty/absent flag falls through); a non-finite parse result
|
|
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).
|
|
60
|
+
*
|
|
61
|
+
* @throws {RangeError} when the flag parses to a finite negative number.
|
|
62
|
+
*/
|
|
63
|
+
export function resolveTimeoutMs(flag) {
|
|
64
|
+
if (flag === undefined || flag.length === 0)
|
|
65
|
+
return undefined;
|
|
66
|
+
const parsed = Number(flag);
|
|
67
|
+
if (!Number.isFinite(parsed))
|
|
68
|
+
return undefined;
|
|
69
|
+
if (parsed < 0) {
|
|
70
|
+
throw new RangeError(TIMEOUT_MS_INVALID_MESSAGE);
|
|
71
|
+
}
|
|
72
|
+
return parsed;
|
|
73
|
+
}
|
|
47
74
|
export const HELP_TEXT = `ByteKit MCP Server
|
|
48
75
|
|
|
49
76
|
Usage:
|
|
50
|
-
bytekit-mcp --api-key <key> [--base-url <url>] [--verbose]
|
|
77
|
+
bytekit-mcp --api-key <key> [--base-url <url>] [--timeout-ms <ms>] [--verbose]
|
|
51
78
|
|
|
52
79
|
Options:
|
|
53
|
-
--api-key
|
|
54
|
-
|
|
55
|
-
--base-url
|
|
56
|
-
|
|
57
|
-
--
|
|
58
|
-
|
|
80
|
+
--api-key ByteKit API key. Resolution order: --api-key flag, then
|
|
81
|
+
BYTEKIT_API_KEY.
|
|
82
|
+
--base-url API base URL. Resolution order: --base-url flag, then
|
|
83
|
+
BYTEKIT_BASE_URL (default: https://api.bytekit.com)
|
|
84
|
+
--timeout-ms Per-request timeout budget in milliseconds (default: 120000;
|
|
85
|
+
0 disables it)
|
|
86
|
+
--verbose Log requests to stderr
|
|
87
|
+
--help Show this help message
|
|
59
88
|
`;
|
|
60
89
|
async function main() {
|
|
61
90
|
const { values } = parseArgs({
|
|
62
91
|
options: {
|
|
63
92
|
'api-key': { type: 'string' },
|
|
64
93
|
'base-url': { type: 'string' },
|
|
94
|
+
'timeout-ms': { type: 'string' },
|
|
65
95
|
verbose: { type: 'boolean', default: false },
|
|
66
96
|
help: { type: 'boolean', default: false },
|
|
67
97
|
},
|
|
@@ -76,10 +106,27 @@ async function main() {
|
|
|
76
106
|
process.stderr.write(API_KEY_REQUIRED_MESSAGE);
|
|
77
107
|
process.exit(1);
|
|
78
108
|
}
|
|
109
|
+
// `exactOptionalPropertyTypes` forbids passing `timeoutMs: undefined` explicitly
|
|
110
|
+
// (the constructor's `timeoutMs?: number` means "present and a number", not
|
|
111
|
+
// "present and possibly undefined") — spread it in only when resolved, so an
|
|
112
|
+
// absent --timeout-ms flag falls through to the constructor's own default.
|
|
113
|
+
let timeoutMs;
|
|
114
|
+
try {
|
|
115
|
+
timeoutMs = resolveTimeoutMs(values['timeout-ms']);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
// resolveTimeoutMs throws a RangeError for a finite negative value — surface
|
|
119
|
+
// it as a graceful CLI error (mirroring the missing-API-key path below)
|
|
120
|
+
// instead of letting it propagate into the BytekitClient constructor, where
|
|
121
|
+
// validateTimeout would throw an uncaught TypeError.
|
|
122
|
+
process.stderr.write(err instanceof Error ? err.message : String(err));
|
|
123
|
+
process.exit(1);
|
|
124
|
+
}
|
|
79
125
|
const client = new BytekitClient({
|
|
80
126
|
apiKey,
|
|
81
127
|
baseUrl: resolveBaseUrl({ flag: values['base-url'], env: process.env }),
|
|
82
128
|
verbose: values.verbose,
|
|
129
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
83
130
|
});
|
|
84
131
|
const server = createServer(client);
|
|
85
132
|
const transport = new StdioServerTransport();
|
package/dist/client.d.ts
CHANGED
|
@@ -140,13 +140,47 @@ export declare class BytekitClient {
|
|
|
140
140
|
* call time so tests can stub `globalThis.fetch` without constructing a new client.
|
|
141
141
|
*/
|
|
142
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;
|
|
143
149
|
constructor(options: {
|
|
144
150
|
apiKey: string;
|
|
145
151
|
baseUrl?: string;
|
|
146
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;
|
|
147
161
|
fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
148
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;
|
|
149
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>;
|
|
150
184
|
search(params: SearchParams): Promise<SearchResponse>;
|
|
151
185
|
screenshot(params: ScreenshotParams): Promise<ScreenshotResult>;
|
|
152
186
|
getScreenshot(id: string): Promise<ScreenshotResult>;
|
|
@@ -155,5 +189,16 @@ export declare class BytekitClient {
|
|
|
155
189
|
private request;
|
|
156
190
|
private post;
|
|
157
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
|
+
*/
|
|
158
203
|
private handleErrorResponse;
|
|
159
204
|
}
|