hugging-bay-mcp 0.1.13 → 0.1.14
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/README.md +51 -24
- package/compact-answers.mjs +6 -3
- package/file-page.mjs +207 -0
- package/hosted-discovery-contracts.mjs +71 -1
- package/index.mjs +31 -10
- package/mcp-typed-result.mjs +4 -3
- package/package.json +3 -3
- package/profile-manifest.mjs +1 -0
- package/public-read-retry.mjs +6 -4
- package/registry-directory-metadata.mjs +6 -6
- package/serve-verdict.mjs +25 -7
- package/server.json +15 -15
- package/tool-descriptions.mjs +20 -0
- package/tool-discovery.mjs +120 -25
- package/tool-input-validation.mjs +2 -2
package/README.md
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
# hugging-bay-mcp
|
|
2
|
-
|
|
3
|
-
## First live MCP call
|
|
4
|
-
|
|
5
|
-
Copy this one public catalog call into a terminal. It needs no API key:
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
curl -fsS 'https://huggingbay.xyz/api/mcp' -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_artifacts","arguments":{"q":"Qwen2.5 0.5B GGUF","limit":5}}}'
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
The response should contain a JSON-RPC `result` with a catalog row. This checks search access, not whether a model runs on your computer.
|
|
12
|
-
|
|
13
|
-
[](https://www.npmjs.com/package/hugging-bay-mcp) [](https://huggingbay.xyz/api/mcp)
|
|
1
|
+
# hugging-bay-mcp [](https://www.npmjs.com/package/hugging-bay-mcp) [](https://huggingbay.xyz/api/mcp)
|
|
14
2
|
|
|
15
3
|
**Promise:** Find open model files with recorded SHA-256 and licence labels. Public reads need no account.<br>
|
|
16
|
-
**Install:** `npx -y hugging-bay-mcp@0.1.
|
|
4
|
+
**Install:** `npx -y hugging-bay-mcp@0.1.14`<br>
|
|
17
5
|
**MCP config (remote):** `claude mcp add --transport http hugging-bay https://huggingbay.xyz/api/mcp`<br>
|
|
18
|
-
**MCP config (stdio):** `{"mcpServers":{"hugging-bay":{"command":"npx","args":["-y","hugging-bay-mcp@0.1.
|
|
6
|
+
**MCP config (stdio):** `{"mcpServers":{"hugging-bay":{"command":"npx","args":["-y","hugging-bay-mcp@0.1.14"],"env":{"HUGGING_BAY_API":"https://huggingbay.xyz"}}}}`<br>
|
|
19
7
|
**First call:** `search_artifacts({ "q": "Qwen3 0.6B GGUF" })`<br>
|
|
20
8
|
**Ask:** Missing a model, file, tool or feature? Ask with request_feature (hosted MCP) or POST https://huggingbay.xyz/api/v1/requests. No account. You get an id and can check its status. What shipped: https://huggingbay.xyz/changelog<br>
|
|
21
9
|
[Changelog](https://huggingbay.xyz/changelog?ref=npm) · [MCP docs](https://huggingbay.xyz/agents?ref=npm)<br>
|
|
@@ -23,6 +11,8 @@ The response should contain a JSON-RPC `result` with a catalog row. This checks
|
|
|
23
11
|
|
|
24
12
|
## Claude Code, Codex CLI and Cursor
|
|
25
13
|
|
|
14
|
+
The 0.1.14 install commands below apply after this version is published.
|
|
15
|
+
|
|
26
16
|
Public reads use no bearer token and need no OAuth login. Configure one transport
|
|
27
17
|
per server name. For Claude Code:
|
|
28
18
|
|
|
@@ -30,7 +20,7 @@ per server name. For Claude Code:
|
|
|
30
20
|
claude mcp add --transport http hugging-bay https://huggingbay.xyz/api/mcp
|
|
31
21
|
claude mcp list
|
|
32
22
|
# Or use stdio under a separate name:
|
|
33
|
-
claude mcp add hugging-bay-stdio -- npx -y hugging-bay-mcp@0.1.
|
|
23
|
+
claude mcp add hugging-bay-stdio -- npx -y hugging-bay-mcp@0.1.14
|
|
34
24
|
```
|
|
35
25
|
|
|
36
26
|
For Codex CLI:
|
|
@@ -48,7 +38,7 @@ url = "https://huggingbay.xyz/api/mcp"
|
|
|
48
38
|
```
|
|
49
39
|
|
|
50
40
|
For stdio, replace `url` with `command = "npx"` and
|
|
51
|
-
`args = ["-y", "hugging-bay-mcp@0.1.
|
|
41
|
+
`args = ["-y", "hugging-bay-mcp@0.1.14"]`. Codex's MCP list reports configuration;
|
|
52
42
|
it does not prove a tool call succeeded. `auth_status: "unsupported"` describes
|
|
53
43
|
OAuth support, not a requirement to sign in for public reads.
|
|
54
44
|
|
|
@@ -62,21 +52,43 @@ Use `tools/list` before calling a tool. The default discovery profile includes
|
|
|
62
52
|
`deployment_plan({"artifact":"<returned id>"})` for current file links and
|
|
63
53
|
hashes. `plan_local_deployment` belongs to the full profile. A successful search
|
|
64
54
|
or connection does not establish model availability, fit or a successful run.
|
|
55
|
+
If `get_model` reports `get_model_not_cacheable`, read the same returned id at
|
|
56
|
+
`GET /api/v1/artifacts/<id>/download-plan` to check current exact-file availability.
|
|
57
|
+
That read can also be unavailable; follow its backoff and keep the result unknown.
|
|
58
|
+
Use only file links actually returned by a current plan, and check its path and
|
|
59
|
+
SHA-256 against the file you intended to use. No search result authorizes a download.
|
|
60
|
+
|
|
61
|
+
For Claude Desktop, open Settings → Developer → Edit Config and merge this into
|
|
62
|
+
`claude_desktop_config.json`. Restart Claude Desktop after saving:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{"mcpServers":{"hugging-bay":{"command":"npx","args":["-y","hugging-bay-mcp@0.1.14"],"env":{"HUGGING_BAY_API":"https://huggingbay.xyz"}}}}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## First live MCP call
|
|
69
|
+
|
|
70
|
+
Copy this one public catalog call into a terminal. It needs no API key:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
curl -fsS 'https://huggingbay.xyz/api/mcp' -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_artifacts","arguments":{"q":"Qwen2.5 0.5B GGUF","limit":5}}}'
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
The response should contain a JSON-RPC `result` with a catalog row. This checks search access, not whether a model runs on your computer.
|
|
65
77
|
|
|
66
78
|
## Profiles: stdio and hosted
|
|
67
79
|
|
|
68
|
-
**MCP 0.1.
|
|
80
|
+
**MCP 0.1.12:** typed MCP tool results, closed argument validation, and a shared 15-second wait budget across pacing and retries. The npm archive and its integrity were observed on 2026-10-25; its default stdio discovery profile retains the 28-tool contract.
|
|
69
81
|
|
|
70
|
-
The stdio launcher and hosted endpoint share the discovery profile. The package keeps
|
|
82
|
+
The 0.1.14 stdio launcher and hosted endpoint share the 29-tool discovery profile. The package keeps
|
|
71
83
|
the broader catalog available, but a client must opt into it explicitly:
|
|
72
84
|
|
|
73
85
|
| Transport/profile | `tools/list` | What it is |
|
|
74
86
|
| --- | --- | --- |
|
|
75
87
|
| stdio `--profile core` / hosted `?profile=core` | **8 tools** | search, finder, model, plan, resolve, files, missing request and request status; opt in for a smaller context |
|
|
76
|
-
| stdio default (`node packages/mcp/index.mjs`) | **
|
|
77
|
-
| stdio `--profile full` | **107 tools** in 0.1.
|
|
78
|
-
| stdio `--profile verify` | **
|
|
79
|
-
| hosted `https://huggingbay.xyz/api/mcp` | **
|
|
88
|
+
| stdio 0.1.14 default (`node packages/mcp/index.mjs`) | **29 tools** | same discovery profile as hosted `/api/mcp`; `tools/list` is the authority |
|
|
89
|
+
| stdio `--profile full` | **107 tools** in 0.1.12 | the complete current stdio catalog; use `tools/list` as the authority rather than hard-coding the count |
|
|
90
|
+
| stdio 0.1.14 `--profile verify` | **29 tools**; **30** with the run-proof flag | discovery plus `get_accepted_run_proof` when `HUGGING_BAY_MCP_ENABLE_UNRELEASED_RUN_PROOF=1` |
|
|
91
|
+
| hosted `https://huggingbay.xyz/api/mcp` | **29 tools** | the deployed discovery profile; other hosted profiles use `?profile=` (see `https://huggingbay.xyz/.well-known/mcp.json`) |
|
|
80
92
|
|
|
81
93
|
The default is also selected when `HUGGING_BAY_MCP_PROFILE` is empty.
|
|
82
94
|
Use
|
|
@@ -96,7 +108,22 @@ with JSON-RPC `-32602` (`Unknown tool`).
|
|
|
96
108
|
|
|
97
109
|
## Stdio arguments and protocol errors
|
|
98
110
|
|
|
99
|
-
|
|
111
|
+
### File pages in the candidate source
|
|
112
|
+
|
|
113
|
+
`list_files` reads at most three records per call, including when a valid older
|
|
114
|
+
client requests a larger page. Continue with the exact `nextCursor` and the same
|
|
115
|
+
artifact and filters until the cursor is null. Both structured output and the
|
|
116
|
+
JSON text ledger retain every returned path and hash. A cursor traverses the
|
|
117
|
+
current inventory; it does not freeze that inventory or authorize a download.
|
|
118
|
+
|
|
119
|
+
An oversized page returns `isError: true` with code
|
|
120
|
+
`list_files_page_too_large` and no structured success or continuation cursor.
|
|
121
|
+
Retry the same question with `limit: 1` only when the recovery instructs it.
|
|
122
|
+
If a single record still exceeds the MCP bounds, use the equivalent HTTP read.
|
|
123
|
+
These candidate changes require release; the published archive has its own
|
|
124
|
+
versioned behavior.
|
|
125
|
+
|
|
126
|
+
The measured npm 0.1.12 archive includes the argument and CLI contract below.
|
|
100
127
|
|
|
101
128
|
`hugging-bay-mcp --help` (or `-h`) prints usage and exits successfully;
|
|
102
129
|
`--version` (or `-v`) prints the artifact version and exits successfully.
|
package/compact-answers.mjs
CHANGED
|
@@ -36,7 +36,10 @@ export function compactAgentDiscovery(payload, sourceUrl = '') {
|
|
|
36
36
|
return boundMcpAnswer(doc, sourceUrl);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
export function boundMcpAnswer(payload, sourceUrl = "") {
|
|
39
|
+
export function boundMcpAnswer(payload, sourceUrl = "", { toolName } = {}) {
|
|
40
|
+
// Canonical tool identity comes from dispatch, never a payload shape or URL.
|
|
41
|
+
// Its actual upstream page and final sanitized result have separate hard caps.
|
|
42
|
+
if (toolName === 'list_files') return payload;
|
|
40
43
|
let doc = payload;
|
|
41
44
|
if (Buffer.byteLength(JSON.stringify(doc)) <= 18000) return doc;
|
|
42
45
|
if (Array.isArray(doc)) doc = { rows: doc };
|
|
@@ -60,7 +63,7 @@ export function boundMcpAnswer(payload, sourceUrl = "") {
|
|
|
60
63
|
}
|
|
61
64
|
// c81: runKit, recommendation and getRunning are the answer itself (file, sha256, command); growing
|
|
62
65
|
// Proof Lab evidence must be trimmed before them, never them (live 22 Oct: /runKit was dropped).
|
|
63
|
-
const protectedKeys = new Set(['oneAnswer', 'signature_coverage', 'serve_verdict', 'local', 'fallback', 'id', 'artifactId', 'schemaVersion', 'counts', 'stats', 'total', 'cursor', 'nextCursor', 'note', 'license', 'licenseLabel', 'downloadable', 'downloadStatus', 'downloadReady', 'hosted', 'commandsAvailable', 'runReady', 'runKit', 'recommendation', 'getRunning']);
|
|
66
|
+
const protectedKeys = new Set(['oneAnswer', 'signature_coverage', 'serve_verdict', 'local', 'fallback', 'id', 'artifactId', 'schemaVersion', 'counts', 'stats', 'total', 'cursor', 'nextCursor', 'note', 'license', 'licenseLabel', 'downloadable', 'downloadStatus', 'downloadReady', 'hosted', 'commandsAvailable', 'runReady', 'runKit', 'recommendation', 'getRunning', 'stale', 'degraded', 'partial', 'freshness', 'lastGood', 'servedFrom', 'answerAgeSeconds']);
|
|
64
67
|
// Keep the selected outcome and its proof together when the card fits the response budget.
|
|
65
68
|
if (doc.receiptCard && Buffer.byteLength(JSON.stringify(doc.receiptCard)) <= 12000) protectedKeys.add('receiptCard');
|
|
66
69
|
const largest = Object.keys(doc).filter(key => !protectedKeys.has(key))
|
|
@@ -104,7 +107,7 @@ export function compactToolOutputSchema(name) {
|
|
|
104
107
|
const MCP_TEXT_BUDGET_BYTES = 6000;
|
|
105
108
|
const MCP_TEXT_PREVIEW_NOTE = "Text preview: lists and long text are shortened and some fields may be left out. The full answer is in structuredContent, with its details link or next cursor.";
|
|
106
109
|
// Safety and identity fields stay in a preview whenever they fit.
|
|
107
|
-
const MCP_TEXT_KEEP_FIRST = ['signature_coverage', 'serve_verdict', 'local', 'fallback', "note", "schemaVersion", "id", "artifactId", "error", "status", "downloadable", "downloadStatus", "license", "licenseLabel", "degraded", "stale", "next", "details"];
|
|
110
|
+
const MCP_TEXT_KEEP_FIRST = ['signature_coverage', 'serve_verdict', 'local', 'fallback', "note", "schemaVersion", "id", "artifactId", "error", "status", "downloadable", "downloadStatus", "license", "licenseLabel", "degraded", "stale", 'partial', 'freshness', 'lastGood', 'servedFrom', 'answerAgeSeconds', "next", "details"];
|
|
108
111
|
// Never shorten a value an agent could use as real: links and digests stay whole.
|
|
109
112
|
const MCP_TEXT_EXACT_VALUE = /^(?:https?:\/\/|\/api\/)|^(?:sha256:)?(?:[a-f0-9]{40}|[a-f0-9]{64})$/i;
|
|
110
113
|
// Identifiers, cursors, tokens, hashes and links are follow-up inputs; keep them whole.
|
package/file-page.mjs
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
// One actual keyset page. Neither a preview nor a complete-inventory promise.
|
|
2
|
+
import { retryAfterMs } from './public-read-retry.mjs';
|
|
3
|
+
export const MCP_FILE_PAGE_MAX_ROWS = 3;
|
|
4
|
+
export const MCP_FILE_PAGE_BODY_MAX_BYTES = 262144;
|
|
5
|
+
export const MCP_FILE_PAGE_STRUCTURED_MAX_BYTES = 65536;
|
|
6
|
+
export const MCP_FILE_PAGE_TEXT_MAX_BYTES = 6000;
|
|
7
|
+
const refusalBrand = Symbol('mcp-file-page-refusal');
|
|
8
|
+
const errorBrand = Symbol('mcp-file-page-size-error');
|
|
9
|
+
const rpcBrand = Symbol('mcp-file-page-rpc');
|
|
10
|
+
const bytes = value => Buffer.byteLength(JSON.stringify(value));
|
|
11
|
+
|
|
12
|
+
export function filePageLimit(value) {
|
|
13
|
+
if (value === undefined) return MCP_FILE_PAGE_MAX_ROWS;
|
|
14
|
+
if (!Number.isInteger(value) || value < 1 || value > 500) {
|
|
15
|
+
throw Object.assign(new Error('list_files limit must be an integer from 1 to 500.'), {
|
|
16
|
+
status: 400, code: -32602, rpcCode: -32602,
|
|
17
|
+
payload: { code: 'invalid_tool_arguments', message: 'list_files limit must be an integer from 1 to 500.' },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return Math.min(value, MCP_FILE_PAGE_MAX_ROWS);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function capFilePageUrl(url, limit) {
|
|
24
|
+
url.searchParams.set('limit', String(filePageLimit(limit)));
|
|
25
|
+
return url;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function publicSource(source) {
|
|
29
|
+
try {
|
|
30
|
+
const url = new URL(source);
|
|
31
|
+
if (!['http:', 'https:'].includes(url.protocol)) return '';
|
|
32
|
+
url.username = ''; url.password = ''; url.hash = '';
|
|
33
|
+
for (const key of [...url.searchParams.keys()]) {
|
|
34
|
+
if (!['q', 'tool', 'limit', 'cursor'].includes(key)) url.searchParams.delete(key);
|
|
35
|
+
}
|
|
36
|
+
return url.href;
|
|
37
|
+
} catch { return ''; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function filePageSizeError(ceiling, maxBytes, receivedBytes, { args = {}, source = '' } = {}) {
|
|
41
|
+
const payload = { code: 'list_files_page_too_large', ceiling, maxBytes, receivedBytes };
|
|
42
|
+
return Object.assign(new Error('list_files_page_too_large'), {
|
|
43
|
+
[errorBrand]: true,
|
|
44
|
+
status: 413, code: -32007,
|
|
45
|
+
payload, data: { ...payload, partialResponseReturned: false, retryable: false },
|
|
46
|
+
filePage: { args, source: publicSource(source) },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const isFilePageSizeError = error => error?.[errorBrand] === true;
|
|
51
|
+
export const isFilePageRefusal = result => isFilePageSizeError(result?.[refusalBrand]);
|
|
52
|
+
|
|
53
|
+
// No structuredContent: clients must not validate an error against a success schema.
|
|
54
|
+
// Never shorten a cursor into a different question, or prescribe a timed retry.
|
|
55
|
+
export function filePageRefusal(error, { echoRecovery = true } = {}) {
|
|
56
|
+
const { args = {}, source = '' } = error.filePage || {};
|
|
57
|
+
const effectiveLimit = filePageLimit(args.limit);
|
|
58
|
+
const retryArguments = Object.fromEntries(['id', 'cursor', 'q', 'tool']
|
|
59
|
+
.filter(key => typeof args[key] === 'string').map(key => [key, args[key]]));
|
|
60
|
+
retryArguments.limit = 1;
|
|
61
|
+
let href = source;
|
|
62
|
+
if (href) {
|
|
63
|
+
const url = new URL(href);
|
|
64
|
+
for (const key of ['cursor', 'q', 'tool']) {
|
|
65
|
+
if (typeof args[key] === 'string') url.searchParams.set(key, args[key]);
|
|
66
|
+
}
|
|
67
|
+
url.searchParams.set('limit', '1'); href = url.href;
|
|
68
|
+
}
|
|
69
|
+
const next = effectiveLimit > 1
|
|
70
|
+
? { tool: 'list_files', retryArguments, href,
|
|
71
|
+
instructions: 'Retry the same artifact, cursor and filters with limit 1. Do not advance the cursor.' }
|
|
72
|
+
: { method: 'GET', href,
|
|
73
|
+
instructions: 'This single-row question exceeds the MCP limit. Use the equivalent HTTP read with your original artifact, cursor and filters; do not repeat this MCP call.' };
|
|
74
|
+
const doc = { ...error.payload, retryable: false,
|
|
75
|
+
message: 'The complete file page exceeds this MCP limit. No file page or continuation cursor was returned.', next };
|
|
76
|
+
if (!echoRecovery || bytes(doc) > MCP_FILE_PAGE_TEXT_MAX_BYTES) {
|
|
77
|
+
delete next.retryArguments;
|
|
78
|
+
delete next.href;
|
|
79
|
+
next.instructions += ' Recovery values are too long to echo; reuse your original values exactly.';
|
|
80
|
+
}
|
|
81
|
+
return { [refusalBrand]: error, isError: true,
|
|
82
|
+
content: [{ type: 'text', text: JSON.stringify(doc) }] };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function readFilePageText(response, {
|
|
86
|
+
args = {}, source = '', maxBytes = MCP_FILE_PAGE_BODY_MAX_BYTES, abort = () => {},
|
|
87
|
+
} = {}) {
|
|
88
|
+
const cap = Math.min(MCP_FILE_PAGE_BODY_MAX_BYTES, maxBytes);
|
|
89
|
+
const fail = async (receivedBytes, reader = null) => {
|
|
90
|
+
try { await (reader ? reader.cancel() : response.body?.cancel()); } catch {}
|
|
91
|
+
abort();
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
// A size error never disguises an upstream429/503 or drops its header hint.
|
|
94
|
+
const delay = retryAfterMs(response.headers.get('retry-after'));
|
|
95
|
+
const retry = delay === null ? null : Math.ceil(delay / 1000);
|
|
96
|
+
const payload = { error: 'upstream_response_too_large', status: response.status,
|
|
97
|
+
...(retry !== null && Number.isFinite(retry) && retry >= 0 ? { retryAfterSeconds: retry, retry_after_s: retry } : {}) };
|
|
98
|
+
throw Object.assign(new Error(`${response.status} ${response.statusText}`), {
|
|
99
|
+
status: response.status, code: -32000, toolFailure: true, payload,
|
|
100
|
+
data: { status: response.status, url: publicSource(source), body: payload },
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
throw filePageSizeError('upstream_body', cap, receivedBytes, { args, source });
|
|
104
|
+
};
|
|
105
|
+
const declared = Number(response.headers.get('content-length') || 0);
|
|
106
|
+
if (Number.isFinite(declared) && declared > cap) await fail(declared);
|
|
107
|
+
if (!response.body) return '';
|
|
108
|
+
const reader = response.body.getReader(), chunks = [];
|
|
109
|
+
let total = 0;
|
|
110
|
+
try {
|
|
111
|
+
while (true) {
|
|
112
|
+
const { done, value } = await reader.read();
|
|
113
|
+
if (done) break;
|
|
114
|
+
total += value.byteLength;
|
|
115
|
+
if (total > cap) await fail(total, reader);
|
|
116
|
+
chunks.push(Buffer.from(value));
|
|
117
|
+
}
|
|
118
|
+
} finally { reader.releaseLock(); }
|
|
119
|
+
return Buffer.concat(chunks, total).toString('utf8');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// The retry layer must not clone/parse an unbounded429/503 before our reader.
|
|
123
|
+
// Consume once within the same cap; retain bounded JSON body hints or headers.
|
|
124
|
+
export async function readFilePageRetryResponse(response, options = {}) {
|
|
125
|
+
let text;
|
|
126
|
+
try { text = await readFilePageText(response, options); }
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (!error.toolFailure || error.status !== response.status) throw error;
|
|
129
|
+
text = JSON.stringify(error.payload);
|
|
130
|
+
}
|
|
131
|
+
const headers = new Headers(response.headers);
|
|
132
|
+
headers.delete('content-encoding'); headers.set('content-length', String(Buffer.byteLength(text)));
|
|
133
|
+
let body = null;
|
|
134
|
+
try { body = JSON.parse(text); } catch {}
|
|
135
|
+
return { response: new Response(text, { status: response.status, statusText: response.statusText, headers }), body };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Models that see only text still receive every path/hash and the real cursor.
|
|
139
|
+
// If this ledger cannot fit, refuse the whole call rather than showing a subset.
|
|
140
|
+
export function filePageText(page, { args = {}, source = '' } = {}) {
|
|
141
|
+
const rows = Array.isArray(page?.rows) ? page.rows : [];
|
|
142
|
+
const ledger = {
|
|
143
|
+
filePage: { returned: rows.length, total: page.total ?? null,
|
|
144
|
+
limit: page.limit ?? filePageLimit(args.limit),
|
|
145
|
+
degraded: page.degraded, stale: page.stale, pending: page.pending,
|
|
146
|
+
readiness: page.readiness, readState: page.readState,
|
|
147
|
+
note: 'Inventory only. A listed path or hash is not permission to download. Stale, pending or degraded data does not prove a complete inventory; check current serving authority.' },
|
|
148
|
+
rows: rows.map(row => ({ path: row.path, sha256: row.sha256 ?? null })),
|
|
149
|
+
nextCursor: page.nextCursor ?? null,
|
|
150
|
+
textPreview: 'Other metadata is in structuredContent. This text lists every returned path and hash; nextCursor continues this page, not a frozen inventory.',
|
|
151
|
+
};
|
|
152
|
+
const size = bytes(ledger);
|
|
153
|
+
if (size > MCP_FILE_PAGE_TEXT_MAX_BYTES) {
|
|
154
|
+
const error = filePageSizeError('text_ledger', MCP_FILE_PAGE_TEXT_MAX_BYTES, size, { args, source });
|
|
155
|
+
error.payload.shown = 0; error.payload.returned = rows.length;
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
return JSON.stringify(ledger);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Call after the existing public/authority/URL/typed-result projections.
|
|
162
|
+
export function finalizeFilePageResult(result, options = {}) {
|
|
163
|
+
if (isFilePageRefusal(result)) {
|
|
164
|
+
// Public-note projection can append to JSON text after the factory bound.
|
|
165
|
+
// Preserve every original value by instruction when the final text cannot
|
|
166
|
+
// echo recovery arguments and still fit; never shorten an opaque cursor.
|
|
167
|
+
return result.content.some(item => item.type === 'text' && Buffer.byteLength(item.text) > MCP_FILE_PAGE_TEXT_MAX_BYTES)
|
|
168
|
+
? { ...result, ...filePageRefusal(result[refusalBrand], { echoRecovery: false }) } : result;
|
|
169
|
+
}
|
|
170
|
+
if (result?.isError || !result?.structuredContent) return result;
|
|
171
|
+
const page = result.structuredContent;
|
|
172
|
+
const size = bytes(page), maxBytes = Math.min(MCP_FILE_PAGE_STRUCTURED_MAX_BYTES,
|
|
173
|
+
options.maxStructuredBytes ?? MCP_FILE_PAGE_STRUCTURED_MAX_BYTES);
|
|
174
|
+
try {
|
|
175
|
+
if (size > maxBytes) throw filePageSizeError('structured_page', maxBytes, size, options);
|
|
176
|
+
return { ...result, content: [{ type: 'text', text: filePageText(page, options) }] };
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (!isFilePageSizeError(error)) throw error;
|
|
179
|
+
return filePageRefusal(error);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// The private brand follows only canonical list_files RPCs through local spreads.
|
|
184
|
+
// It is never serialized or inferred from arbitrary upstream JSON.
|
|
185
|
+
export function brandFilePageRpc(rpc, options = {}) {
|
|
186
|
+
return rpc && typeof rpc === 'object' ? { ...rpc, [rpcBrand]: options } : rpc;
|
|
187
|
+
}
|
|
188
|
+
export const filePageRpcOptions = rpc => rpc?.[rpcBrand] ?? null;
|
|
189
|
+
|
|
190
|
+
export function fitFilePageRpc(rpc, { serialize = JSON.stringify, maxBytes, usedBytes = 0, overheadBytes = 3 } = {}) {
|
|
191
|
+
const options = filePageRpcOptions(rpc);
|
|
192
|
+
if (!options) return rpc;
|
|
193
|
+
const size = Buffer.byteLength(serialize(rpc));
|
|
194
|
+
if (size + usedBytes + overheadBytes <= maxBytes) return rpc;
|
|
195
|
+
const error = filePageSizeError('final_response', Math.max(0, maxBytes - usedBytes - overheadBytes), size, options);
|
|
196
|
+
const replacement = brandFilePageRpc({ jsonrpc: '2.0', id: rpc.id,
|
|
197
|
+
result: { ...(rpc.result?.resultType ? { resultType: rpc.result.resultType } : {}),
|
|
198
|
+
...(rpc.result?._meta ? { _meta: rpc.result._meta } : {}),
|
|
199
|
+
...filePageRefusal(error) } }, options);
|
|
200
|
+
if (Buffer.byteLength(serialize(replacement)) + usedBytes + overheadBytes > maxBytes) {
|
|
201
|
+
// Whole-request pressure: callers must preserve this nonretrying failure.
|
|
202
|
+
error.status = 413; error.code = -32007;
|
|
203
|
+
error.data = { ...error.payload, partialResponseReturned: false, retryable: false };
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
return replacement;
|
|
207
|
+
}
|
|
@@ -10,7 +10,8 @@ export const HOSTED_DISCOVERY_EXTRA_TOOL_NAMES = [
|
|
|
10
10
|
"list_teach_bases",
|
|
11
11
|
"get_teach_template",
|
|
12
12
|
"get_model",
|
|
13
|
-
"get_serve_decision"
|
|
13
|
+
"get_serve_decision",
|
|
14
|
+
"request_crawl_access"
|
|
14
15
|
];
|
|
15
16
|
export const HOSTED_DISCOVERY_EXTRA_TOOLS = [
|
|
16
17
|
{
|
|
@@ -639,5 +640,74 @@ export const HOSTED_DISCOVERY_EXTRA_TOOLS = [
|
|
|
639
640
|
},
|
|
640
641
|
"additionalProperties": false
|
|
641
642
|
}
|
|
643
|
+
},
|
|
644
|
+
{
|
|
645
|
+
"name": "request_crawl_access",
|
|
646
|
+
"title": "Request crawl or data access",
|
|
647
|
+
"description": "Ask for higher crawl limits or a bulk catalog feed. Needs contact_email and intended_use; returns a request id and status URL. We reply by email.",
|
|
648
|
+
"inputSchema": {
|
|
649
|
+
"type": "object",
|
|
650
|
+
"required": [
|
|
651
|
+
"contact_email",
|
|
652
|
+
"intended_use"
|
|
653
|
+
],
|
|
654
|
+
"properties": {
|
|
655
|
+
"contact_email": {
|
|
656
|
+
"type": "string",
|
|
657
|
+
"format": "email",
|
|
658
|
+
"maxLength": 254,
|
|
659
|
+
"description": "Where we reply. Kept private."
|
|
660
|
+
},
|
|
661
|
+
"intended_use": {
|
|
662
|
+
"type": "string",
|
|
663
|
+
"minLength": 3,
|
|
664
|
+
"maxLength": 1000,
|
|
665
|
+
"description": "What you will do with the data."
|
|
666
|
+
},
|
|
667
|
+
"name": {
|
|
668
|
+
"type": "string",
|
|
669
|
+
"maxLength": 120,
|
|
670
|
+
"description": "Name or organisation."
|
|
671
|
+
},
|
|
672
|
+
"user_agent": {
|
|
673
|
+
"type": "string",
|
|
674
|
+
"maxLength": 300,
|
|
675
|
+
"description": "Your crawler's User-Agent."
|
|
676
|
+
},
|
|
677
|
+
"volume_per_day": {
|
|
678
|
+
"type": "integer",
|
|
679
|
+
"minimum": 0,
|
|
680
|
+
"maximum": 1000000000,
|
|
681
|
+
"description": "Expected requests per day."
|
|
682
|
+
},
|
|
683
|
+
"option": {
|
|
684
|
+
"type": "string",
|
|
685
|
+
"enum": [
|
|
686
|
+
"higher_limits",
|
|
687
|
+
"bulk_feed",
|
|
688
|
+
"other"
|
|
689
|
+
],
|
|
690
|
+
"default": "other",
|
|
691
|
+
"description": "higher_limits, bulk_feed or other."
|
|
692
|
+
},
|
|
693
|
+
"use_type": {
|
|
694
|
+
"type": "string",
|
|
695
|
+
"enum": [
|
|
696
|
+
"research",
|
|
697
|
+
"open-source",
|
|
698
|
+
"partner",
|
|
699
|
+
"commercial"
|
|
700
|
+
],
|
|
701
|
+
"description": "research, open-source, partner or commercial."
|
|
702
|
+
}
|
|
703
|
+
},
|
|
704
|
+
"additionalProperties": false
|
|
705
|
+
},
|
|
706
|
+
"annotations": {
|
|
707
|
+
"readOnlyHint": false,
|
|
708
|
+
"destructiveHint": false,
|
|
709
|
+
"idempotentHint": true,
|
|
710
|
+
"openWorldHint": false
|
|
711
|
+
}
|
|
642
712
|
}
|
|
643
713
|
];
|
package/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { createPublicReadFetch, backoffDelayMs } from "./public-read-retry.mjs";
|
|
4
4
|
import { createSwarmClient } from "./swarm-client.mjs";
|
|
5
|
+
import { filePageLimit, readFilePageText, readFilePageRetryResponse, finalizeFilePageResult, isFilePageSizeError, filePageRefusal } from './file-page.mjs';
|
|
5
6
|
import { SWARM_TOOLS, callSwarmTool } from "./swarm-tools.mjs";
|
|
6
7
|
import { installProxyAwareFetch } from "./proxy-fetch.mjs";
|
|
7
8
|
import { boundMcpAnswer, compactAgentDiscovery, mcpAnswerText, mcpAnswerSource, reconcileFindRunnablePublicSummary, withCompactAnswerSchema } from "./compact-answers.mjs";
|
|
@@ -1875,7 +1876,7 @@ function paramsFrom(input, allowed) {
|
|
|
1875
1876
|
|
|
1876
1877
|
async function apiRequest(path, options = {}) {
|
|
1877
1878
|
const acceptedStatuses = new Set(Array.isArray(options.acceptStatuses) ? options.acceptStatuses.map(Number) : []);
|
|
1878
|
-
const { acceptStatuses: _acceptStatuses, timeoutMs: _timeoutMs, ...fetchOptions } = options;
|
|
1879
|
+
const { acceptStatuses: _acceptStatuses, timeoutMs: _timeoutMs, mcpFilePage, ...fetchOptions } = options;
|
|
1879
1880
|
const headers = new Headers(options.headers || {});
|
|
1880
1881
|
if (options.body) headers.set("Content-Type", "application/json");
|
|
1881
1882
|
if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
@@ -1884,8 +1885,12 @@ async function apiRequest(path, options = {}) {
|
|
|
1884
1885
|
if (fetchOptions.signal) signals.push(fetchOptions.signal);
|
|
1885
1886
|
if (Number.isFinite(timeoutMs) && timeoutMs > 0) signals.push(AbortSignal.timeout(timeoutMs));
|
|
1886
1887
|
const signal = signals.length === 0 ? undefined : signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
1887
|
-
const
|
|
1888
|
-
const
|
|
1888
|
+
const pageOptions = mcpFilePage ? { args: mcpFilePage.args, source: apiUrl(path).toString() } : null;
|
|
1889
|
+
const response = await publicReadFetch(apiUrl(path), { ...fetchOptions, headers, ...(signal ? { signal } : {}) },
|
|
1890
|
+
pageOptions ? { readRetryResponse: response => readFilePageRetryResponse(response, pageOptions) } : {});
|
|
1891
|
+
const text = mcpFilePage
|
|
1892
|
+
? await readFilePageText(response, { args: mcpFilePage.args, source: apiUrl(path).toString() })
|
|
1893
|
+
: await response.text();
|
|
1889
1894
|
let body;
|
|
1890
1895
|
try {
|
|
1891
1896
|
body = text ? JSON.parse(text) : null;
|
|
@@ -1995,6 +2000,9 @@ async function callTool(name, input, signal) {
|
|
|
1995
2000
|
}
|
|
1996
2001
|
return apiRequest("/api/v1/request-missing", { method: "POST", body: JSON.stringify(checked.value) });
|
|
1997
2002
|
}
|
|
2003
|
+
if (name === "request_crawl_access") {
|
|
2004
|
+
return apiRequest("/api/v1/crawl-access/requests", { method: "POST", body: JSON.stringify(input) });
|
|
2005
|
+
}
|
|
1998
2006
|
if (name === "deployment_plan") {
|
|
1999
2007
|
const params = paramsFrom(input, ["artifact"]);
|
|
2000
2008
|
return apiRequest(`/api/agents/deployment-plan?${params}`);
|
|
@@ -2243,8 +2251,8 @@ async function callTool(name, input, signal) {
|
|
|
2243
2251
|
if (name === "preview_file") return apiRequest(`/api/previews/${encodeURIComponent(input.id)}/${encodeURIComponent(input.path)}`);
|
|
2244
2252
|
if (name === "list_files") {
|
|
2245
2253
|
const params = paramsFrom(input, ["q", "tool", "limit", "cursor"]);
|
|
2246
|
-
|
|
2247
|
-
return apiRequest(`/api/v1/artifacts/${encodeURIComponent(input.id)}/files?${params}
|
|
2254
|
+
params.set('limit', String(filePageLimit(input.limit)));
|
|
2255
|
+
return apiRequest(`/api/v1/artifacts/${encodeURIComponent(input.id)}/files?${params}`, { mcpFilePage: { args: input } });
|
|
2248
2256
|
}
|
|
2249
2257
|
if (name === "list_downloadable_files") {
|
|
2250
2258
|
const params = paramsFrom(input, ["q", "pack", "artifactId", "path", "sourceKind", "tool", "limit"]);
|
|
@@ -2739,7 +2747,9 @@ async function handleMessage(message) {
|
|
|
2739
2747
|
return;
|
|
2740
2748
|
}
|
|
2741
2749
|
if (message.method === "tools/list") {
|
|
2742
|
-
|
|
2750
|
+
// HUGGING_BAY_MCP_SCHEMAS=full restores every schema constraint, title and annotation hint.
|
|
2751
|
+
const schemas = process.env.HUGGING_BAY_MCP_SCHEMAS === "full" ? "full" : "slim";
|
|
2752
|
+
const tools = listedTools.map(tool => leanMcpTool(tool, { schemas }));
|
|
2743
2753
|
const page = mcpV2Enabled ? paginateMcpDiscovery("tools", { tools }, message.params, mcpProfile) : { tools };
|
|
2744
2754
|
result(id, mcpProfile === "full" ? page : projectPublicNote(page, { appendNote: true }));
|
|
2745
2755
|
return;
|
|
@@ -2774,7 +2784,7 @@ async function handleMessage(message) {
|
|
|
2774
2784
|
return;
|
|
2775
2785
|
}
|
|
2776
2786
|
const output = tagMcpDownloadUrls(called);
|
|
2777
|
-
const publicOutput = projectPublicNote(boundMcpAnswer(output, mcpAnswerSource(message.params?.name, message.params?.arguments || {}, output, apiBase)), { appendNote: true });
|
|
2787
|
+
const publicOutput = projectPublicNote(boundMcpAnswer(output, mcpAnswerSource(message.params?.name, message.params?.arguments || {}, output, apiBase), { toolName: message.params?.name }), { appendNote: true });
|
|
2778
2788
|
const legacyArrayText = Array.isArray(rawCalled) && output?.nextCursor == null
|
|
2779
2789
|
&& message.params?.arguments?.cursor === undefined && message.params?.arguments?.limit === undefined;
|
|
2780
2790
|
const textOutput = legacyArrayText
|
|
@@ -2783,14 +2793,20 @@ async function handleMessage(message) {
|
|
|
2783
2793
|
const publishedOutput = message.params?.name === "find_runnable" && textOutput && typeof textOutput === "object" && !Array.isArray(textOutput)
|
|
2784
2794
|
? reconcileFindRunnablePublicSummary(textOutput)
|
|
2785
2795
|
: textOutput;
|
|
2796
|
+
const structuredOutput = message.params?.name === "find_runnable"
|
|
2797
|
+
? reconcileFindRunnablePublicSummary(publicOutput) : publicOutput;
|
|
2786
2798
|
// Public objects carry the note in both representations, read independently.
|
|
2787
2799
|
const callResult = {
|
|
2788
2800
|
content: [{ type: "text", text: mcpAnswerText(publishedOutput) }],
|
|
2789
|
-
structuredContent: Array.isArray(
|
|
2790
|
-
:
|
|
2801
|
+
structuredContent: Array.isArray(structuredOutput) ? { rows: structuredOutput }
|
|
2802
|
+
: structuredOutput && typeof structuredOutput === "object" ? structuredOutput : { value: structuredOutput ?? null },
|
|
2791
2803
|
isError: false,
|
|
2792
2804
|
};
|
|
2793
|
-
|
|
2805
|
+
const typed = typedToolResult(callResult, message.params?.name, message.params?.arguments);
|
|
2806
|
+
result(id, message.params?.name === 'list_files' ? finalizeFilePageResult(typed, {
|
|
2807
|
+
args: message.params?.arguments || {},
|
|
2808
|
+
source: mcpAnswerSource('list_files', message.params?.arguments || {}, output, apiBase),
|
|
2809
|
+
}) : typed);
|
|
2794
2810
|
return;
|
|
2795
2811
|
}
|
|
2796
2812
|
if (message.method === "resources/templates/list") {
|
|
@@ -2843,6 +2859,10 @@ async function handleMessage(message) {
|
|
|
2843
2859
|
if (id !== undefined) errorResult(id, -32601, `Method not found: ${message.method}`);
|
|
2844
2860
|
} catch (error) {
|
|
2845
2861
|
if (id !== undefined) {
|
|
2862
|
+
if (message.method === 'tools/call' && message.params?.name === 'list_files' && isFilePageSizeError(error)) {
|
|
2863
|
+
result(id, filePageRefusal(error));
|
|
2864
|
+
return;
|
|
2865
|
+
}
|
|
2846
2866
|
if (!replySent && (entry.abortReason === "timeout" || (controller.signal.aborted && entry.abortReason === "timeout"))) {
|
|
2847
2867
|
errorResult(id, -32000, "Request timed out", {
|
|
2848
2868
|
code: "stdio_request_timeout",
|
|
@@ -2899,6 +2919,7 @@ function typedToolResult(callResult, name, args) {
|
|
|
2899
2919
|
if (!typedResultsEnabled || typeof name !== "string" || runProofToolNames.has(name)) return callResult;
|
|
2900
2920
|
return attachMcpToolResult(callResult, {
|
|
2901
2921
|
name, args: args && typeof args === "object" ? args : {}, tools: listedTools,
|
|
2922
|
+
renderText: mcpAnswerText,
|
|
2902
2923
|
validateArguments: (schema, input) => (mcpInvalidToolArgumentsResult(name, schema, input) ? "invalid_arguments" : null),
|
|
2903
2924
|
});
|
|
2904
2925
|
}
|
package/mcp-typed-result.mjs
CHANGED
|
@@ -355,12 +355,13 @@ function annotateFindRunnable(structured) {
|
|
|
355
355
|
|
|
356
356
|
/**
|
|
357
357
|
* Attach hb_result to a tools/call result (returns a new result object).
|
|
358
|
-
* Keeps
|
|
358
|
+
* Keeps JSON text in sync through the transport's bounded preview renderer.
|
|
359
359
|
*/
|
|
360
360
|
export function attachMcpToolResult(result, options = {}) {
|
|
361
361
|
if (!plainObject(result)) return result;
|
|
362
362
|
const tool = (options.tools || []).find((entry) => entry?.name === options.name);
|
|
363
363
|
const typed = buildMcpToolResult(result, options);
|
|
364
|
+
const renderText = typeof options.renderText === "function" ? options.renderText : JSON.stringify;
|
|
364
365
|
const structured = plainObject(result.structuredContent) ? result.structuredContent : null;
|
|
365
366
|
if (structured && outputSchemaIsOpen(tool)) {
|
|
366
367
|
const content = Array.isArray(result.content) ? result.content : [];
|
|
@@ -373,11 +374,11 @@ export function attachMcpToolResult(result, options = {}) {
|
|
|
373
374
|
}
|
|
374
375
|
const syncFindRunnableText = options.name === "find_runnable" && !result.isError;
|
|
375
376
|
const nextContent = mirrorIndex >= 0
|
|
376
|
-
? content.map((item, index) => index === mirrorIndex ? { ...item, text:
|
|
377
|
+
? content.map((item, index) => index === mirrorIndex ? { ...item, text: renderText(next) } : item)
|
|
377
378
|
: fallbackFindRunnable
|
|
378
379
|
? content.map((item) => item?.type === 'text' ? { ...item, text: next.summary || typed.hint } : item)
|
|
379
380
|
: syncFindRunnableText
|
|
380
|
-
? content.map((item) => item?.type === "text" ? { ...item, text:
|
|
381
|
+
? content.map((item) => item?.type === "text" ? { ...item, text: renderText(next) } : item)
|
|
381
382
|
: result.content;
|
|
382
383
|
return { ...result, ...(nextContent ? { content: nextContent } : {}), structuredContent: next };
|
|
383
384
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hugging-bay-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"description": "Open model files with recorded SHA-256 and licence labels. Ask for what's missing.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -35,8 +35,7 @@
|
|
|
35
35
|
"node": ">=18.17"
|
|
36
36
|
},
|
|
37
37
|
"publishConfig": {
|
|
38
|
-
"access": "public"
|
|
39
|
-
"provenance": true
|
|
38
|
+
"access": "public"
|
|
40
39
|
},
|
|
41
40
|
"scripts": {
|
|
42
41
|
"generate:listings": "node bin/generate-listing-metadata.mjs",
|
|
@@ -52,6 +51,7 @@
|
|
|
52
51
|
"local-teach.mjs",
|
|
53
52
|
"public-note-copy.mjs",
|
|
54
53
|
"compact-answers.mjs",
|
|
54
|
+
"file-page.mjs",
|
|
55
55
|
"serve-verdict.mjs",
|
|
56
56
|
"serve-verdict-contract.mjs",
|
|
57
57
|
"profile-manifest.mjs",
|
package/profile-manifest.mjs
CHANGED