hugging-bay-mcp 0.1.10 → 0.1.12
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 +10 -0
- package/README.md +109 -17
- package/compact-answers.mjs +43 -6
- package/hosted-discovery-contracts.mjs +2 -4
- package/index.mjs +76 -23
- package/mcp-download-via.mjs +11 -1
- package/mcp-prompts.mjs +18 -4
- package/mcp-skills.mjs +248 -0
- package/mcp-typed-result.mjs +414 -0
- package/package.json +15 -2
- package/proxy-fetch.mjs +12 -2
- package/public-note-copy.mjs +12 -2
- package/public-read-retry.mjs +100 -0
- package/registry-directory-metadata.mjs +48 -17
- package/release-authority.mjs +10 -4
- package/request-missing.mjs +16 -0
- package/serve-verdict-contract.mjs +122 -0
- package/serve-verdict.mjs +148 -0
- package/server.json +34 -12
- package/starter-tasks.mjs +78 -0
- package/swarm-client.mjs +127 -0
- package/swarm-tools.mjs +17 -0
- package/tool-descriptions.mjs +3 -3
- package/tool-input-validation.mjs +2 -2
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Changes for `hugging-bay-mcp`.
|
|
4
|
+
|
|
5
|
+
## 0.1.12 — source candidate
|
|
6
|
+
|
|
7
|
+
Not published.
|
|
8
|
+
|
|
9
|
+
- Timed-out tool failures report unavailable status.
|
|
10
|
+
- Degraded deployment plans and incomplete runnable results retain unavailable or pending status instead of appearing empty.
|
package/README.md
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
1
1
|
# hugging-bay-mcp
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/hugging-bay-mcp) [](https://huggingbay.xyz/api/mcp)
|
|
4
|
+
|
|
3
5
|
**Promise:** Find open model files with recorded SHA-256 and licence labels. Public reads need no account.<br>
|
|
4
|
-
**Install:** `npx -y hugging-bay-mcp@0.1.
|
|
6
|
+
**Install:** `npx -y hugging-bay-mcp@0.1.11`<br>
|
|
5
7
|
**MCP config (remote):** `claude mcp add --transport http hugging-bay https://huggingbay.xyz/api/mcp`<br>
|
|
6
|
-
**MCP config (stdio):** `{"mcpServers":{"hugging-bay":{"command":"npx","args":["-y","hugging-bay-mcp@0.1.
|
|
8
|
+
**MCP config (stdio):** `{"mcpServers":{"hugging-bay":{"command":"npx","args":["-y","hugging-bay-mcp@0.1.11"],"env":{"HUGGING_BAY_API":"https://huggingbay.xyz"}}}}`<br>
|
|
7
9
|
**First call:** `search_artifacts({ "q": "Qwen3 0.6B GGUF" })`<br>
|
|
8
10
|
**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>
|
|
9
11
|
[Changelog](https://huggingbay.xyz/changelog?ref=npm) · [MCP docs](https://huggingbay.xyz/agents?ref=npm)<br>
|
|
10
12
|
**Keywords:** `gguf`, `local-llm`, `huggingface-alternative`, `mcp`
|
|
11
13
|
|
|
14
|
+
## Claude Code, Codex CLI and Cursor
|
|
15
|
+
|
|
16
|
+
Public reads use no bearer token and need no OAuth login. Configure one transport
|
|
17
|
+
per server name. For Claude Code:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
claude mcp add --transport http hugging-bay https://huggingbay.xyz/api/mcp
|
|
21
|
+
claude mcp list
|
|
22
|
+
# Or use stdio under a separate name:
|
|
23
|
+
claude mcp add hugging-bay-stdio -- npx -y hugging-bay-mcp@0.1.11
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
For Codex CLI:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
codex mcp add hugging-bay --url https://huggingbay.xyz/api/mcp
|
|
30
|
+
codex mcp list
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The equivalent entry in `~/.codex/config.toml` is:
|
|
34
|
+
|
|
35
|
+
```toml
|
|
36
|
+
[mcp_servers.hugging-bay]
|
|
37
|
+
url = "https://huggingbay.xyz/api/mcp"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
For stdio, replace `url` with `command = "npx"` and
|
|
41
|
+
`args = ["-y", "hugging-bay-mcp@0.1.11"]`. Codex's MCP list reports configuration;
|
|
42
|
+
it does not prove a tool call succeeded. `auth_status: "unsupported"` describes
|
|
43
|
+
OAuth support, not a requirement to sign in for public reads.
|
|
44
|
+
|
|
45
|
+
For Cursor, merge this into `.cursor/mcp.json` (project) or `~/.cursor/mcp.json`:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{"mcpServers":{"hugging-bay":{"url":"https://huggingbay.xyz/api/mcp"}}}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Use `tools/list` before calling a tool. The default discovery profile includes
|
|
52
|
+
`deployment_plan({"artifact":"<returned id>"})` for current file links and
|
|
53
|
+
hashes. `plan_local_deployment` belongs to the full profile. A successful search
|
|
54
|
+
or connection does not establish model availability, fit or a successful run.
|
|
55
|
+
|
|
12
56
|
## Profiles: stdio and hosted
|
|
13
57
|
|
|
14
|
-
**
|
|
58
|
+
**Source candidate:** `0.1.12` reports timeouts and degraded deployment or runnable results as unavailable or pending instead of empty.<br>
|
|
59
|
+
**MCP 0.1.11:** typed MCP tool results, closed argument validation, and a shared 15-second wait budget across pacing and retries. The SHA-pinned npm archive was measured on 2026-10-24; its default stdio discovery profile retains the 28-tool contract.
|
|
15
60
|
|
|
16
61
|
The stdio launcher and hosted endpoint share the discovery profile. The package keeps
|
|
17
62
|
the broader catalog available, but a client must opt into it explicitly:
|
|
@@ -19,7 +64,7 @@ the broader catalog available, but a client must opt into it explicitly:
|
|
|
19
64
|
| Transport/profile | `tools/list` | What it is |
|
|
20
65
|
| --- | --- | --- |
|
|
21
66
|
| stdio default (`node packages/mcp/index.mjs`) | **28 tools** | same discovery profile as hosted `/api/mcp`; `tools/list` is the authority |
|
|
22
|
-
| stdio `--profile full` | **
|
|
67
|
+
| stdio `--profile full` | **107 tools** in 0.1.11 | the complete current stdio catalog; use `tools/list` as the authority rather than hard-coding the count |
|
|
23
68
|
| stdio `--profile verify` | **28 tools**; **29** with the run-proof flag | discovery plus `get_accepted_run_proof` when `HUGGING_BAY_MCP_ENABLE_UNRELEASED_RUN_PROOF=1` |
|
|
24
69
|
| hosted `https://huggingbay.xyz/api/mcp` | **28 tools** | the deployed discovery profile; other hosted profiles use `?profile=` (see `https://huggingbay.xyz/.well-known/mcp.json`) |
|
|
25
70
|
|
|
@@ -28,12 +73,43 @@ The default is also selected when `HUGGING_BAY_MCP_PROFILE` is empty. Use
|
|
|
28
73
|
catalog; a CLI profile takes precedence over the environment. Use
|
|
29
74
|
`--profile discovery` to make the bounded choice explicit. Unknown profile
|
|
30
75
|
values are refused with JSON-RPC `-32602` rather than silently changing the
|
|
31
|
-
requested surface.
|
|
32
|
-
with `
|
|
33
|
-
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
|
|
76
|
+
requested surface. Source tools outside the selected profile fail `tools/call`
|
|
77
|
+
with JSON-RPC `-32602` (`Unknown tool`).
|
|
78
|
+
|
|
79
|
+
## Stdio arguments and protocol errors
|
|
80
|
+
|
|
81
|
+
The measured npm 0.1.11 archive includes the argument and CLI contract below.
|
|
82
|
+
|
|
83
|
+
`hugging-bay-mcp --help` (or `-h`) prints usage and exits successfully;
|
|
84
|
+
`--version` (or `-v`) prints the artifact version and exits successfully.
|
|
85
|
+
Neither command waits for stdin to close or calls the API.
|
|
86
|
+
|
|
87
|
+
Send JSON-RPC 2.0 messages over stdin/stdout. Newline and Content-Length
|
|
88
|
+
framing are supported. The supported revisions are `2025-06-18`,
|
|
89
|
+
`2025-11-25`, and `2026-07-28`. The 2025 revisions negotiate through
|
|
90
|
+
`initialize`; the 2026 revision uses `server/discover` and per-request
|
|
91
|
+
`params._meta["io.modelcontextprotocol/protocolVersion"]` (plus clientInfo
|
|
92
|
+
and clientCapabilities metadata). Inspect the returned tool schemas for
|
|
93
|
+
the selected profile before calling a tool.
|
|
94
|
+
|
|
95
|
+
Unknown argument names, wrong types, missing required fields and invalid
|
|
96
|
+
ranges are rejected before API dispatch. Known tool schema failures return
|
|
97
|
+
`result.isError: true`, text explaining the correction, and
|
|
98
|
+
`result.structuredContent.code: "invalid_tool_arguments"`. The
|
|
99
|
+
`request_missing` confirmation workflow retains its specialized validation
|
|
100
|
+
and error codes. The hosted API retains its existing `invalid_arguments`
|
|
101
|
+
envelope; it enforces the same rejection rule without promising identical
|
|
102
|
+
transport envelopes.
|
|
103
|
+
|
|
104
|
+
Protocol errors use numeric JSON-RPC codes: malformed JSON is `-32700`
|
|
105
|
+
with message `Parse error` and id `null`; invalid requests are `-32600`;
|
|
106
|
+
unknown methods are `-32601`; invalid parameters or unknown tools are
|
|
107
|
+
`-32602`; execution/transport failures use `-32000` with bounded recovery
|
|
108
|
+
data where available. Tool-domain failures may instead use `result.isError`.
|
|
109
|
+
Error text does not echo untrusted argument values or configured credentials.
|
|
110
|
+
An error or stale backend response does not establish current availability.
|
|
111
|
+
|
|
112
|
+
## MCP v2 features
|
|
37
113
|
|
|
38
114
|
Model cards and run kits are resources. Use `resources/list` for public records or
|
|
39
115
|
`resources/templates/list` with an artifact id:
|
|
@@ -69,7 +145,10 @@ response. Calls without a token keep their ordinary response format.
|
|
|
69
145
|
The conformance test uses pinned official schemas for every advertised protocol
|
|
70
146
|
version, including `2026-07-28` and both supported 2025 revisions.
|
|
71
147
|
|
|
72
|
-
##
|
|
148
|
+
## Tools across profiles
|
|
149
|
+
|
|
150
|
+
This table includes full-profile tools. Check the selected transport's
|
|
151
|
+
`tools/list`; a name in this table may be absent from discovery.
|
|
73
152
|
|
|
74
153
|
| Tool | What it returns |
|
|
75
154
|
| --- | --- |
|
|
@@ -189,7 +268,7 @@ Available information from Hugging Bay:
|
|
|
189
268
|
|
|
190
269
|
MIT
|
|
191
270
|
|
|
192
|
-
## Local teaching for agents (
|
|
271
|
+
## Local teaching for agents (optional, default off)
|
|
193
272
|
|
|
194
273
|
The npm stdio package can run the installed local Teach engine. Set `HBAY_TEACH_LOCAL=1` and `HBAY_TEACH_PYTHON` to the Python executable in an environment with this source version of `hbay-teach` and its MLX or PEFT extra. The flag adds two local tools to the selected profile. The hosted MCP endpoint does not train models.
|
|
195
274
|
|
|
@@ -213,15 +292,15 @@ Downloadable doesn't mean tested: this record says whether the exact file can be
|
|
|
213
292
|
The request-and-status sentence above is approved copy held on the c29 AEO-72/AEO-73 deployment gate. Verify the deployed `request_feature`, `get_request`, and public changelog/status path before package publication or directory copy uses it.
|
|
214
293
|
|
|
215
294
|
|
|
216
|
-
### Run a model on your computer (
|
|
295
|
+
### Run a model on your computer (optional, default off)
|
|
217
296
|
|
|
218
|
-
|
|
297
|
+
Install hbay 0.2.0 or later and the local MCP package, then set `HUGGING_BAY_MCP_ENABLE_RUN_LOCAL=1` to expose `run_local` to your assistant. This feature runs on your computer; the hosted MCP does not start a model.
|
|
219
298
|
|
|
220
299
|
#### 1. Set up the local tools
|
|
221
300
|
|
|
222
301
|
Use a terminal on your own computer. You need both the native hbay program and the local MCP package before calling your assistant.
|
|
223
302
|
|
|
224
|
-
Install the
|
|
303
|
+
Install the hbay 0.2.0 or later binary, then start the local npm stdio package with `HUGGING_BAY_MCP_ENABLE_RUN_LOCAL=1`. The flag defaults off. `HBAY_BINARY` may name a trusted local executable; `HBAY_DATA_DIR` may select an isolated data directory.
|
|
225
304
|
|
|
226
305
|
#### 2. Start one model
|
|
227
306
|
|
|
@@ -229,14 +308,16 @@ Call `run_local({"model":"Qwen/Qwen2.5-0.5B-Instruct-GGUF"})`. It checks for a r
|
|
|
229
308
|
|
|
230
309
|
#### 3. Keep the session open
|
|
231
310
|
|
|
232
|
-
One MCP process owns one model server. Close the MCP session to stop it. Cancelling a pending call, startup failure, or startup timeout also stops its child. Downloads may take up to 15 minutes before readiness. The hosted MCP, behind `HUGGING_BAY_RUN_LOCAL=1` (default off), returns local package setup steps and never starts a model on the hosted machine.
|
|
311
|
+
One MCP process owns one model server. Close the MCP session to stop it. Cancelling a pending call, startup failure, or startup timeout also stops its child. Downloads may take up to 15 minutes before readiness. The hosted MCP, behind `HUGGING_BAY_RUN_LOCAL=1` (default off), returns local package setup steps and never starts a model on the hosted machine.
|
|
233
312
|
|
|
234
313
|
Prompts stay on your machine.
|
|
235
314
|
|
|
236
315
|
## Complete tool reference for agent builders
|
|
237
316
|
|
|
238
317
|
The expanded [MCP reference](https://huggingbay.xyz/docs/mcp) is staged behind
|
|
239
|
-
`HUGGING_BAY_AGENT_BUILDER_DOCS=1` (default off).
|
|
318
|
+
`HUGGING_BAY_AGENT_BUILDER_DOCS=1` (default off). With
|
|
319
|
+
`HUGGING_BAY_AGENT_GUARDRAILS=1`, the `verify-before-finish` MCP prompt is also
|
|
320
|
+
listed. It lists each hosted tool and
|
|
240
321
|
each source stdio tool separately, with profiles, purpose, inputs, outputs,
|
|
241
322
|
request templates, errors, and rate limits. Until that flag is enabled, use
|
|
242
323
|
[GET discovery](https://huggingbay.xyz/api/mcp/info) for hosted schemas and
|
|
@@ -258,3 +339,14 @@ node apps/web/bin/generate-agent-mcp-stdio-reference.mjs
|
|
|
258
339
|
The reference tests compare that inventory with all source profiles, including
|
|
259
340
|
local tools and accepted-run-proof opt-ins, and validate every argument example
|
|
260
341
|
against its tool schema.
|
|
342
|
+
|
|
343
|
+
Backing catalog reads follow the [shared backoff contract](../../docs/backoff-contract.md): at most two retries on 429/503, full Retry-After seconds or HTTP-date and JSON hints plus positive jitter, and a 15 second total wait budget. A longer delay is returned to the caller. Writes are never automatically replayed; only the known read-only get_model/get_serve_decision POST proxies opt into retries. Successful v1 Retry-After responses pace the next backing read.
|
|
344
|
+
|
|
345
|
+
### Swarm helpers (source-only, opt in)
|
|
346
|
+
|
|
347
|
+
With `HUGGING_BAY_SWARM_FEATURES=1`, the explicit verify/full profiles add
|
|
348
|
+
`get_swarm_limits`, `get_snapshot`, `resolve_artifacts`, `deployment_plans`,
|
|
349
|
+
and `find_runnable_many`. Share the returned snapshot across every batch.
|
|
350
|
+
`swarm-client.mjs` also exports `createSwarmClient` for bounded parallel reads,
|
|
351
|
+
single-flight caching and shared Retry-After backoff. The discovery profile
|
|
352
|
+
stays unchanged. See [the quickstart](../../docs/swarm-quickstart.md).
|
package/compact-answers.mjs
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
1
|
// Shared result shapes and output budgets for hosted and packaged MCP clients.
|
|
2
2
|
// No transport, authorization, licence decisions, or census calculations live here.
|
|
3
|
+
import { SERVE_VERDICT_SCHEMA } from './serve-verdict.mjs';
|
|
4
|
+
import { PUBLIC_DESCRIPTION_WITHHELD } from "./public-note-copy.mjs";
|
|
5
|
+
|
|
3
6
|
export const COMPACT_LIST_TOOLS = new Set(['search_artifacts', 'resolve_artifact', 'find_runnable', 'find_model', 'recommend_artifacts', 'recommend_safe_model', 'recommend_with_citation', 'find_ungated_alternatives', 'get_ranking', 'get_trending']);
|
|
4
7
|
|
|
8
|
+
/** Replace a withheld prose placeholder in find-runnable's top-level summary when pick facts remain. */
|
|
9
|
+
export function reconcileFindRunnablePublicSummary(doc) {
|
|
10
|
+
if (!doc || typeof doc !== "object" || Array.isArray(doc)) return doc;
|
|
11
|
+
if (doc.summary !== PUBLIC_DESCRIPTION_WITHHELD) return doc;
|
|
12
|
+
const pick = doc.recommendation;
|
|
13
|
+
if (pick && typeof pick === "object") {
|
|
14
|
+
const label = pick.repo || pick.name || pick.artifactId || pick.id;
|
|
15
|
+
if (typeof label === "string" && label) {
|
|
16
|
+
return { ...doc, summary: `Runnable pick: ${label}. Use structured fields and candidates for files and next steps.` };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const guidance = typeof doc.guidance === "string" ? doc.guidance : typeof doc.reason === "string" ? doc.reason : "";
|
|
20
|
+
if (guidance) {
|
|
21
|
+
const sentence = guidance.includes(".") ? `${guidance.split(".")[0]}.` : guidance;
|
|
22
|
+
return { ...doc, summary: sentence };
|
|
23
|
+
}
|
|
24
|
+
return doc;
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
// Use the same discovery projection in hosted and both stdio entrypoints. The
|
|
6
28
|
// full provider directory otherwise consumes the budget and drops endpoints.
|
|
7
29
|
export function compactAgentDiscovery(payload, sourceUrl = '') {
|
|
@@ -25,7 +47,7 @@ export function boundMcpAnswer(payload, sourceUrl = "") {
|
|
|
25
47
|
return value.slice(0, cap).map((item, i) => preview(item, `${path}/${i}`, cap));
|
|
26
48
|
}
|
|
27
49
|
if (value && typeof value === 'object') return Object.fromEntries(Object.entries(value).map(([key, item]) =>
|
|
28
|
-
[key, ['runKit', 'proofLab', 'testedRunPlan', 'receiptCard'].includes(key) ? item : preview(item, `${path}/${key}`, cap)]));
|
|
50
|
+
[key, ['oneAnswer', 'runKit', 'proofLab', 'testedRunPlan', 'receiptCard'].includes(key) ? item : preview(item, `${path}/${key}`, cap)]));
|
|
29
51
|
if (typeof value === 'string' && value.length > 1200) {
|
|
30
52
|
omissions.push({ path, omittedCharacters: value.length - 1200 });
|
|
31
53
|
return value.slice(0, 1200);
|
|
@@ -36,7 +58,9 @@ export function boundMcpAnswer(payload, sourceUrl = "") {
|
|
|
36
58
|
if (Buffer.byteLength(JSON.stringify(doc)) > 16000) {
|
|
37
59
|
doc = preview(doc, '', 1);
|
|
38
60
|
}
|
|
39
|
-
|
|
61
|
+
// c81: runKit, recommendation and getRunning are the answer itself (file, sha256, command); growing
|
|
62
|
+
// 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']);
|
|
40
64
|
// Keep the selected outcome and its proof together when the card fits the response budget.
|
|
41
65
|
if (doc.receiptCard && Buffer.byteLength(JSON.stringify(doc.receiptCard)) <= 12000) protectedKeys.add('receiptCard');
|
|
42
66
|
const largest = Object.keys(doc).filter(key => !protectedKeys.has(key))
|
|
@@ -55,6 +79,7 @@ export function boundMcpAnswer(payload, sourceUrl = "") {
|
|
|
55
79
|
export const COMPACT_ARTIFACT_SCHEMA = {
|
|
56
80
|
type: 'object', required: ['id', 'name', 'task', 'sizeBytes', 'licenseLabel', 'hosted', 'downloadable', 'details'],
|
|
57
81
|
properties: {
|
|
82
|
+
serve_verdict: SERVE_VERDICT_SCHEMA,
|
|
58
83
|
id: { type: 'string' }, name: { type: 'string' }, task: { type: ['string', 'null'] }, sizeBytes: { type: ['number', 'null'] },
|
|
59
84
|
licenseLabel: { type: 'string' }, hosted: { type: ['boolean', 'null'] }, downloadable: { type: ['boolean', 'null'] },
|
|
60
85
|
details: { type: 'object', required: ['href', 'tool'], properties: { href: { type: 'string' }, tool: { const: 'get_artifact' } } },
|
|
@@ -66,7 +91,7 @@ export function compactToolOutputSchema(name) {
|
|
|
66
91
|
const row = { anyOf: [COMPACT_ARTIFACT_SCHEMA, { type: 'object', description: 'Full details when detail is full, or a separate service handoff.' }] };
|
|
67
92
|
return { type: 'object', properties: {
|
|
68
93
|
...(name === 'search_artifacts' || name === 'get_ranking' || name === 'get_trending' ? { rows: { type: 'array', items: row }, total: { type: ['number', 'null'] }, nextCursor: { type: ['string', 'null'] } } : {}),
|
|
69
|
-
...(name === 'find_runnable' ? { recommendation: { anyOf: [row, { type: 'null' }] }, alternatives: { type: 'array', items: row } } : {}),
|
|
94
|
+
...(name === 'find_runnable' ? { local: { enum: ['found', 'none_found', 'checking'] }, fallback: { type: 'object' }, recommendation: { anyOf: [row, { type: 'null' }] }, alternatives: { type: 'array', items: row } } : {}),
|
|
70
95
|
note: { type: 'object', properties: { summary: { type: 'string' } } },
|
|
71
96
|
}, additionalProperties: true };
|
|
72
97
|
}
|
|
@@ -74,7 +99,7 @@ export function compactToolOutputSchema(name) {
|
|
|
74
99
|
const MCP_TEXT_BUDGET_BYTES = 6000;
|
|
75
100
|
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.";
|
|
76
101
|
// Safety and identity fields stay in a preview whenever they fit.
|
|
77
|
-
const MCP_TEXT_KEEP_FIRST = ["note", "schemaVersion", "id", "artifactId", "error", "status", "downloadable", "downloadStatus", "license", "licenseLabel", "degraded", "stale", "next", "details"];
|
|
102
|
+
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"];
|
|
78
103
|
// Never shorten a value an agent could use as real: links and digests stay whole.
|
|
79
104
|
const MCP_TEXT_EXACT_VALUE = /^(?:https?:\/\/|\/api\/)|^(?:sha256:)?(?:[a-f0-9]{40}|[a-f0-9]{64})$/i;
|
|
80
105
|
// Identifiers, cursors, tokens, hashes and links are follow-up inputs; keep them whole.
|
|
@@ -122,10 +147,22 @@ export function mcpAnswerText(payload) {
|
|
|
122
147
|
return withMarker(kept);
|
|
123
148
|
}
|
|
124
149
|
|
|
150
|
+
// A detail link must ask the same question as the bounded response. Do not
|
|
151
|
+
// carry arbitrary tool arguments (credentials, host settings) into public URLs.
|
|
152
|
+
export function findRunnableSourceUrl(args, base) {
|
|
153
|
+
const url = new URL('/api/agents/find-runnable', base);
|
|
154
|
+
for (const key of ['task', 'model', 'requestedModel', 'model_name', 'modelName', 'commercial', 'gpu', 'hardware', 'ramGb', 'ram', 'ctx', 'os', 'deviceFamily', 'customMemoryGb', 'provenOnly']) {
|
|
155
|
+
const value = args[key];
|
|
156
|
+
if (['string', 'number', 'boolean'].includes(typeof value) && String(value) !== '') url.searchParams.set(key, String(value));
|
|
157
|
+
}
|
|
158
|
+
return url.href;
|
|
159
|
+
}
|
|
160
|
+
|
|
125
161
|
export function mcpAnswerSource(name, args, payload, base) {
|
|
162
|
+
if (name === 'find_runnable' && process.env.HUGGING_BAY_AGENT_FLOW_V2 === '1') return findRunnableSourceUrl(args, base);
|
|
126
163
|
const id = args.id || args.artifact || payload?.artifactId || payload?.id;
|
|
127
|
-
if (id && ['get_artifact', 'get_artifact_card', 'list_files', 'deployment_plan'].includes(name)) {
|
|
128
|
-
const suffix = name === 'list_files' ? '/files' : name === 'get_artifact_card' ? '/card' : '';
|
|
164
|
+
if (id && ['get_artifact', 'get_artifact_card', 'get_harness_card', 'list_files', 'deployment_plan'].includes(name)) {
|
|
165
|
+
const suffix = name === 'list_files' ? '/files' : name === 'get_artifact_card' ? '/card' : name === 'get_harness_card' ? '/harness-card' : '';
|
|
129
166
|
return new URL(`/api/v1/artifacts/${encodeURIComponent(id)}${suffix}`, base).href;
|
|
130
167
|
}
|
|
131
168
|
return payload?.apiUrl || new URL(name === 'get_agent_discovery' ? '/api/agent-discovery' : '/api/index.json', base).href;
|
|
@@ -496,13 +496,11 @@ export const HOSTED_DISCOVERY_EXTRA_TOOLS = [
|
|
|
496
496
|
"enum": [
|
|
497
497
|
"received",
|
|
498
498
|
"planned",
|
|
499
|
-
"
|
|
500
|
-
"shipped",
|
|
499
|
+
"built",
|
|
501
500
|
"declined",
|
|
502
|
-
"duplicate",
|
|
503
501
|
"withdrawn"
|
|
504
502
|
],
|
|
505
|
-
"description": "Filter by the
|
|
503
|
+
"description": "Filter by the public lifecycle status: received, planned, built, declined or withdrawn."
|
|
506
504
|
},
|
|
507
505
|
"kind": {
|
|
508
506
|
"type": "string",
|
package/index.mjs
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { createPublicReadFetch, backoffDelayMs } from "./public-read-retry.mjs";
|
|
4
|
+
import { createSwarmClient } from "./swarm-client.mjs";
|
|
5
|
+
import { SWARM_TOOLS, callSwarmTool } from "./swarm-tools.mjs";
|
|
3
6
|
import { installProxyAwareFetch } from "./proxy-fetch.mjs";
|
|
4
|
-
import { boundMcpAnswer, compactAgentDiscovery, mcpAnswerText, mcpAnswerSource, withCompactAnswerSchema } from "./compact-answers.mjs";
|
|
7
|
+
import { boundMcpAnswer, compactAgentDiscovery, mcpAnswerText, mcpAnswerSource, reconcileFindRunnablePublicSummary, withCompactAnswerSchema } from "./compact-answers.mjs";
|
|
5
8
|
import {
|
|
6
9
|
MCP_RELEASE_VERSION,
|
|
7
10
|
MCP_SUPPORTED_PROTOCOL_VERSIONS,
|
|
@@ -19,7 +22,7 @@ import { createMcpStdioReader } from "./mcp-stdio-framing.mjs";
|
|
|
19
22
|
import { mcpStdioLimitsFromEnv, mcpRequestDeadlineMs } from "./mcp-stdio-limits.mjs";
|
|
20
23
|
import { mcpSanitizeClientErrorMessage, mcpSanitizeClientErrorData } from "./mcp-stdio-client-errors.mjs";
|
|
21
24
|
import { withStdioToolMetadata } from "./tool-descriptions.mjs";
|
|
22
|
-
import { REQUEST_MISSING_TOOL, validateRequestMissing, requestMissingTool } from "./request-missing.mjs";
|
|
25
|
+
import { REQUEST_MISSING_TOOL, validateRequestMissing, requestMissingTool, requestMissingValidationMessage } from "./request-missing.mjs";
|
|
23
26
|
import { tagMcpDownloadUrls } from "./mcp-download-via.mjs";
|
|
24
27
|
import { HOSTED_DISCOVERY_EXTRA_TOOLS } from "./hosted-discovery-contracts.mjs";
|
|
25
28
|
import { RUN_LOCAL_TOOL, createLocalRunner } from "./run-local.mjs";
|
|
@@ -27,9 +30,20 @@ import { localTeach } from "./local-teach.mjs";
|
|
|
27
30
|
import { MCP_ARTIFACT_RESOURCE_TEMPLATES, MCP_REPO_RESOURCE_TEMPLATES, parseMcpArtifactResource, parseMcpRepoResource, artifactResourcePath, artifactResources, artifactRunKitResource } from "./mcp-resources.mjs";
|
|
28
31
|
import { MCP_PROMPTS, listMcpPrompts, renderMcpPrompt, mcpPromptResource } from "./mcp-prompts.mjs";
|
|
29
32
|
import { withMcpV2ToolSchema, paginateMcpDiscovery, callMcpListTool } from "./mcp-v2-contracts.mjs";
|
|
33
|
+
import { handleMcpSkillsRequest, mcpSkillResources, readMcpSkillResource } from "./mcp-skills.mjs";
|
|
34
|
+
import { attachMcpToolResult } from "./mcp-typed-result.mjs";
|
|
35
|
+
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
36
|
+
process.stdout.write(`Usage: hugging-bay-mcp [--profile NAME]\n\nMCP server over stdin/stdout. Default profile: ${MCP_PROFILE_MANIFEST.defaultProfile}.\nOptions: --help, --version, --profile NAME\n`);
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
if (process.argv.includes("--version") || process.argv.includes("-v")) {
|
|
40
|
+
process.stdout.write(`${MCP_RELEASE_VERSION}\n`);
|
|
41
|
+
process.exit(0);
|
|
42
|
+
}
|
|
30
43
|
|
|
31
44
|
// Egress-proxy-only machines (agent sandboxes, corporate networks): Node's fetch ignores HTTPS_PROXY.
|
|
32
45
|
installProxyAwareFetch();
|
|
46
|
+
const publicReadFetch = createPublicReadFetch({ fetchImpl: globalThis.fetch });
|
|
33
47
|
const apiBase = process.env.HUGGING_BAY_API || "https://huggingbay.xyz";
|
|
34
48
|
const mcpV2Enabled = process.env.HUGGING_BAY_MCP_V2 === "1";
|
|
35
49
|
const searchV3Enabled = process.env.HUGGING_BAY_SEARCH_V3 === "1";
|
|
@@ -54,7 +68,8 @@ const HOSTED_DISCOVERY_TOOL_NAMES = MCP_PROFILE_MANIFEST.profiles.discovery.tool
|
|
|
54
68
|
const discoveryProfileOnly = mcpProfile === "discovery";
|
|
55
69
|
const runProofDiscoveryEnabled = mcpProfile === "verify"
|
|
56
70
|
&& process.env.HUGGING_BAY_MCP_ENABLE_UNRELEASED_RUN_PROOF === "1";
|
|
57
|
-
const serverCapabilities = mcpServerCapabilities({ surface: "stdio", resources: true, prompts: true });
|
|
71
|
+
const serverCapabilities = mcpServerCapabilities({ surface: "stdio", resources: true, prompts: true, skills: true });
|
|
72
|
+
const typedResultsEnabled = process.env.HUGGING_BAY_MCP_TYPED_RESULTS !== "0";
|
|
58
73
|
const RUN_PROOF_ID_RE = /^hbrp_[a-f0-9]{64}$/;
|
|
59
74
|
const ARTIFACT_ID_RE = /^[a-z0-9][a-z0-9-]{2,150}$/;
|
|
60
75
|
const SHA256_RE = /^sha256:[a-f0-9]{64}$/;
|
|
@@ -81,7 +96,10 @@ const RUN_PROOF_RESOURCE_TEMPLATE = {
|
|
|
81
96
|
mimeType: "application/json",
|
|
82
97
|
};
|
|
83
98
|
|
|
99
|
+
const swarmHelpersEnabled = process.env.HUGGING_BAY_SWARM_FEATURES === "1";
|
|
100
|
+
let swarmClient;
|
|
84
101
|
const tools = [
|
|
102
|
+
...(swarmHelpersEnabled ? SWARM_TOOLS : []),
|
|
85
103
|
RUN_LOCAL_TOOL,
|
|
86
104
|
{
|
|
87
105
|
name: "fine_tune",
|
|
@@ -194,7 +212,7 @@ const tools = [
|
|
|
194
212
|
commercial: { type: "boolean" },
|
|
195
213
|
gpu: { type: "string", description: "Deprecated preset id; prefer hardware." },
|
|
196
214
|
ctx: { type: "integer" },
|
|
197
|
-
os: { type: "string", enum: ["macos", "linux", "windows"], description: "Client OS for the
|
|
215
|
+
os: { type: "string", enum: ["macos", "linux", "windows"], description: "Client OS for getRunning local commands (macos, linux, windows). When omitted, the API returns commandsByOs or infers from User-Agent when getRunning is enabled." },
|
|
198
216
|
},
|
|
199
217
|
additionalProperties: false,
|
|
200
218
|
},
|
|
@@ -1613,7 +1631,8 @@ if (hostedDiscoveryTools.some((tool) => !tool)) {
|
|
|
1613
1631
|
// set is derived from the manifest and membership is enforced on every call.
|
|
1614
1632
|
// Only `full` (toolNames: null) exposes the complete surface. This closes the
|
|
1615
1633
|
// hole where `--profile verify` fell through to every one of the 105 tools.
|
|
1616
|
-
const
|
|
1634
|
+
const profileToolNames = MCP_PROFILE_MANIFEST.profiles[mcpProfile]?.toolNames ?? null;
|
|
1635
|
+
const activeProfileToolNames = swarmHelpersEnabled && mcpProfile === "verify" ? [...profileToolNames, ...SWARM_TOOLS.map(tool => tool.name)] : profileToolNames;
|
|
1617
1636
|
const isBoundedProfile = Array.isArray(activeProfileToolNames);
|
|
1618
1637
|
if (isBoundedProfile) {
|
|
1619
1638
|
const missing = activeProfileToolNames.filter((name) => !allToolsByName.get(name));
|
|
@@ -1861,7 +1880,7 @@ async function apiRequest(path, options = {}) {
|
|
|
1861
1880
|
if (fetchOptions.signal) signals.push(fetchOptions.signal);
|
|
1862
1881
|
if (Number.isFinite(timeoutMs) && timeoutMs > 0) signals.push(AbortSignal.timeout(timeoutMs));
|
|
1863
1882
|
const signal = signals.length === 0 ? undefined : signals.length === 1 ? signals[0] : AbortSignal.any(signals);
|
|
1864
|
-
const response = await
|
|
1883
|
+
const response = await publicReadFetch(apiUrl(path), { ...fetchOptions, headers, ...(signal ? { signal } : {}) });
|
|
1865
1884
|
const text = await response.text();
|
|
1866
1885
|
let body;
|
|
1867
1886
|
try {
|
|
@@ -1870,9 +1889,12 @@ async function apiRequest(path, options = {}) {
|
|
|
1870
1889
|
body = text;
|
|
1871
1890
|
}
|
|
1872
1891
|
if (!response.ok && !acceptedStatuses.has(response.status)) {
|
|
1873
|
-
const message = typeof body === "object" && body?.error ? body.error : `${response.status} ${response.statusText}`;
|
|
1892
|
+
const message = typeof body === "object" && (body?.message || body?.error) ? body.message || body.error : `${response.status} ${response.statusText}`;
|
|
1874
1893
|
const error = new Error(message);
|
|
1875
|
-
error.
|
|
1894
|
+
error.status = response.status;
|
|
1895
|
+
const delay = backoffDelayMs(response.headers, body);
|
|
1896
|
+
error.payload = body && typeof body === "object" && delay !== null
|
|
1897
|
+
? { ...body, retry_after_s: delay / 1000, retryAfterSeconds: delay / 1000 } : body;
|
|
1876
1898
|
throw error;
|
|
1877
1899
|
}
|
|
1878
1900
|
return projectPublicNote(body);
|
|
@@ -1883,7 +1905,7 @@ async function apiText(path, options = {}) {
|
|
|
1883
1905
|
if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
1884
1906
|
const timeout = AbortSignal.timeout(stdioLimits.fetchTimeoutMs);
|
|
1885
1907
|
const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
|
|
1886
|
-
const response = await
|
|
1908
|
+
const response = await publicReadFetch(apiUrl(path), { ...options, headers, signal });
|
|
1887
1909
|
const text = await response.text();
|
|
1888
1910
|
if (!response.ok) {
|
|
1889
1911
|
const error = new Error(`${response.status} ${response.statusText}`);
|
|
@@ -1896,12 +1918,12 @@ async function apiText(path, options = {}) {
|
|
|
1896
1918
|
async function remoteHostedMcpStructuredContent(name, input, signal) {
|
|
1897
1919
|
const headers = new Headers({ "Content-Type": "application/json", Accept: "application/json" });
|
|
1898
1920
|
if (token) headers.set("Authorization", `Bearer ${token}`);
|
|
1899
|
-
const response = await
|
|
1921
|
+
const response = await publicReadFetch(apiUrl("/api/mcp"), {
|
|
1900
1922
|
method: "POST",
|
|
1901
1923
|
headers,
|
|
1902
1924
|
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: input } }),
|
|
1903
1925
|
...(signal ? { signal } : {}),
|
|
1904
|
-
});
|
|
1926
|
+
}, { readOnlyPost: ["get_model", "get_serve_decision"].includes(name) });
|
|
1905
1927
|
const text = await response.text();
|
|
1906
1928
|
let body;
|
|
1907
1929
|
try {
|
|
@@ -1912,7 +1934,10 @@ async function remoteHostedMcpStructuredContent(name, input, signal) {
|
|
|
1912
1934
|
if (!response.ok || body?.error) {
|
|
1913
1935
|
const error = new Error(body?.error?.message || `hosted_mcp_proxy_http_${response.status}`);
|
|
1914
1936
|
error.rpcCode = body?.error?.code;
|
|
1915
|
-
|
|
1937
|
+
const payload = body?.error?.data ?? (body && typeof body === "object" ? body : undefined);
|
|
1938
|
+
const delay = backoffDelayMs(response.headers, body);
|
|
1939
|
+
error.status = response.status;
|
|
1940
|
+
error.payload = delay !== null ? { ...payload, retry_after_s: delay / 1000, retryAfterSeconds: delay / 1000 } : payload;
|
|
1916
1941
|
throw error;
|
|
1917
1942
|
}
|
|
1918
1943
|
if (!body?.result || body.result.isError === true) {
|
|
@@ -1951,13 +1976,18 @@ async function callTool(name, input, signal) {
|
|
|
1951
1976
|
// Enforce the allowlist on EVERY bounded profile (discovery AND verify), so a
|
|
1952
1977
|
// verify/discovery launcher can never invoke a tool outside its profile.
|
|
1953
1978
|
if (isBoundedProfile && !listedToolNames.has(name)) throw runProofError("mcp_tool_not_in_profile");
|
|
1979
|
+
if (swarmHelpersEnabled && SWARM_TOOLS.some(tool => tool.name === name)) {
|
|
1980
|
+
swarmClient ||= createSwarmClient({ baseUrl: apiBase, token, backoffV1: process.env.HUGGING_BAY_SWARM_BACKOFF_V1 === "1" });
|
|
1981
|
+
return callSwarmTool(swarmClient, name, input, signal ? { signal } : {});
|
|
1982
|
+
}
|
|
1954
1983
|
if (name === "run_local") return localRunner.run(input, signal);
|
|
1955
1984
|
if (name === "get_accepted_run_proof") return getAcceptedRunProof(input, signal);
|
|
1956
1985
|
if (name === "request_missing") {
|
|
1957
1986
|
const checked = validateRequestMissing(input);
|
|
1958
1987
|
if (!checked.ok) {
|
|
1959
1988
|
const { ok, ...payload } = checked;
|
|
1960
|
-
|
|
1989
|
+
const message = requestMissingValidationMessage(checked);
|
|
1990
|
+
throw Object.assign(new Error(message), { rpcCode: -32602, payload: { ...payload, message } });
|
|
1961
1991
|
}
|
|
1962
1992
|
return apiRequest("/api/v1/request-missing", { method: "POST", body: JSON.stringify(checked.value) });
|
|
1963
1993
|
}
|
|
@@ -2703,13 +2733,20 @@ async function handleMessage(message) {
|
|
|
2703
2733
|
result(id, rendered);
|
|
2704
2734
|
return;
|
|
2705
2735
|
}
|
|
2736
|
+
// skills/list + skills/get: static "how to use Hugging Bay" SKILL.md set (sha256 + size).
|
|
2737
|
+
const skills = handleMcpSkillsRequest(message.method, message.params);
|
|
2738
|
+
if (skills) {
|
|
2739
|
+
if (skills.error) errorResult(id, skills.error.code, skills.error.message, skills.error.data);
|
|
2740
|
+
else result(id, skills.result);
|
|
2741
|
+
return;
|
|
2742
|
+
}
|
|
2706
2743
|
if (message.method === "tools/list") {
|
|
2707
2744
|
const page = mcpV2Enabled ? paginateMcpDiscovery("tools", { tools: listedTools }, message.params, mcpProfile) : { tools: listedTools };
|
|
2708
2745
|
result(id, mcpProfile === "full" ? page : projectPublicNote(page, { appendNote: true }));
|
|
2709
2746
|
return;
|
|
2710
2747
|
}
|
|
2711
2748
|
if (message.method === "tools/call") {
|
|
2712
|
-
|
|
2749
|
+
{
|
|
2713
2750
|
const tool = listedTools.find((tool) => tool.name === message.params?.name);
|
|
2714
2751
|
if (!tool) { errorResult(id, -32602, "Unknown tool", {
|
|
2715
2752
|
guidance: "Call tools/list for this profile, then use a returned tool name.",
|
|
@@ -2744,13 +2781,17 @@ async function handleMessage(message) {
|
|
|
2744
2781
|
const textOutput = legacyArrayText
|
|
2745
2782
|
? projectPublicNote(boundMcpAnswer(tagMcpDownloadUrls(rawCalled), mcpAnswerSource(message.params?.name, message.params?.arguments || {}, rawCalled, apiBase)), { appendNote: true })
|
|
2746
2783
|
: publicOutput;
|
|
2784
|
+
const publishedOutput = message.params?.name === "find_runnable" && textOutput && typeof textOutput === "object" && !Array.isArray(textOutput)
|
|
2785
|
+
? reconcileFindRunnablePublicSummary(textOutput)
|
|
2786
|
+
: textOutput;
|
|
2747
2787
|
// Public objects carry the note in both representations, read independently.
|
|
2748
|
-
|
|
2749
|
-
content: [{ type: "text", text: mcpAnswerText(
|
|
2788
|
+
const callResult = {
|
|
2789
|
+
content: [{ type: "text", text: mcpAnswerText(publishedOutput) }],
|
|
2750
2790
|
structuredContent: Array.isArray(publicOutput) ? { rows: publicOutput }
|
|
2751
|
-
:
|
|
2791
|
+
: publishedOutput && typeof publishedOutput === "object" ? publishedOutput : { value: publishedOutput ?? null },
|
|
2752
2792
|
isError: false,
|
|
2753
|
-
}
|
|
2793
|
+
};
|
|
2794
|
+
result(id, typedToolResult(callResult, message.params?.name, message.params?.arguments));
|
|
2754
2795
|
return;
|
|
2755
2796
|
}
|
|
2756
2797
|
if (message.method === "resources/templates/list") {
|
|
@@ -2760,7 +2801,7 @@ async function handleMessage(message) {
|
|
|
2760
2801
|
return;
|
|
2761
2802
|
}
|
|
2762
2803
|
if (message.method === "resources/list") {
|
|
2763
|
-
if (!mcpV2Enabled) { result(id, { resources:
|
|
2804
|
+
if (!mcpV2Enabled) { result(id, { resources: mcpSkillResources() }); return; }
|
|
2764
2805
|
const cursor = message.params?.cursor;
|
|
2765
2806
|
if (cursor !== undefined && (typeof cursor !== "string" || !/^\d{1,12}$/.test(cursor))) {
|
|
2766
2807
|
throw Object.assign(new Error("Invalid resource cursor"), { rpcCode: -32602,
|
|
@@ -2770,12 +2811,14 @@ async function handleMessage(message) {
|
|
|
2770
2811
|
if (cursor !== undefined) params.set("cursor", cursor);
|
|
2771
2812
|
const sample = await apiRequest(`/api/v1/search?${params}`, { signal: controller.signal });
|
|
2772
2813
|
const rows = Array.isArray(sample?.rows) ? sample.rows : Array.isArray(sample?.items) ? sample.items : [];
|
|
2773
|
-
const resources = rows.flatMap((row) =>
|
|
2774
|
-
typeof row.id === "string" ? artifactResources(row.id, row.name || row.id) : []);
|
|
2814
|
+
const resources = [...(cursor === undefined ? mcpSkillResources() : []), ...rows.flatMap((row) =>
|
|
2815
|
+
typeof row.id === "string" ? artifactResources(row.id, row.name || row.id) : [])];
|
|
2775
2816
|
result(id, { resources, ...(sample?.nextCursor != null ? { nextCursor: String(sample.nextCursor) } : {}) });
|
|
2776
2817
|
return;
|
|
2777
2818
|
}
|
|
2778
2819
|
if (message.method === "resources/read") {
|
|
2820
|
+
const skillContents = readMcpSkillResource(message.params?.uri);
|
|
2821
|
+
if (skillContents) { result(id, { contents: [skillContents] }); return; }
|
|
2779
2822
|
beginProgress();
|
|
2780
2823
|
const uri = message.params?.uri;
|
|
2781
2824
|
const match = typeof uri === "string" ? uri.match(/^huggingbay:\/\/run-proof\/(hbrp_[a-f0-9]{64})$/) : null;
|
|
@@ -2815,11 +2858,11 @@ async function handleMessage(message) {
|
|
|
2815
2858
|
const failure = toolFailure(message.params?.name, error);
|
|
2816
2859
|
const missingPayload = message.params?.name === "request_missing" && error?.payload
|
|
2817
2860
|
? mcpSanitizeClientErrorData(error.payload, { redact: token }) : null;
|
|
2818
|
-
result(id, {
|
|
2861
|
+
result(id, typedToolResult({
|
|
2819
2862
|
content: [{ type: "text", text: JSON.stringify(missingPayload || failure) }],
|
|
2820
2863
|
structuredContent: failure,
|
|
2821
2864
|
isError: true,
|
|
2822
|
-
});
|
|
2865
|
+
}, message.params?.name, message.params?.arguments));
|
|
2823
2866
|
return;
|
|
2824
2867
|
}
|
|
2825
2868
|
if (error?.name === "AbortError" || error?.name === "TimeoutError") {
|
|
@@ -2849,6 +2892,16 @@ async function handleMessage(message) {
|
|
|
2849
2892
|
}
|
|
2850
2893
|
}
|
|
2851
2894
|
|
|
2895
|
+
// Closed typed result (hb_result) on tools/call; HUGGING_BAY_MCP_TYPED_RESULTS=0 disables.
|
|
2896
|
+
function typedToolResult(callResult, name, args) {
|
|
2897
|
+
// Accepted-run proofs are exact citation data mirrored by resources/read; leave them byte-identical.
|
|
2898
|
+
if (!typedResultsEnabled || typeof name !== "string" || runProofToolNames.has(name)) return callResult;
|
|
2899
|
+
return attachMcpToolResult(callResult, {
|
|
2900
|
+
name, args: args && typeof args === "object" ? args : {}, tools: listedTools,
|
|
2901
|
+
validateArguments: (schema, input) => (mcpInvalidToolArgumentsResult(name, schema, input) ? "invalid_arguments" : null),
|
|
2902
|
+
});
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2852
2905
|
const stdioReader = createMcpStdioReader({
|
|
2853
2906
|
limits: stdioLimits,
|
|
2854
2907
|
onMessage(message) { void handleMessage(message); },
|
package/mcp-download-via.mjs
CHANGED
|
@@ -40,6 +40,7 @@ export function tagMcpDownloadUrl(url, via = "mcp") {
|
|
|
40
40
|
|
|
41
41
|
function collect(value, mapping, via, seen) {
|
|
42
42
|
if (!value || typeof value !== "object" || seen.has(value)) return;
|
|
43
|
+
if (value.schemaVersion === "hugging-bay.one-answer.v1") return;
|
|
43
44
|
seen.add(value);
|
|
44
45
|
if (Array.isArray(value)) {
|
|
45
46
|
for (const item of value) collect(item, mapping, via, seen);
|
|
@@ -70,8 +71,17 @@ function replacer(mapping) {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function rewrite(value, replace, seen) {
|
|
73
|
-
if (typeof value === "string")
|
|
74
|
+
if (typeof value === "string") {
|
|
75
|
+
if (value.startsWith("{")) {
|
|
76
|
+
try {
|
|
77
|
+
const parsed = JSON.parse(value);
|
|
78
|
+
if (parsed.oneAnswer || parsed.schemaVersion === "hugging-bay.one-answer.v1") return JSON.stringify(rewrite(parsed, replace, new WeakMap()));
|
|
79
|
+
} catch { /* Plain text keeps the ordinary attribution rewrite. */ }
|
|
80
|
+
}
|
|
81
|
+
return replace(value);
|
|
82
|
+
}
|
|
74
83
|
if (!value || typeof value !== "object") return value;
|
|
84
|
+
if (value.schemaVersion === "hugging-bay.one-answer.v1") return value;
|
|
75
85
|
if (seen.has(value)) return seen.get(value);
|
|
76
86
|
if (Array.isArray(value)) {
|
|
77
87
|
const out = [];
|