@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
|
@@ -28,6 +28,20 @@ function scoreEntry(title, body, tokens) {
|
|
|
28
28
|
}
|
|
29
29
|
return score;
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Strips a leading `# <title>` H1 line from `body`, when present, so callers that
|
|
33
|
+
* already display `title` separately don't duplicate it (issue #2591 item 6). Every
|
|
34
|
+
* bundled doc page's body starts with its own H1 (`scripts/build-docs-bundle.ts`
|
|
35
|
+
* `extractTitle`/bundling), so `${title} ${body}` otherwise reads as
|
|
36
|
+
* "Title # Title\n\n...".
|
|
37
|
+
*/
|
|
38
|
+
function stripLeadingTitleHeading(body, title) {
|
|
39
|
+
const newlineIdx = body.indexOf('\n');
|
|
40
|
+
const firstLine = newlineIdx === -1 ? body : body.slice(0, newlineIdx);
|
|
41
|
+
if (firstLine.trim() !== `# ${title}`)
|
|
42
|
+
return body;
|
|
43
|
+
return newlineIdx === -1 ? '' : body.slice(newlineIdx + 1).replace(/^\n+/, '');
|
|
44
|
+
}
|
|
31
45
|
/**
|
|
32
46
|
* Extracts a ~200-char snippet around the first occurrence of any query token
|
|
33
47
|
* in the given text. Returns the full text if no match is found (shouldn't
|
|
@@ -72,7 +86,7 @@ export function searchDocsTool(server) {
|
|
|
72
86
|
path,
|
|
73
87
|
title: meta.title,
|
|
74
88
|
section: meta.section,
|
|
75
|
-
snippet: extractSnippet(`${meta.title} ${meta.body}`, tokens),
|
|
89
|
+
snippet: extractSnippet(`${meta.title} ${stripLeadingTitleHeading(meta.body, meta.title)}`, tokens),
|
|
76
90
|
score,
|
|
77
91
|
});
|
|
78
92
|
}
|
package/dist/tools/web-search.js
CHANGED
|
@@ -55,13 +55,29 @@ export function webSearchTool(server, client) {
|
|
|
55
55
|
date_range: params.date_range,
|
|
56
56
|
}),
|
|
57
57
|
});
|
|
58
|
+
// The results JSON block stays first and untouched (existing consumers key off
|
|
59
|
+
// it) — credits_used/related_searches (both spec-required, openapi.yaml
|
|
60
|
+
// SearchResponse) append after it rather than reordering anything (issue #2591
|
|
61
|
+
// item 1). related_searches is omitted entirely when empty rather than printing
|
|
62
|
+
// a dangling empty line.
|
|
63
|
+
const lines = [
|
|
64
|
+
JSON.stringify(result.results, null, 2),
|
|
65
|
+
`Credits used: ${result.credits_used}`,
|
|
66
|
+
];
|
|
67
|
+
if (result.related_searches.length > 0) {
|
|
68
|
+
lines.push(`Related searches: ${result.related_searches.join(', ')}`);
|
|
69
|
+
}
|
|
58
70
|
return {
|
|
59
|
-
content: [{ type: 'text', text:
|
|
71
|
+
content: [{ type: 'text', text: lines.join('\n') }],
|
|
60
72
|
};
|
|
61
73
|
}
|
|
62
74
|
catch (error) {
|
|
63
|
-
// Surface the API error code (e.g. search_provider_error
|
|
64
|
-
//
|
|
75
|
+
// Surface the API error code (e.g. search_provider_error, which /v1/search
|
|
76
|
+
// sends on a 502 as the flat body {"error":"search_provider_error"} — see
|
|
77
|
+
// docs/api/openapi.yaml §/v1/search 502 — and which client.ts's flat-shape
|
|
78
|
+
// branch parses into errorCode, issue #2541) without exposing any
|
|
79
|
+
// underlying provider name: the gateway's 502 body is a fixed constant, so
|
|
80
|
+
// the client error message is already vendor-free.
|
|
65
81
|
let message = error instanceof Error ? error.message : 'Unknown error';
|
|
66
82
|
if (error instanceof BytekitApiError && error.errorCode) {
|
|
67
83
|
message = `${message} (${error.errorCode})`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hunt-labs/bytekit-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
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",
|
|
@@ -1,9 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
});
|