@hunt-labs/bytekit-mcp 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +64 -0
- package/README.md +11 -13
- package/dist/cli.d.ts +3 -5
- package/dist/cli.js +4 -6
- package/dist/client.d.ts +79 -12
- package/dist/client.js +302 -22
- package/dist/docs-bundle/docs-bundle.json +149 -119
- package/dist/docs-bundle/helpers.d.ts +17 -1
- package/dist/docs-bundle/helpers.js +25 -0
- package/dist/docs-bundle/load-bundle.d.ts +7 -4
- package/dist/docs-bundle/load-bundle.js +10 -5
- package/dist/lib/render-scrape.d.ts +27 -0
- package/dist/lib/render-scrape.js +83 -0
- package/dist/lib/render-screenshot.d.ts +18 -0
- package/dist/lib/render-screenshot.js +38 -0
- package/dist/tools/get-account.js +3 -1
- package/dist/tools/get-doc.js +1 -1
- package/dist/tools/get-result.js +19 -15
- package/dist/tools/list-docs.d.ts +6 -0
- package/dist/tools/list-docs.js +8 -4
- package/dist/tools/scrape-url.js +5 -69
- package/dist/tools/screenshot-url.js +5 -17
- package/dist/tools/web-search.js +6 -2
- package/package.json +1 -1
|
@@ -5,6 +5,22 @@
|
|
|
5
5
|
* without spinning up the Next.js server. The build script imports them at
|
|
6
6
|
* runtime; the test suite imports them for unit coverage.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Every section label `slugToSection` can return.
|
|
10
|
+
*
|
|
11
|
+
* This is the single source of truth for the docs taxonomy: the bundle
|
|
12
|
+
* generator stamps `section` from `slugToSection`, and `list_docs` advertises
|
|
13
|
+
* its `section` filter values by joining this tuple. Adding a mapping below
|
|
14
|
+
* without adding its label here (or vice versa) is caught by the bundle
|
|
15
|
+
* invariant test in `src/__tests__/build-docs-bundle.test.ts`.
|
|
16
|
+
*
|
|
17
|
+
* `'General'` is the deliberate fallback for bare top-level pages
|
|
18
|
+
* (`changelog`, `introduction`, `mcp`, `quickstart`) — not a catch-all for
|
|
19
|
+
* unmapped directories (issue #2570).
|
|
20
|
+
*/
|
|
21
|
+
export declare const DOC_SECTIONS: readonly ["Guides", "API Reference", "SDK Reference", "CLI Reference", "Libraries", "General"];
|
|
22
|
+
/** One of the section labels enumerated by {@link DOC_SECTIONS}. */
|
|
23
|
+
export type DocSection = (typeof DOC_SECTIONS)[number];
|
|
8
24
|
/**
|
|
9
25
|
* Maps a page slug (array of path segments) to a human-readable section
|
|
10
26
|
* label for the bundle schema.
|
|
@@ -12,7 +28,7 @@
|
|
|
12
28
|
* Slug segments come from the fumadocs source manifest and mirror the
|
|
13
29
|
* directory structure under `content/docs/`.
|
|
14
30
|
*/
|
|
15
|
-
export declare function slugToSection(slug: string[]):
|
|
31
|
+
export declare function slugToSection(slug: string[]): DocSection;
|
|
16
32
|
/**
|
|
17
33
|
* Returns true for the root landing page, which should be excluded from
|
|
18
34
|
* the bundle (it contains only JSX nav cards, no prose content).
|
|
@@ -5,6 +5,27 @@
|
|
|
5
5
|
* without spinning up the Next.js server. The build script imports them at
|
|
6
6
|
* runtime; the test suite imports them for unit coverage.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Every section label `slugToSection` can return.
|
|
10
|
+
*
|
|
11
|
+
* This is the single source of truth for the docs taxonomy: the bundle
|
|
12
|
+
* generator stamps `section` from `slugToSection`, and `list_docs` advertises
|
|
13
|
+
* its `section` filter values by joining this tuple. Adding a mapping below
|
|
14
|
+
* without adding its label here (or vice versa) is caught by the bundle
|
|
15
|
+
* invariant test in `src/__tests__/build-docs-bundle.test.ts`.
|
|
16
|
+
*
|
|
17
|
+
* `'General'` is the deliberate fallback for bare top-level pages
|
|
18
|
+
* (`changelog`, `introduction`, `mcp`, `quickstart`) — not a catch-all for
|
|
19
|
+
* unmapped directories (issue #2570).
|
|
20
|
+
*/
|
|
21
|
+
export const DOC_SECTIONS = [
|
|
22
|
+
'Guides',
|
|
23
|
+
'API Reference',
|
|
24
|
+
'SDK Reference',
|
|
25
|
+
'CLI Reference',
|
|
26
|
+
'Libraries',
|
|
27
|
+
'General',
|
|
28
|
+
];
|
|
8
29
|
/**
|
|
9
30
|
* Maps a page slug (array of path segments) to a human-readable section
|
|
10
31
|
* label for the bundle schema.
|
|
@@ -20,6 +41,10 @@ export function slugToSection(slug) {
|
|
|
20
41
|
return 'API Reference';
|
|
21
42
|
if (first === 'sdk')
|
|
22
43
|
return 'SDK Reference';
|
|
44
|
+
if (first === 'cli')
|
|
45
|
+
return 'CLI Reference';
|
|
46
|
+
if (first === 'libraries')
|
|
47
|
+
return 'Libraries';
|
|
23
48
|
return 'General';
|
|
24
49
|
}
|
|
25
50
|
/**
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Loads the generated docs-bundle.json from disk.
|
|
3
3
|
*
|
|
4
|
-
* The bundle is produced by
|
|
5
|
-
* (
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The bundle is produced by the mcp-server build's generator hook
|
|
5
|
+
* (`scripts/build-docs-bundle.ts`) and is committed to git so the gateway
|
|
6
|
+
* Docker image (built by Coolify from a git checkout) ships it (#2469).
|
|
7
|
+
* If it is genuinely missing, this function throws a NEUTRAL, customer-safe
|
|
8
|
+
* message — the thrown message becomes the MCP tool result text — and logs the
|
|
9
|
+
* operator-facing build hint via console.warn (server-side only, never surfaced
|
|
10
|
+
* to the client).
|
|
8
11
|
*/
|
|
9
12
|
export interface BundleEntry {
|
|
10
13
|
title: string;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Loads the generated docs-bundle.json from disk.
|
|
3
3
|
*
|
|
4
|
-
* The bundle is produced by
|
|
5
|
-
* (
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* The bundle is produced by the mcp-server build's generator hook
|
|
5
|
+
* (`scripts/build-docs-bundle.ts`) and is committed to git so the gateway
|
|
6
|
+
* Docker image (built by Coolify from a git checkout) ships it (#2469).
|
|
7
|
+
* If it is genuinely missing, this function throws a NEUTRAL, customer-safe
|
|
8
|
+
* message — the thrown message becomes the MCP tool result text — and logs the
|
|
9
|
+
* operator-facing build hint via console.warn (server-side only, never surfaced
|
|
10
|
+
* to the client).
|
|
8
11
|
*/
|
|
9
12
|
import { readFile } from 'node:fs/promises';
|
|
10
13
|
import { fileURLToPath } from 'node:url';
|
|
@@ -18,7 +21,9 @@ export async function loadBundle() {
|
|
|
18
21
|
catch (err) {
|
|
19
22
|
const isNotFound = err instanceof Error && err.code === 'ENOENT';
|
|
20
23
|
if (isNotFound) {
|
|
21
|
-
|
|
24
|
+
// Operator-facing hint stays server-side; it must not reach the MCP client.
|
|
25
|
+
console.warn('docs bundle missing at runtime — regenerate and commit the docs bundle (mcp-server build)');
|
|
26
|
+
throw new Error('The documentation index is temporarily unavailable. Please try again shortly.', { cause: err });
|
|
22
27
|
}
|
|
23
28
|
throw err;
|
|
24
29
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ScrapeResult } from '../client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Renders a scrape envelope (from POST /v1/scrape or GET /v1/scrape/{id}) into
|
|
4
|
+
* human-readable lines for MCP tool output.
|
|
5
|
+
*
|
|
6
|
+
* This is the single scrape formatter (issue #2538, E3). Both `scrape_url` (which
|
|
7
|
+
* produces an envelope) and `get_result` (which redeems an `sc_` handle) render through
|
|
8
|
+
* it, so the two surfaces cannot drift: a render-requiring scrape answered with 202 +
|
|
9
|
+
* queued envelope is described the same way whether the agent saw it at submit time or
|
|
10
|
+
* at poll time.
|
|
11
|
+
*
|
|
12
|
+
* Handles all three envelope shapes the API returns (scrape-contract.generated.ts):
|
|
13
|
+
* - queued: `{ status:'queued', id, url, status_url, queued_at, events }` — the async
|
|
14
|
+
* handle, and also what GET returns while the job is pending/processing (gateway
|
|
15
|
+
* routes/scrape.ts `handleGetScrapeById`). Non-error: the agent should poll, not fail.
|
|
16
|
+
* - failed: `{ status:'failed', id, error:{ code, message, ... } }` — flagged as a tool
|
|
17
|
+
* error, rendering the public error code + message only.
|
|
18
|
+
* - success: full envelope; primary content prefers markdown → html → raw_html, with
|
|
19
|
+
* optional links/images blocks appended.
|
|
20
|
+
*
|
|
21
|
+
* Every optional line is omitted when absent, so no `undefined`/`null` literal is ever
|
|
22
|
+
* emitted (issue #2419).
|
|
23
|
+
*/
|
|
24
|
+
export declare function renderScrapeResult(result: ScrapeResult): {
|
|
25
|
+
text: string;
|
|
26
|
+
isError: boolean;
|
|
27
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { truncateContent } from './truncate.js';
|
|
2
|
+
function renderLinks(links) {
|
|
3
|
+
return links
|
|
4
|
+
.map((link) => typeof link === 'string' ? link : `${link.url}${link.text ? ` — ${link.text}` : ''}`)
|
|
5
|
+
.join('\n');
|
|
6
|
+
}
|
|
7
|
+
function renderImages(images) {
|
|
8
|
+
return images
|
|
9
|
+
.map((image) => typeof image === 'string' ? image : `${image.url}${image.alt ? ` — ${image.alt}` : ''}`)
|
|
10
|
+
.join('\n');
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Renders a scrape envelope (from POST /v1/scrape or GET /v1/scrape/{id}) into
|
|
14
|
+
* human-readable lines for MCP tool output.
|
|
15
|
+
*
|
|
16
|
+
* This is the single scrape formatter (issue #2538, E3). Both `scrape_url` (which
|
|
17
|
+
* produces an envelope) and `get_result` (which redeems an `sc_` handle) render through
|
|
18
|
+
* it, so the two surfaces cannot drift: a render-requiring scrape answered with 202 +
|
|
19
|
+
* queued envelope is described the same way whether the agent saw it at submit time or
|
|
20
|
+
* at poll time.
|
|
21
|
+
*
|
|
22
|
+
* Handles all three envelope shapes the API returns (scrape-contract.generated.ts):
|
|
23
|
+
* - queued: `{ status:'queued', id, url, status_url, queued_at, events }` — the async
|
|
24
|
+
* handle, and also what GET returns while the job is pending/processing (gateway
|
|
25
|
+
* routes/scrape.ts `handleGetScrapeById`). Non-error: the agent should poll, not fail.
|
|
26
|
+
* - failed: `{ status:'failed', id, error:{ code, message, ... } }` — flagged as a tool
|
|
27
|
+
* error, rendering the public error code + message only.
|
|
28
|
+
* - success: full envelope; primary content prefers markdown → html → raw_html, with
|
|
29
|
+
* optional links/images blocks appended.
|
|
30
|
+
*
|
|
31
|
+
* Every optional line is omitted when absent, so no `undefined`/`null` literal is ever
|
|
32
|
+
* emitted (issue #2419).
|
|
33
|
+
*/
|
|
34
|
+
export function renderScrapeResult(result) {
|
|
35
|
+
if (result.status === 'queued') {
|
|
36
|
+
return {
|
|
37
|
+
text: [
|
|
38
|
+
`ID: ${result.id}`,
|
|
39
|
+
'Status: queued',
|
|
40
|
+
`URL: ${result.url}`,
|
|
41
|
+
`Status URL: ${result.status_url}`,
|
|
42
|
+
].join('\n'),
|
|
43
|
+
isError: false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (result.status === 'failed') {
|
|
47
|
+
return {
|
|
48
|
+
text: [
|
|
49
|
+
`ID: ${result.id}`,
|
|
50
|
+
'Status: failed',
|
|
51
|
+
`Error: ${result.error.code}`,
|
|
52
|
+
result.error.message,
|
|
53
|
+
].join('\n'),
|
|
54
|
+
isError: true,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Primary content for display: prefer markdown → html → rawHtml
|
|
58
|
+
const content = result.formats.markdown ?? result.formats.html ?? result.formats.raw_html ?? '';
|
|
59
|
+
const { text, truncated } = truncateContent(content);
|
|
60
|
+
const metaLines = [
|
|
61
|
+
`ID: ${result.id}`,
|
|
62
|
+
`URL: ${result.url}`,
|
|
63
|
+
result.final_url !== result.url ? `Final URL: ${result.final_url}` : null,
|
|
64
|
+
result.status_code !== null ? `Status Code: ${result.status_code}` : null,
|
|
65
|
+
result.content_type ? `Content-Type: ${result.content_type}` : null,
|
|
66
|
+
result.metadata.title ? `Title: ${result.metadata.title}` : null,
|
|
67
|
+
truncated ? 'Note: Content was truncated to 100KB' : null,
|
|
68
|
+
]
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join('\n');
|
|
71
|
+
let body = `${metaLines}\n\n---\n\n${text}`;
|
|
72
|
+
// Append links block when present
|
|
73
|
+
if (Array.isArray(result.formats.links) && result.formats.links.length > 0) {
|
|
74
|
+
const linkList = renderLinks(result.formats.links);
|
|
75
|
+
body += `\n\nLinks (${result.formats.links.length}):\n${linkList}`;
|
|
76
|
+
}
|
|
77
|
+
// Append images block when present
|
|
78
|
+
if (Array.isArray(result.formats.images) && result.formats.images.length > 0) {
|
|
79
|
+
const imgList = renderImages(result.formats.images);
|
|
80
|
+
body += `\n\nImages (${result.formats.images.length}):\n${imgList}`;
|
|
81
|
+
}
|
|
82
|
+
return { text: body, isError: false };
|
|
83
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ScreenshotResult } from '../client.js';
|
|
2
|
+
/**
|
|
3
|
+
* Renders a screenshot resource (from POST /v1/screenshots or GET /v1/screenshots/:id)
|
|
4
|
+
* into human-readable lines for MCP tool output.
|
|
5
|
+
*
|
|
6
|
+
* Handles the envelope shapes the API returns (issue #2477):
|
|
7
|
+
* - failed (#2027): { status:'failed', error:{ code, message, ... } } — no id/url/image_url.
|
|
8
|
+
* Rendered as `Status: failed` plus the error code/message, flagged as a tool error.
|
|
9
|
+
* - pending/processing: top-level fields present but null (e.g. credits_charged:null).
|
|
10
|
+
* - completed: full spec fields (openapi.yaml ScreenshotResponse: image_width, image_height,
|
|
11
|
+
* file_size_bytes; there is no `format` field).
|
|
12
|
+
*
|
|
13
|
+
* Never emits a `undefined`/`null` literal line: every optional line is omitted when absent.
|
|
14
|
+
*/
|
|
15
|
+
export declare function renderScreenshotResult(result: ScreenshotResult): {
|
|
16
|
+
text: string;
|
|
17
|
+
isError: boolean;
|
|
18
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders a screenshot resource (from POST /v1/screenshots or GET /v1/screenshots/:id)
|
|
3
|
+
* into human-readable lines for MCP tool output.
|
|
4
|
+
*
|
|
5
|
+
* Handles the envelope shapes the API returns (issue #2477):
|
|
6
|
+
* - failed (#2027): { status:'failed', error:{ code, message, ... } } — no id/url/image_url.
|
|
7
|
+
* Rendered as `Status: failed` plus the error code/message, flagged as a tool error.
|
|
8
|
+
* - pending/processing: top-level fields present but null (e.g. credits_charged:null).
|
|
9
|
+
* - completed: full spec fields (openapi.yaml ScreenshotResponse: image_width, image_height,
|
|
10
|
+
* file_size_bytes; there is no `format` field).
|
|
11
|
+
*
|
|
12
|
+
* Never emits a `undefined`/`null` literal line: every optional line is omitted when absent.
|
|
13
|
+
*/
|
|
14
|
+
export function renderScreenshotResult(result) {
|
|
15
|
+
if (result.status === 'failed') {
|
|
16
|
+
const err = result.error;
|
|
17
|
+
const lines = [
|
|
18
|
+
'Status: failed',
|
|
19
|
+
err?.code ? `Error code: ${err.code}` : null,
|
|
20
|
+
err?.message ? `Error: ${err.message}` : null,
|
|
21
|
+
].filter((line) => line !== null);
|
|
22
|
+
return { text: lines.join('\n'), isError: true };
|
|
23
|
+
}
|
|
24
|
+
const lines = [
|
|
25
|
+
result.id ? `ID: ${result.id}` : null,
|
|
26
|
+
result.url ? `URL: ${result.url}` : null,
|
|
27
|
+
`Status: ${result.status}`,
|
|
28
|
+
result.image_url ? `Image: ${result.image_url}` : null,
|
|
29
|
+
result.image_width && result.image_height
|
|
30
|
+
? `Size: ${result.image_width}x${result.image_height}`
|
|
31
|
+
: null,
|
|
32
|
+
result.file_size_bytes ? `File size: ${result.file_size_bytes} bytes` : null,
|
|
33
|
+
result.credits_charged !== undefined && result.credits_charged !== null
|
|
34
|
+
? `Credits: ${result.credits_charged}`
|
|
35
|
+
: null,
|
|
36
|
+
].filter((line) => line !== null);
|
|
37
|
+
return { text: lines.join('\n'), isError: false };
|
|
38
|
+
}
|
|
@@ -2,8 +2,10 @@ export function getAccountTool(server, client) {
|
|
|
2
2
|
server.tool('get_account', 'Get your ByteKit account details, plan info, and current usage/quota.', {}, async () => {
|
|
3
3
|
try {
|
|
4
4
|
const [account, usage] = await Promise.all([client.getAccount(), client.getUsage()]);
|
|
5
|
+
// The API may return a null account name (issue #2477) — fall back to the email
|
|
6
|
+
// rather than rendering the literal `Account: null`.
|
|
5
7
|
const lines = [
|
|
6
|
-
`Account: ${account.name} (${account.email})`,
|
|
8
|
+
`Account: ${account.name ?? account.email} (${account.email})`,
|
|
7
9
|
`Account ID: ${account.id}`,
|
|
8
10
|
'',
|
|
9
11
|
`Plan: ${account.plan.name} (${account.plan.slug})`,
|
package/dist/tools/get-doc.js
CHANGED
|
@@ -23,7 +23,7 @@ export function getDocTool(server) {
|
|
|
23
23
|
server.tool('get_doc', 'Retrieve the full rendered markdown for a specific documentation page. Use list_docs or search_docs to discover valid paths first.', {
|
|
24
24
|
path: z
|
|
25
25
|
.string()
|
|
26
|
-
.describe('Relative doc path (e.g. "guides/authentication", "api/
|
|
26
|
+
.describe('Relative doc path (e.g. "guides/authentication", "api/scrape/createscrape")'),
|
|
27
27
|
}, async (params) => {
|
|
28
28
|
if (!isValidPath(params.path)) {
|
|
29
29
|
return {
|
package/dist/tools/get-result.js
CHANGED
|
@@ -1,35 +1,39 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { renderScrapeResult } from '../lib/render-scrape.js';
|
|
3
|
+
import { renderScreenshotResult } from '../lib/render-screenshot.js';
|
|
2
4
|
export function getResultTool(server, client) {
|
|
3
|
-
server.tool('get_result', 'Get the result of a previous
|
|
4
|
-
id: z.string().describe('
|
|
5
|
+
server.tool('get_result', 'Get the result of a previous capture by ID: a screenshot (ss_ prefix) or a scrape (sc_ prefix, as returned by scrape_url when a page needs rendering).', {
|
|
6
|
+
id: z.string().describe('Result ID — ss_... (screenshot) or sc_... (scrape)'),
|
|
5
7
|
}, async (params) => {
|
|
6
8
|
try {
|
|
7
9
|
const id = params.id;
|
|
10
|
+
// Prefix dispatch: the id itself selects the resource, so one tool redeems both
|
|
11
|
+
// handle kinds (issue #2538). A render-requiring scrape answers 202 with an `sc_`
|
|
12
|
+
// id; before this, get_result rejected it outright and the handle was a dead end.
|
|
13
|
+
if (id.startsWith('sc_')) {
|
|
14
|
+
const result = await client.getScrape(id);
|
|
15
|
+
const { text, isError } = renderScrapeResult(result);
|
|
16
|
+
return {
|
|
17
|
+
...(isError ? { isError: true } : {}),
|
|
18
|
+
content: [{ type: 'text', text }],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
8
21
|
if (!id.startsWith('ss_')) {
|
|
9
22
|
return {
|
|
10
23
|
isError: true,
|
|
11
24
|
content: [
|
|
12
25
|
{
|
|
13
26
|
type: 'text',
|
|
14
|
-
text: `Invalid ID prefix. Expected ss_ (screenshot), got: ${id.substring(0, 3)}`,
|
|
27
|
+
text: `Invalid ID prefix. Expected ss_ (screenshot) or sc_ (scrape), got: ${id.substring(0, 3)}`,
|
|
15
28
|
},
|
|
16
29
|
],
|
|
17
30
|
};
|
|
18
31
|
}
|
|
19
32
|
const result = await client.getScreenshot(id);
|
|
20
|
-
const
|
|
21
|
-
`ID: ${result.id}`,
|
|
22
|
-
`URL: ${result.url}`,
|
|
23
|
-
`Status: ${result.status}`,
|
|
24
|
-
result.image_url ? `Image: ${result.image_url}` : null,
|
|
25
|
-
result.width && result.height ? `Size: ${result.width}x${result.height}` : null,
|
|
26
|
-
result.format ? `Format: ${result.format}` : null,
|
|
27
|
-
result.credits_charged !== undefined ? `Credits: ${result.credits_charged}` : null,
|
|
28
|
-
]
|
|
29
|
-
.filter(Boolean)
|
|
30
|
-
.join('\n');
|
|
33
|
+
const { text, isError } = renderScreenshotResult(result);
|
|
31
34
|
return {
|
|
32
|
-
|
|
35
|
+
...(isError ? { isError: true } : {}),
|
|
36
|
+
content: [{ type: 'text', text }],
|
|
33
37
|
};
|
|
34
38
|
}
|
|
35
39
|
catch (error) {
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
/**
|
|
3
|
+
* The advertised description of the `section` filter, derived from
|
|
4
|
+
* `DOC_SECTIONS` so it can never drift from what `slugToSection` actually
|
|
5
|
+
* stamps onto bundle entries (issue #2570).
|
|
6
|
+
*/
|
|
7
|
+
export declare const SECTION_FILTER_DESCRIPTION: string;
|
|
2
8
|
export declare function listDocsTool(server: McpServer): void;
|
package/dist/tools/list-docs.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { loadBundle } from '../docs-bundle/load-bundle.js';
|
|
3
|
+
import { DOC_SECTIONS } from '../docs-bundle/helpers.js';
|
|
4
|
+
/**
|
|
5
|
+
* The advertised description of the `section` filter, derived from
|
|
6
|
+
* `DOC_SECTIONS` so it can never drift from what `slugToSection` actually
|
|
7
|
+
* stamps onto bundle entries (issue #2570).
|
|
8
|
+
*/
|
|
9
|
+
export const SECTION_FILTER_DESCRIPTION = `Optional section filter. One of: ${DOC_SECTIONS.map((section) => `"${section}"`).join(', ')}`;
|
|
3
10
|
export function listDocsTool(server) {
|
|
4
11
|
server.tool('list_docs', 'List all pages in the ByteKit documentation bundle. Returns a section tree of { title, section, path } for every bundled page. Use the optional section filter to narrow results.', {
|
|
5
|
-
section: z
|
|
6
|
-
.string()
|
|
7
|
-
.optional()
|
|
8
|
-
.describe('Optional section filter (e.g. "Guides", "API Reference", "SDK Reference")'),
|
|
12
|
+
section: z.string().optional().describe(SECTION_FILTER_DESCRIPTION),
|
|
9
13
|
}, async (params) => {
|
|
10
14
|
try {
|
|
11
15
|
const bundle = await loadBundle();
|
package/dist/tools/scrape-url.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
3
|
-
function renderLinks(links) {
|
|
4
|
-
return links
|
|
5
|
-
.map((link) => typeof link === 'string' ? link : `${link.url}${link.text ? ` — ${link.text}` : ''}`)
|
|
6
|
-
.join('\n');
|
|
7
|
-
}
|
|
8
|
-
function renderImages(images) {
|
|
9
|
-
return images
|
|
10
|
-
.map((image) => typeof image === 'string' ? image : `${image.url}${image.alt ? ` — ${image.alt}` : ''}`)
|
|
11
|
-
.join('\n');
|
|
12
|
-
}
|
|
2
|
+
import { renderScrapeResult } from '../lib/render-scrape.js';
|
|
13
3
|
export function scrapeUrlTool(server, client) {
|
|
14
|
-
server.tool('scrape_url', 'Scrape a webpage and return its content. Returns markdown by default. Use the formats parameter to request additional representations (rawHtml, html, links, images).', {
|
|
4
|
+
server.tool('scrape_url', 'Scrape a webpage and return its content. Returns markdown by default. Use the formats parameter to request additional representations (rawHtml, html, links, images). A render-requiring page may come back as Status: queued with an sc_ ID — redeem it with get_result.', {
|
|
15
5
|
url: z.string().url().describe('The URL to scrape'),
|
|
16
6
|
formats: z
|
|
17
7
|
.array(z.enum(['rawHtml', 'html', 'markdown', 'links', 'images']))
|
|
@@ -26,64 +16,10 @@ export function scrapeUrlTool(server, client) {
|
|
|
26
16
|
formats,
|
|
27
17
|
...(params.country !== undefined && { country: params.country }),
|
|
28
18
|
});
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
content: [
|
|
32
|
-
{
|
|
33
|
-
type: 'text',
|
|
34
|
-
text: [
|
|
35
|
-
`ID: ${result.id}`,
|
|
36
|
-
'Status: queued',
|
|
37
|
-
`URL: ${result.url}`,
|
|
38
|
-
`Status URL: ${result.status_url}`,
|
|
39
|
-
].join('\n'),
|
|
40
|
-
},
|
|
41
|
-
],
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
if (result.status === 'failed') {
|
|
45
|
-
return {
|
|
46
|
-
isError: true,
|
|
47
|
-
content: [
|
|
48
|
-
{
|
|
49
|
-
type: 'text',
|
|
50
|
-
text: [
|
|
51
|
-
`ID: ${result.id}`,
|
|
52
|
-
'Status: failed',
|
|
53
|
-
`Error: ${result.error.code}`,
|
|
54
|
-
result.error.message,
|
|
55
|
-
].join('\n'),
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
// Primary content for display: prefer markdown → html → rawHtml
|
|
61
|
-
const content = result.formats.markdown ?? result.formats.html ?? result.formats.raw_html ?? '';
|
|
62
|
-
const { text, truncated } = truncateContent(content);
|
|
63
|
-
const metaLines = [
|
|
64
|
-
`ID: ${result.id}`,
|
|
65
|
-
`URL: ${result.url}`,
|
|
66
|
-
result.final_url !== result.url ? `Final URL: ${result.final_url}` : null,
|
|
67
|
-
result.status_code !== null ? `Status Code: ${result.status_code}` : null,
|
|
68
|
-
result.content_type ? `Content-Type: ${result.content_type}` : null,
|
|
69
|
-
result.metadata.title ? `Title: ${result.metadata.title}` : null,
|
|
70
|
-
truncated ? 'Note: Content was truncated to 100KB' : null,
|
|
71
|
-
]
|
|
72
|
-
.filter(Boolean)
|
|
73
|
-
.join('\n');
|
|
74
|
-
let body = `${metaLines}\n\n---\n\n${text}`;
|
|
75
|
-
// Append links block when present
|
|
76
|
-
if (Array.isArray(result.formats.links) && result.formats.links.length > 0) {
|
|
77
|
-
const linkList = renderLinks(result.formats.links);
|
|
78
|
-
body += `\n\nLinks (${result.formats.links.length}):\n${linkList}`;
|
|
79
|
-
}
|
|
80
|
-
// Append images block when present
|
|
81
|
-
if (Array.isArray(result.formats.images) && result.formats.images.length > 0) {
|
|
82
|
-
const imgList = renderImages(result.formats.images);
|
|
83
|
-
body += `\n\nImages (${result.formats.images.length}):\n${imgList}`;
|
|
84
|
-
}
|
|
19
|
+
const { text, isError } = renderScrapeResult(result);
|
|
85
20
|
return {
|
|
86
|
-
|
|
21
|
+
...(isError ? { isError: true } : {}),
|
|
22
|
+
content: [{ type: 'text', text }],
|
|
87
23
|
};
|
|
88
24
|
}
|
|
89
25
|
catch (error) {
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { renderScreenshotResult } from '../lib/render-screenshot.js';
|
|
2
3
|
export function screenshotUrlTool(server, client) {
|
|
3
4
|
server.tool('screenshot_url', 'Take a screenshot of a webpage. Returns the image URL and metadata.', {
|
|
4
5
|
url: z.string().url().describe('The URL to screenshot'),
|
|
5
6
|
full_page: z.boolean().optional().describe('Capture the full scrollable page'),
|
|
6
|
-
device: z
|
|
7
|
-
.enum(['desktop', 'mobile', 'tablet'])
|
|
8
|
-
.optional()
|
|
9
|
-
.describe('Device type for rendering'),
|
|
7
|
+
device: z.enum(['desktop', 'mobile']).optional().describe('Device type for rendering'),
|
|
10
8
|
format: z.enum(['png', 'jpeg']).optional().describe('Image format'),
|
|
11
9
|
}, async (params) => {
|
|
12
10
|
try {
|
|
@@ -31,20 +29,10 @@ export function screenshotUrlTool(server, client) {
|
|
|
31
29
|
],
|
|
32
30
|
};
|
|
33
31
|
}
|
|
34
|
-
const
|
|
35
|
-
`ID: ${result.id}`,
|
|
36
|
-
`URL: ${result.url}`,
|
|
37
|
-
`Status: ${result.status}`,
|
|
38
|
-
result.image_url ? `Image: ${result.image_url}` : null,
|
|
39
|
-
result.width && result.height ? `Size: ${result.width}x${result.height}` : null,
|
|
40
|
-
result.format ? `Format: ${result.format}` : null,
|
|
41
|
-
result.file_size ? `File size: ${result.file_size} bytes` : null,
|
|
42
|
-
result.credits_charged !== undefined ? `Credits: ${result.credits_charged}` : null,
|
|
43
|
-
]
|
|
44
|
-
.filter(Boolean)
|
|
45
|
-
.join('\n');
|
|
32
|
+
const { text, isError } = renderScreenshotResult(result);
|
|
46
33
|
return {
|
|
47
|
-
|
|
34
|
+
...(isError ? { isError: true } : {}),
|
|
35
|
+
content: [{ type: 'text', text }],
|
|
48
36
|
};
|
|
49
37
|
}
|
|
50
38
|
catch (error) {
|
package/dist/tools/web-search.js
CHANGED
|
@@ -60,8 +60,12 @@ export function webSearchTool(server, client) {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
|
-
// Surface the API error code (e.g. search_provider_error
|
|
64
|
-
//
|
|
63
|
+
// Surface the API error code (e.g. search_provider_error, which /v1/search
|
|
64
|
+
// sends on a 502 as the flat body {"error":"search_provider_error"} — see
|
|
65
|
+
// docs/api/openapi.yaml §/v1/search 502 — and which client.ts's flat-shape
|
|
66
|
+
// branch parses into errorCode, issue #2541) without exposing any
|
|
67
|
+
// underlying provider name: the gateway's 502 body is a fixed constant, so
|
|
68
|
+
// the client error message is already vendor-free.
|
|
65
69
|
let message = error instanceof Error ? error.message : 'Unknown error';
|
|
66
70
|
if (error instanceof BytekitApiError && error.errorCode) {
|
|
67
71
|
message = `${message} (${error.errorCode})`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hunt-labs/bytekit-mcp",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "ByteKit MCP server — exposes ByteKit web-data tools (scrape, screenshot, search, docs) to AI agents over the Model Context Protocol, hosted or as a local stdio server.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|