@hunt-labs/bytekit-mcp 0.1.2 → 0.2.0

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.
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * Loads the generated docs-bundle.json from disk.
3
3
  *
4
- * The bundle is produced by `pnpm --filter @hunt-labs/bytekit-mcp prebuild`
5
- * (which runs `scripts/build-docs-bundle.ts`). It is gitignored because it
6
- * is a build artifact. If it doesn't exist, this function throws with a
7
- * clear message telling the operator how to build it.
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 `pnpm --filter @hunt-labs/bytekit-mcp prebuild`
5
- * (which runs `scripts/build-docs-bundle.ts`). It is gitignored because it
6
- * is a build artifact. If it doesn't exist, this function throws with a
7
- * clear message telling the operator how to build it.
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
- throw new Error('docs bundle not built yet — run: pnpm --filter @hunt-labs/bytekit-mcp prebuild', { cause: err });
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,9 @@
1
+ /**
2
+ * Behavior tests for loadBundle's error surface (#2469).
3
+ *
4
+ * The thrown Error.message becomes the MCP tool result text (list-docs/search-docs/get-doc catch
5
+ * the error and surface `error.message`), so on a missing bundle the customer-facing message must
6
+ * be neutral and must NOT leak the internal pnpm build command. The dev hint moves to a
7
+ * server-side console.warn.
8
+ */
9
+ export {};
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Behavior tests for loadBundle's error surface (#2469).
3
+ *
4
+ * The thrown Error.message becomes the MCP tool result text (list-docs/search-docs/get-doc catch
5
+ * the error and surface `error.message`), so on a missing bundle the customer-facing message must
6
+ * be neutral and must NOT leak the internal pnpm build command. The dev hint moves to a
7
+ * server-side console.warn.
8
+ */
9
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
10
+ const readFileMock = vi.fn();
11
+ vi.mock('node:fs/promises', () => ({
12
+ readFile: (...args) => readFileMock(...args),
13
+ }));
14
+ function enoent() {
15
+ const err = new Error('ENOENT');
16
+ err.code = 'ENOENT';
17
+ return err;
18
+ }
19
+ describe('loadBundle error surface', () => {
20
+ beforeEach(() => {
21
+ readFileMock.mockReset();
22
+ vi.spyOn(console, 'warn').mockImplementation(() => { });
23
+ });
24
+ afterEach(() => {
25
+ vi.restoreAllMocks();
26
+ });
27
+ // Covers #2469 DoD bullet 6 / E5 / E6: the customer-facing message on a missing bundle is
28
+ // neutral and contains no internal command (no pnpm / --filter / prebuild / file path).
29
+ it('throws a neutral message with no internal command when the bundle is missing', async () => {
30
+ readFileMock.mockRejectedValueOnce(enoent());
31
+ readFileMock.mockRejectedValueOnce(enoent());
32
+ const { loadBundle } = await import('./load-bundle.js');
33
+ await expect(loadBundle()).rejects.toThrow(/temporarily unavailable/i);
34
+ await expect(loadBundle()).rejects.not.toThrow(/pnpm|--filter|prebuild/);
35
+ });
36
+ // Covers #2469 E5: the operator-facing build hint is logged server-side (console.warn), never
37
+ // surfaced in the thrown message.
38
+ it('logs the internal build hint via console.warn', async () => {
39
+ readFileMock.mockRejectedValueOnce(enoent());
40
+ const { loadBundle } = await import('./load-bundle.js');
41
+ await expect(loadBundle()).rejects.toThrow();
42
+ expect(console.warn).toHaveBeenCalledWith(expect.stringMatching(/docs bundle/i));
43
+ });
44
+ // Non-ENOENT read errors propagate unchanged (not swallowed by the neutral-message path).
45
+ it('re-throws non-ENOENT read errors unchanged', async () => {
46
+ readFileMock.mockRejectedValueOnce(new Error('EACCES: permission denied'));
47
+ const { loadBundle } = await import('./load-bundle.js');
48
+ await expect(loadBundle()).rejects.toThrow(/EACCES/);
49
+ });
50
+ });
@@ -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})`,
@@ -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/create-scrape")'),
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 {
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { renderScreenshotResult } from '../lib/render-screenshot.js';
2
3
  export function getResultTool(server, client) {
3
4
  server.tool('get_result', 'Get the result of a previous screenshot by ID (ss_ prefix).', {
4
5
  id: z.string().describe('Screenshot result ID (ss_...)'),
@@ -17,19 +18,10 @@ export function getResultTool(server, client) {
17
18
  };
18
19
  }
19
20
  const result = await client.getScreenshot(id);
20
- const meta = [
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');
21
+ const { text, isError } = renderScreenshotResult(result);
31
22
  return {
32
- content: [{ type: 'text', text: meta }],
23
+ ...(isError ? { isError: true } : {}),
24
+ content: [{ type: 'text', text }],
33
25
  };
34
26
  }
35
27
  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 meta = [
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
- content: [{ type: 'text', text: meta }],
34
+ ...(isError ? { isError: true } : {}),
35
+ content: [{ type: 'text', text }],
48
36
  };
49
37
  }
50
38
  catch (error) {
@@ -1,7 +1,7 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { type BytekitClient } from '../client.js';
3
3
  /**
4
- * `web-search` MCP tool — runs a web search and returns ranked organic results.
4
+ * `web_search` MCP tool — runs a web search and returns ranked organic results.
5
5
  *
6
6
  * Distinct from `search_docs` (which searches the bundled documentation). All
7
7
  * HTTP/search logic lives in the client; this tool only validates input,
@@ -1,14 +1,14 @@
1
1
  import { z } from 'zod';
2
2
  import { BytekitApiError, } from '../client.js';
3
3
  /**
4
- * `web-search` MCP tool — runs a web search and returns ranked organic results.
4
+ * `web_search` MCP tool — runs a web search and returns ranked organic results.
5
5
  *
6
6
  * Distinct from `search_docs` (which searches the bundled documentation). All
7
7
  * HTTP/search logic lives in the client; this tool only validates input,
8
8
  * delegates to `client.search`, and shapes the response into MCP content.
9
9
  */
10
10
  export function webSearchTool(server, client) {
11
- server.tool('web-search', 'Run a web search and return ranked organic results (position, title, url, snippet, date). Distinct from search_docs, which searches the documentation.', {
11
+ server.tool('web_search', 'Run a web search and return ranked organic results (position, title, url, snippet, date). Distinct from search_docs, which searches the documentation.', {
12
12
  query: z.string().min(1, 'query must be non-empty').describe('The search query'),
13
13
  // Kept as a free-form string (not z.enum) on purpose: the API is the
14
14
  // source of truth for the valid set, so the MCP tool must stay
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hunt-labs/bytekit-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
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",
@@ -18,7 +18,8 @@
18
18
  "bytekit-mcp": "./dist/cli.js"
19
19
  },
20
20
  "files": [
21
- "dist"
21
+ "dist",
22
+ "CHANGELOG.md"
22
23
  ],
23
24
  "exports": {
24
25
  ".": {
@@ -49,19 +50,13 @@
49
50
  ],
50
51
  "homepage": "https://bytekit.com/mcp/",
51
52
  "bugs": {
52
- "email": "support@bytekit.com"
53
+ "email": "support@bytekit.com",
54
+ "url": "https://bytekit.com/contact"
53
55
  },
54
56
  "dependencies": {
55
57
  "@modelcontextprotocol/sdk": "^1.12.1",
56
58
  "zod": "^3.23.6"
57
59
  },
58
- "devDependencies": {
59
- "@types/node": "^22.0.0",
60
- "tsx": "^4.11.0",
61
- "typescript": "^5.4.5",
62
- "vitest": "^1.6.0",
63
- "@bytekit/docs": "0.0.1"
64
- },
65
60
  "scripts": {
66
61
  "prebuild": "pnpm check:scrape-contract && tsx scripts/build-docs-bundle.ts",
67
62
  "build": "rm -rf dist tsconfig.tsbuildinfo && tsc && mkdir -p dist/docs-bundle && cp src/docs-bundle/docs-bundle.json dist/docs-bundle/docs-bundle.json",