@hunt-labs/bytekit-mcp 0.2.1 → 0.2.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/CHANGELOG.md +163 -0
- package/README.md +121 -19
- package/dist/cli.d.ts +23 -1
- package/dist/cli.js +58 -7
- package/dist/client.d.ts +43 -3
- package/dist/client.js +119 -3
- package/dist/docs-bundle/docs-bundle.json +236 -236
- package/dist/docs-bundle/helpers.d.ts +16 -0
- package/dist/docs-bundle/helpers.js +22 -0
- package/dist/lib/render-scrape.d.ts +12 -3
- package/dist/lib/render-scrape.js +142 -25
- package/dist/lib/render-screenshot.js +22 -0
- package/dist/lib/truncate.d.ts +38 -1
- package/dist/lib/truncate.js +180 -12
- package/dist/resources/account.js +7 -1
- package/dist/scrape-contract.generated.d.ts +7 -2
- package/dist/tools/get-account.js +11 -3
- package/dist/tools/get-result.js +4 -2
- 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 +61 -4
- package/dist/tools/screenshot-url.js +40 -0
- package/dist/tools/search-docs.js +15 -1
- package/dist/tools/web-search.js +23 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,167 @@ 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.3] - 2026-08-07
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `scrape_url` / `get_result` render a zero-count `Links (0):` / `Images (0):` header for
|
|
18
|
+
a format you requested that came back empty, so "the page has none" is no longer
|
|
19
|
+
indistinguishable from "the format was not returned". A format you did not request
|
|
20
|
+
still renders nothing at all. (#2687)
|
|
21
|
+
- The queued-scrape render carries the spec-required `events` array, and the success
|
|
22
|
+
render carries `content_length` — the compressed upstream wire-byte count that is the
|
|
23
|
+
billing basis for the call, which nothing else in the output surfaced. (#2687)
|
|
24
|
+
- Screenshot renders carry `page_title` (a spec field the tool description already
|
|
25
|
+
promised as "metadata") and a note that `image_url` is a signed link with a short
|
|
26
|
+
lifetime, using the concrete `expires_at` instant when the API supplies one. (#2687)
|
|
27
|
+
- A queued scrape now gets the same "Use `get_result` with this ID to check when it
|
|
28
|
+
completes." guidance a pending screenshot got in 0.2.2. (#2687)
|
|
29
|
+
- `screenshot_url` exposes `quality`, `dark_mode`, `country` and `language`. None of them
|
|
30
|
+
can reach the queued outcome; `quality` and `dark_mode` are additionally cost-neutral (a
|
|
31
|
+
screenshot bills on the phase-1 fetch's wire bytes, never the artifact size), while
|
|
32
|
+
`country`/`language` change which page the origin serves and so can change that figure.
|
|
33
|
+
`token_budget`, `clean_markdown` and `cache_ttl` stay unexposed on `scrape_url`, each
|
|
34
|
+
for a reason recorded in `src/tools/scrape-url.ts`. (#2687)
|
|
35
|
+
- **New output contract.** `scrape_url` / `get_result` render the envelope's `warnings`
|
|
36
|
+
under a `Warnings (N):` section, one `code: message (element)` line per warning, on both
|
|
37
|
+
the success and the terminal-failure render. The `(element)` suffix is omitted for the
|
|
38
|
+
whole-extraction codes that carry no element. Nothing rendered them before, so an
|
|
39
|
+
`artifact_unavailable` — a format you requested and were billed for is missing from the
|
|
40
|
+
response — was indistinguishable from a page that simply had none of it. The block is
|
|
41
|
+
budgeted inside the same 100KB cap as the content, ahead of the links/images sections, so
|
|
42
|
+
a long links list cannot crowd a failure signal out. A `warnings` array that is empty or
|
|
43
|
+
absent renders nothing, exactly as before. (#2679)
|
|
44
|
+
|
|
45
|
+
### Fixed
|
|
46
|
+
|
|
47
|
+
- **Compile-time breaking for TypeScript consumers that read `SearchResult.snippet` or
|
|
48
|
+
`SearchResult.date` unguarded.** Both were declared required on the exported
|
|
49
|
+
`SearchResult` type, but `POST /v1/search` omits both keys for `type: 'images'`
|
|
50
|
+
results — `docs/api/openapi.yaml` declares `required: [position, title, url]` and
|
|
51
|
+
nothing else for a search result. Reading `result.snippet.length` therefore compiled
|
|
52
|
+
under strict TypeScript and threw at runtime on any images result. They are now
|
|
53
|
+
`snippet?: string` and `date?: string | null`. Runtime behaviour is unchanged — the
|
|
54
|
+
server has always passed the API's JSON through verbatim, and no MCP tool output
|
|
55
|
+
moved; what changes is that `tsc` now requires a guard (`result.snippet?.length`, or
|
|
56
|
+
an `if (result.snippet !== undefined)` narrowing) at every read site. `web`/`news`
|
|
57
|
+
results still carry both fields and `date` is still nullable there, so `null`
|
|
58
|
+
(the provider reported no date) stays distinguishable from absent (the index carries
|
|
59
|
+
no such field at all). (#2781)
|
|
60
|
+
- The hosted `/mcp` transport and a local `npx` install now render invalid-argument errors
|
|
61
|
+
identically. They had diverged — hosted returned the raw Zod issue-array JSON where
|
|
62
|
+
stdio returned the flattened `Required at url` — and the cause was neither a stale
|
|
63
|
+
deploy nor a difference in ByteKit source: both transports share one server factory, and
|
|
64
|
+
the text is produced inside `@modelcontextprotocol/sdk`. What differed was the SDK
|
|
65
|
+
version each side resolved. `@modelcontextprotocol/sdk` 1.30.0 rewrote
|
|
66
|
+
`getParseErrorMessage` to format Zod issues as `<message> at <path>`, where 1.29.0 fell
|
|
67
|
+
through to `ZodError.message` (the raw JSON array). The hosted image builds with a frozen
|
|
68
|
+
lockfile, which still pinned 1.29.0, while the unpinned `^1.12.1` range let an `npx`
|
|
69
|
+
consumer resolve 1.30.0. The lockfile is now bumped to 1.30.0 so both sides run the same
|
|
70
|
+
SDK; the declared range is deliberately left at `^1.12.1` so upstream fixes keep
|
|
71
|
+
arriving. (#2682)
|
|
72
|
+
- A truncated links or images list is cut between whole entries instead of mid-URL, and
|
|
73
|
+
each affected section is annotated with `[Links truncated: N of M entries shown]`, so
|
|
74
|
+
the section header's count stays reconcilable with what was actually returned. The
|
|
75
|
+
markers are spent from the same 100KB budget, not appended on top of it. (#2687)
|
|
76
|
+
- `web_search` no longer prints the API error code twice
|
|
77
|
+
(`validation_error: … (validation_error)`); the code is appended only when the message
|
|
78
|
+
does not already carry it. (#2687)
|
|
79
|
+
- `scrape_url` rejects `formats: []` at the schema boundary — matching the API's own
|
|
80
|
+
`minItems: 1` — instead of forwarding it and returning a server 422. Omitting the
|
|
81
|
+
parameter still yields the `["markdown"]` default. (#2687)
|
|
82
|
+
- `--timeout-ms` with a non-numeric value is rejected with an error instead of being
|
|
83
|
+
silently ignored, which had left the client running on its default budget while the
|
|
84
|
+
operator believed one was set. (#2687)
|
|
85
|
+
- Reading `bytekit://account` issues its two sub-requests serially, matching the
|
|
86
|
+
`get_account` tool — concurrent sub-requests could rate-limit a 1-rps plan against
|
|
87
|
+
itself. (#2687)
|
|
88
|
+
- `list_docs` with a `section` outside the documentation taxonomy returns an error naming
|
|
89
|
+
the valid set, rather than a silent empty list that a correctly-spelled but empty
|
|
90
|
+
section would also produce. (#2687)
|
|
91
|
+
- The Claude Desktop / `mcp-remote` bridge config in README.md now authenticates as
|
|
92
|
+
written. It previously passed `"Authorization: Bearer $BYTEKIT_API_KEY"` in `args`;
|
|
93
|
+
an MCP host launches `command`/`args` with no shell, and `mcp-remote` interpolates
|
|
94
|
+
only the braced `${VAR}` form, so the literal text was sent as the bearer token and
|
|
95
|
+
the endpoint answered `401`. The snippet now uses `"Authorization:${AUTH_HEADER}"`
|
|
96
|
+
with a matching `env` block, and the hosted-HTTP snippet carries the same
|
|
97
|
+
no-shell-expansion caveat. (#2688)
|
|
98
|
+
- The bundled documentation no longer teaches the deactivated `/v1/recordings` endpoint
|
|
99
|
+
or links its removed reference pages. (#2688)
|
|
100
|
+
- A 429 caused by the account's **concurrency** cap now says so and fails fast, instead of
|
|
101
|
+
being reported as a rate limit. HTTP 429 carries two conditions (`rate_limited` and
|
|
102
|
+
`concurrency_limit`), and the client read neither the body nor the code: every 429 got
|
|
103
|
+
one `Retry-After` retry and then `Rate limited. Try again in a moment.` with the error
|
|
104
|
+
code hardcoded to `rate_limited`. The concurrency variant does not clear on that
|
|
105
|
+
back-off — the API spec calls its `Retry-After` "a fixed small back-off" while the slots
|
|
106
|
+
free only when the in-flight jobs finish — so the retry was spent on a condition a
|
|
107
|
+
second cannot clear, and the error object named the wrong cause. A `concurrency_limit`
|
|
108
|
+
429 now throws immediately with the real wait scale and `errorCode: 'concurrency_limit'`,
|
|
109
|
+
at both 429 sites. `rate_limited` 429s, and any 429 whose body is empty, non-JSON or
|
|
110
|
+
carries no recognizable code, keep the single honored-header retry and the exact message
|
|
111
|
+
and code they had. (#2681)
|
|
112
|
+
- A screenshot that fails inside the API's sync hold now surfaces its REAL failure code
|
|
113
|
+
(`blocked`, `timeout`, …) and message. `POST /v1/screenshots` answers that case with HTTP
|
|
114
|
+
422 carrying the flat screenshot resource, not the unified error envelope, and the client
|
|
115
|
+
parsed neither — so every such failure read as the literal `Validation error.`. The
|
|
116
|
+
`(Screenshot ID: ss_…)` handle line is unchanged, and a genuine request-validation 422
|
|
117
|
+
still renders exactly as it did. (#2679)
|
|
118
|
+
|
|
119
|
+
## [0.2.2] - 2026-07-29
|
|
120
|
+
|
|
121
|
+
### Fixed
|
|
122
|
+
|
|
123
|
+
- `scrape_url` / `get_result` render every returned textual format
|
|
124
|
+
(`markdown`/`html`/`raw_html`), not just the first present — a multi-format call
|
|
125
|
+
previously dropped every secondary format silently despite it being billed. Secondary
|
|
126
|
+
formats are rendered under a `--- format: <name> ---` delimiter, in canonical order
|
|
127
|
+
after the unlabeled primary. (#2589)
|
|
128
|
+
- The 100KB output truncation budget now covers the links/images blocks too — they were
|
|
129
|
+
previously appended AFTER truncation, so a combined output could exceed the budget.
|
|
130
|
+
The whole assembled payload is now truncated exactly once, with the links/images
|
|
131
|
+
block reserved its own share of the budget so it is never dropped in full just
|
|
132
|
+
because the textual formats alone already fill the budget. (#2589)
|
|
133
|
+
- `scrape_url` / `get_result` descriptions no longer advertise a queued `sc_` outcome
|
|
134
|
+
that the MCP input schema (`url`/`formats`/`country`) cannot produce — that outcome
|
|
135
|
+
was only reachable via `body.async` or fields `can-fast-path.ts` gates on, none of
|
|
136
|
+
which this tool's schema exposes. (#2589)
|
|
137
|
+
- `web_search` now renders `credits_used` and `related_searches`, both spec-required
|
|
138
|
+
fields that were previously dropped silently. (#2591)
|
|
139
|
+
- A sync-failed screenshot's `ss_` handle — absent from the 422 error body — is now
|
|
140
|
+
read from the `X-Screenshot-ID` response header and included in the error text, so
|
|
141
|
+
it can still be redeemed via `get_result`. Degrades gracefully when the header is
|
|
142
|
+
absent. (#2591)
|
|
143
|
+
- The 402 message on `/v1/screenshots` no longer says "Bandwidth quota exhausted"
|
|
144
|
+
(screenshot quotas are credit/count-based) and no longer points at `get_account`,
|
|
145
|
+
which is rate-limit-fragile immediately after a quota failure. Every other endpoint's
|
|
146
|
+
402 wording is unchanged. (#2591)
|
|
147
|
+
- `get_result`'s invalid-id-prefix message no longer truncates the offending id to 3
|
|
148
|
+
characters. (#2591)
|
|
149
|
+
- `get_result` now gives the same "poll with get_result" guidance `screenshot_url`'s
|
|
150
|
+
queued branch gives when a screenshot is still `pending`/`processing`. (#2591)
|
|
151
|
+
- `get_account` no longer renders a duplicate email (`Account: foo@bar.com
|
|
152
|
+
(foo@bar.com)`) when the account has no name. (#2591)
|
|
153
|
+
- `search_docs` snippets no longer duplicate the page title when the match falls near
|
|
154
|
+
the body's own leading `# <Title>` heading. (#2591)
|
|
155
|
+
- `ScrapeErrorEnvelope.id` is now modeled as nullable, matching
|
|
156
|
+
`docs/api/openapi.yaml` (`id` is null when a scrape was never queued, e.g. a
|
|
157
|
+
validation failure) — `get_result`/`scrape_url` render `ID: —` instead of the
|
|
158
|
+
literal `ID: null`. (#2591)
|
|
159
|
+
|
|
160
|
+
### Changed
|
|
161
|
+
|
|
162
|
+
- `get_account` now issues its `getAccount`/`getUsage` requests serially instead of
|
|
163
|
+
via `Promise.all`, so it no longer doubles the concurrent request rate against
|
|
164
|
+
1-rps plans. (#2591)
|
|
165
|
+
- Regenerated the bundled `src/docs-bundle/docs-bundle.json` against the current
|
|
166
|
+
`packages/docs/content` tree. Every guarded endpoint's docs page now states its
|
|
167
|
+
request-body byte ceiling and the `request_too_large` error code (#2640), and the
|
|
168
|
+
`/v1/bulk` pages document `defaults.type` inheritance plus the 422 on unrecognized
|
|
169
|
+
keys (#2643). Content only — no tool surface, schema, or runtime behavior changed.
|
|
170
|
+
(#2640, #2643)
|
|
171
|
+
|
|
11
172
|
## [0.2.1] - 2026-07-24
|
|
12
173
|
|
|
13
174
|
### Fixed
|
|
@@ -122,6 +283,8 @@ today, see [README.md](./README.md), which remains the authoritative usage guide
|
|
|
122
283
|
(scrape, screenshot, search, docs) to AI agents over the Model Context Protocol,
|
|
123
284
|
as a local stdio server or hosted.
|
|
124
285
|
|
|
286
|
+
[0.2.2]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
287
|
+
[0.2.1]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
125
288
|
[0.2.0]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
126
289
|
[0.1.3]: https://github.com/Hunt-Labs-Inc/ByteKit/tree/main/packages/mcp-server
|
|
127
290
|
[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
|
{
|
|
@@ -34,13 +34,67 @@ 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
|
+
|
|
49
|
+
**Claude Desktop does not accept this shape.** `claude_desktop_config.json`
|
|
50
|
+
only launches local **stdio** subprocesses (`command`/`args`/`env`) — it has
|
|
51
|
+
no native `url`-based remote-server entry, so pasting the config above into
|
|
52
|
+
it will not connect. To reach the hosted endpoint from Claude Desktop, either:
|
|
53
|
+
|
|
54
|
+
- add ByteKit as a [Connector](https://claude.com/connectors) (Settings →
|
|
55
|
+
Connectors → Add custom connector), or
|
|
56
|
+
- bridge it locally with [`mcp-remote`](https://www.npmjs.com/package/mcp-remote):
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"mcpServers": {
|
|
61
|
+
"bytekit": {
|
|
62
|
+
"command": "npx",
|
|
63
|
+
"args": [
|
|
64
|
+
"-y",
|
|
65
|
+
"mcp-remote",
|
|
66
|
+
"https://api.bytekit.com/mcp",
|
|
67
|
+
"--header",
|
|
68
|
+
"Authorization:${AUTH_HEADER}"
|
|
69
|
+
],
|
|
70
|
+
"env": {
|
|
71
|
+
"AUTH_HEADER": "Bearer sk_live_xxx"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
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
|
+
|
|
95
|
+
Or skip the hosted endpoint entirely and run the **local stdio server**
|
|
96
|
+
(Option 2 below), which Claude Desktop supports natively.
|
|
97
|
+
|
|
44
98
|
## Option 2 — Local stdio (`npx`)
|
|
45
99
|
|
|
46
100
|
Run the server as a local subprocess over stdio. Nothing to install globally —
|
|
@@ -75,12 +129,13 @@ Client config for a stdio server (`claude_desktop_config.json` and equivalents):
|
|
|
75
129
|
|
|
76
130
|
### CLI flags
|
|
77
131
|
|
|
78
|
-
| Flag
|
|
79
|
-
|
|
|
80
|
-
| `--api-key <key>`
|
|
81
|
-
| `--base-url <url>`
|
|
82
|
-
| `--
|
|
83
|
-
| `--
|
|
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. |
|
|
84
139
|
|
|
85
140
|
### API-key resolution order
|
|
86
141
|
|
|
@@ -89,23 +144,70 @@ The local server resolves the key in this order:
|
|
|
89
144
|
1. `--api-key <key>` flag
|
|
90
145
|
2. `BYTEKIT_API_KEY` environment variable
|
|
91
146
|
|
|
147
|
+
### Base-URL resolution order
|
|
148
|
+
|
|
149
|
+
The base URL resolves the same way, and it is not just an `--help`-only
|
|
150
|
+
detail — it also falls back to an environment variable:
|
|
151
|
+
|
|
152
|
+
1. `--base-url <url>` flag
|
|
153
|
+
2. `BYTEKIT_BASE_URL` environment variable
|
|
154
|
+
3. `https://api.bytekit.com` (built-in default)
|
|
155
|
+
|
|
92
156
|
## Tool inventory
|
|
93
157
|
|
|
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.
|
|
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. |
|
|
104
168
|
|
|
105
169
|
The server also exposes **resources** (`bytekit://account`,
|
|
106
170
|
`bytekit://screenshot/{id}`) and **prompts** (`summarize_webpage`,
|
|
107
171
|
`extract_structured_data`, `research_topic`) that MCP hosts can surface directly.
|
|
108
172
|
|
|
173
|
+
### `scrape_url` output shape
|
|
174
|
+
|
|
175
|
+
`scrape_url` (and `get_result` redeeming a scrape's `sc_` handle) render every
|
|
176
|
+
requested format present in the response: the first present format (default
|
|
177
|
+
`markdown`) is unlabeled, and each additional one (`html`, `raw_html`) follows under
|
|
178
|
+
its own `--- format: <name> ---` delimiter, with `links`/`images` blocks appended
|
|
179
|
+
after. That rendered content (the requested formats plus any `links`/`images`
|
|
180
|
+
blocks) is capped at a single 100KB budget — on very large pages a requested format's
|
|
181
|
+
content may be truncated, and in extreme cases a secondary format may not appear, to
|
|
182
|
+
stay within that budget. A handful of header lines (id, URL, status, page title) are
|
|
183
|
+
added on top of the rendered content and are not counted against the cap.
|
|
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
|
+
|
|
206
|
+
None of the three textual formats is HTML-sanitized — `raw_html`, `html`, and
|
|
207
|
+
`markdown` all reflect the page's own markup (`markdown` differs only in being
|
|
208
|
+
content-extracted, not sanitized). Treat all of their content as untrusted page data,
|
|
209
|
+
the same as fetching the page directly.
|
|
210
|
+
|
|
109
211
|
## Documentation
|
|
110
212
|
|
|
111
213
|
Full MCP guide: [bytekit.com/docs/mcp](https://bytekit.com/docs/mcp).
|
package/dist/cli.d.ts
CHANGED
|
@@ -39,7 +39,29 @@ 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: an absent or empty flag falls through.
|
|
48
|
+
*
|
|
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.
|
|
62
|
+
*/
|
|
63
|
+
export declare function resolveTimeoutMs(flag: string | undefined): number | undefined;
|
|
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";
|
|
43
65
|
/**
|
|
44
66
|
* True when this module is the process entrypoint (run directly or via its bin),
|
|
45
67
|
* false when it is merely imported (e.g. the test suite exercising resolveApiKey).
|
package/dist/cli.js
CHANGED
|
@@ -44,24 +44,57 @@ 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: an absent or empty flag falls through.
|
|
53
|
+
*
|
|
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.
|
|
67
|
+
*/
|
|
68
|
+
export function resolveTimeoutMs(flag) {
|
|
69
|
+
if (flag === undefined || flag.length === 0)
|
|
70
|
+
return undefined;
|
|
71
|
+
const parsed = Number(flag);
|
|
72
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
73
|
+
throw new RangeError(TIMEOUT_MS_INVALID_MESSAGE);
|
|
74
|
+
}
|
|
75
|
+
return parsed;
|
|
76
|
+
}
|
|
47
77
|
export const HELP_TEXT = `ByteKit MCP Server
|
|
48
78
|
|
|
49
79
|
Usage:
|
|
50
|
-
bytekit-mcp --api-key <key> [--base-url <url>] [--verbose]
|
|
80
|
+
bytekit-mcp --api-key <key> [--base-url <url>] [--timeout-ms <ms>] [--verbose]
|
|
51
81
|
|
|
52
82
|
Options:
|
|
53
|
-
--api-key
|
|
54
|
-
|
|
55
|
-
--base-url
|
|
56
|
-
|
|
57
|
-
--
|
|
58
|
-
|
|
83
|
+
--api-key ByteKit API key. Resolution order: --api-key flag, then
|
|
84
|
+
BYTEKIT_API_KEY.
|
|
85
|
+
--base-url API base URL. Resolution order: --base-url flag, then
|
|
86
|
+
BYTEKIT_BASE_URL (default: https://api.bytekit.com)
|
|
87
|
+
--timeout-ms Per-request timeout budget in milliseconds (default: 120000;
|
|
88
|
+
0 disables it)
|
|
89
|
+
--verbose Log requests to stderr
|
|
90
|
+
--help Show this help message
|
|
59
91
|
`;
|
|
60
92
|
async function main() {
|
|
61
93
|
const { values } = parseArgs({
|
|
62
94
|
options: {
|
|
63
95
|
'api-key': { type: 'string' },
|
|
64
96
|
'base-url': { type: 'string' },
|
|
97
|
+
'timeout-ms': { type: 'string' },
|
|
65
98
|
verbose: { type: 'boolean', default: false },
|
|
66
99
|
help: { type: 'boolean', default: false },
|
|
67
100
|
},
|
|
@@ -76,10 +109,28 @@ async function main() {
|
|
|
76
109
|
process.stderr.write(API_KEY_REQUIRED_MESSAGE);
|
|
77
110
|
process.exit(1);
|
|
78
111
|
}
|
|
112
|
+
// `exactOptionalPropertyTypes` forbids passing `timeoutMs: undefined` explicitly
|
|
113
|
+
// (the constructor's `timeoutMs?: number` means "present and a number", not
|
|
114
|
+
// "present and possibly undefined") — spread it in only when resolved, so an
|
|
115
|
+
// absent --timeout-ms flag falls through to the constructor's own default.
|
|
116
|
+
let timeoutMs;
|
|
117
|
+
try {
|
|
118
|
+
timeoutMs = resolveTimeoutMs(values['timeout-ms']);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
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.
|
|
126
|
+
process.stderr.write(err instanceof Error ? err.message : String(err));
|
|
127
|
+
process.exit(1);
|
|
128
|
+
}
|
|
79
129
|
const client = new BytekitClient({
|
|
80
130
|
apiKey,
|
|
81
131
|
baseUrl: resolveBaseUrl({ flag: values['base-url'], env: process.env }),
|
|
82
132
|
verbose: values.verbose,
|
|
133
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
83
134
|
});
|
|
84
135
|
const server = createServer(client);
|
|
85
136
|
const transport = new StdioServerTransport();
|
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
|
*
|