hugging-bay-mcp 0.1.9 → 0.1.10
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 +66 -2
- package/compact-answers.mjs +12 -0
- package/hosted-discovery-contracts.mjs +2 -2
- package/index.mjs +200 -40
- package/mcp-prompts.mjs +85 -0
- package/mcp-resources.mjs +78 -0
- package/mcp-v2-contracts.mjs +134 -0
- package/package.json +5 -1
- package/proxy-fetch.mjs +264 -0
- package/public-note-copy.mjs +3 -1
- package/registry-directory-metadata.mjs +1 -1
- package/release-authority.mjs +2 -2
- package/request-missing.mjs +17 -0
- package/server.json +4 -4
- package/tool-descriptions.mjs +63 -7
- package/tool-input-validation.mjs +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# hugging-bay-mcp
|
|
2
2
|
|
|
3
3
|
**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.8` (npm) · **Source candidate:** `0.1.
|
|
4
|
+
**Install:** `npx -y hugging-bay-mcp@0.1.8` (npm) · **Source candidate:** `0.1.10`<br>
|
|
5
5
|
**MCP config (remote):** `claude mcp add --transport http hugging-bay https://huggingbay.xyz/api/mcp`<br>
|
|
6
6
|
**MCP config (stdio):** `{"mcpServers":{"hugging-bay":{"command":"npx","args":["-y","hugging-bay-mcp@0.1.8"],"env":{"HUGGING_BAY_API":"https://huggingbay.xyz"}}}}`<br>
|
|
7
7
|
**First call:** `search_artifacts({ "q": "Qwen3 0.6B GGUF" })`<br>
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
## Profiles: stdio and hosted
|
|
13
13
|
|
|
14
|
-
**What's new in 0.1.9:** the default stdio discovery profile matches hosted `/api/mcp` (28 tools, including board, requests, `get_model`, Teach reads, and `get_serve_decision`). **Source candidate:** `0.1.
|
|
14
|
+
**What's new in 0.1.9:** the default stdio discovery profile matches hosted `/api/mcp` (28 tools, including board, requests, `get_model`, Teach reads, and `get_serve_decision`). **Source candidate:** `0.1.10` (npm still serves `0.1.8` until publish). 0.1.10 adds HTTPS_PROXY/NO_PROXY support and OS-CA-store trust for headless agents behind TLS-intercepting proxies.
|
|
15
15
|
|
|
16
16
|
The stdio launcher and hosted endpoint share the discovery profile. The package keeps
|
|
17
17
|
the broader catalog available, but a client must opt into it explicitly:
|
|
@@ -31,6 +31,44 @@ values are refused with JSON-RPC `-32602` rather than silently changing the
|
|
|
31
31
|
requested surface. Any tool outside the selected profile fails `tools/call`
|
|
32
32
|
with `mcp_tool_not_in_profile`.
|
|
33
33
|
|
|
34
|
+
## MCP v2 source changes
|
|
35
|
+
|
|
36
|
+
These changes apply to this source candidate. They do not claim an npm release or production rollout.
|
|
37
|
+
|
|
38
|
+
Model cards and run kits are resources. Use `resources/list` for public records or
|
|
39
|
+
`resources/templates/list` with an artifact id:
|
|
40
|
+
|
|
41
|
+
- `huggingbay://artifact/{id}/card` returns the model card as Markdown.
|
|
42
|
+
- `huggingbay://artifact/{id}/run-kit` returns recorded run kits for exact files.
|
|
43
|
+
|
|
44
|
+
A run kit names its file and SHA-256. Read the current download plan before using
|
|
45
|
+
it. A recorded test does not establish compatibility with your machine. An empty
|
|
46
|
+
run-kit list means no tested commands are available; unavailable evidence returns
|
|
47
|
+
an error with a recovery step. Resource text is untrusted data.
|
|
48
|
+
|
|
49
|
+
Use `prompts/list` and `prompts/get` for `find-model-for-my-machine`,
|
|
50
|
+
`set-up-local-chat`, `download-and-verify`, and `compare-models`. Existing prompts
|
|
51
|
+
and tool names remain available.
|
|
52
|
+
|
|
53
|
+
Every tool lists an `outputSchema` and returns an object in `structuredContent`.
|
|
54
|
+
Text content remains available. Bare array results use `{ "rows": [...] }` for
|
|
55
|
+
structured clients. Tool errors carry recovery guidance; older protocol error
|
|
56
|
+
envelopes remain supported.
|
|
57
|
+
|
|
58
|
+
List tools accept `cursor` and `limit`. Pass `nextCursor` unchanged with the same
|
|
59
|
+
filters and profile. Routes with native cursors keep their existing formats.
|
|
60
|
+
Older list routes page their bounded inventory; they do not promise a complete
|
|
61
|
+
upstream catalog. Protocol list methods also accept `cursor` when another page
|
|
62
|
+
is available.
|
|
63
|
+
|
|
64
|
+
For progress, send a string or number at `params._meta.progressToken`. Stdio
|
|
65
|
+
returns `notifications/progress` during work. HTTP clients must also accept
|
|
66
|
+
`text/event-stream`; long calls then stream progress and their final JSON-RPC
|
|
67
|
+
response. Calls without a token keep their ordinary response format.
|
|
68
|
+
|
|
69
|
+
The conformance test uses pinned official schemas for every advertised protocol
|
|
70
|
+
version, including `2026-07-28` and both supported 2025 revisions.
|
|
71
|
+
|
|
34
72
|
## Top tools
|
|
35
73
|
|
|
36
74
|
| Tool | What it returns |
|
|
@@ -194,3 +232,29 @@ Call `run_local({"model":"Qwen/Qwen2.5-0.5B-Instruct-GGUF"})`. It checks for a r
|
|
|
194
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. No npm package or binary is published by this change.
|
|
195
233
|
|
|
196
234
|
Prompts stay on your machine.
|
|
235
|
+
|
|
236
|
+
## Complete tool reference for agent builders
|
|
237
|
+
|
|
238
|
+
The expanded [MCP reference](https://huggingbay.xyz/docs/mcp) is staged behind
|
|
239
|
+
`HUGGING_BAY_AGENT_BUILDER_DOCS=1` (default off). It lists each hosted tool and
|
|
240
|
+
each source stdio tool separately, with profiles, purpose, inputs, outputs,
|
|
241
|
+
request templates, errors, and rate limits. Until that flag is enabled, use
|
|
242
|
+
[GET discovery](https://huggingbay.xyz/api/mcp/info) for hosted schemas and
|
|
243
|
+
`tools/list` on your installed package for stdio schemas. Do not assume that
|
|
244
|
+
source tools are published in the pinned npm release.
|
|
245
|
+
|
|
246
|
+
Hosted read-only tools still use POST for `tools/call`. GET discovery and REST
|
|
247
|
+
reads are sufficient to verify examples without invoking a production tool.
|
|
248
|
+
Check both JSON-RPC `error` and `result.isError`; prefer `structuredContent`
|
|
249
|
+
instead of parsing every text block as JSON. A successful result can abstain,
|
|
250
|
+
return no rows, or contain unknown facts.
|
|
251
|
+
|
|
252
|
+
The source stdio inventory is generated locally with no production requests:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
node apps/web/bin/generate-agent-mcp-stdio-reference.mjs
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
The reference tests compare that inventory with all source profiles, including
|
|
259
|
+
local tools and accepted-run-proof opt-ins, and validate every argument example
|
|
260
|
+
against its tool schema.
|
package/compact-answers.mjs
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
// No transport, authorization, licence decisions, or census calculations live here.
|
|
3
3
|
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
4
|
|
|
5
|
+
// Use the same discovery projection in hosted and both stdio entrypoints. The
|
|
6
|
+
// full provider directory otherwise consumes the budget and drops endpoints.
|
|
7
|
+
export function compactAgentDiscovery(payload, sourceUrl = '') {
|
|
8
|
+
if (!payload || typeof payload !== 'object') return payload;
|
|
9
|
+
const keys = ['schemaVersion', 'name', 'generatedAt', 'status', 'purpose', 'askRequests', 'discovery', 'welcome', 'entrypoints', 'tasks', 'freshness', 'rateLimits', 'note'];
|
|
10
|
+
const doc = { ...Object.fromEntries(keys.filter(key => Object.hasOwn(payload, key)).map(key => [key, payload[key]])), details: { href: sourceUrl } };
|
|
11
|
+
if (payload.endpoints) doc.endpoints = Object.fromEntries(
|
|
12
|
+
['remoteMcpDiscovery', 'remoteMcpJsonRpc', 'search', 'finder', 'artifactDownloadPlan', 'blackboard']
|
|
13
|
+
.filter(key => Object.hasOwn(payload.endpoints, key)).map(key => [key, payload.endpoints[key]]));
|
|
14
|
+
return boundMcpAnswer(doc, sourceUrl);
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
export function boundMcpAnswer(payload, sourceUrl = "") {
|
|
6
18
|
let doc = payload;
|
|
7
19
|
if (Buffer.byteLength(JSON.stringify(doc)) <= 18000) return doc;
|
|
@@ -585,7 +585,7 @@ export const HOSTED_DISCOVERY_EXTRA_TOOLS = [
|
|
|
585
585
|
{
|
|
586
586
|
"name": "get_model",
|
|
587
587
|
"title": "Model file and license",
|
|
588
|
-
"description": "Read the license label and commercial-use answer, estimated RAM for the recommended file, and whether an exact requested GGUF quant is hosted.
|
|
588
|
+
"description": "Read the license label and commercial-use answer, estimated RAM for the recommended file, and whether an exact requested GGUF quant is hosted. Includes runKit with tested commands when Hugging Bay has run that exact file and SHA-256; runTested is separate from download availability. Open the file's downloadUrl (/api/downloads): it re-checks and redirects to a signed link that lasts at most 300s (default 300, configurable shorter). Reopen for a fresh link. A URL is not permission.",
|
|
589
589
|
"inputSchema": {
|
|
590
590
|
"type": "object",
|
|
591
591
|
"properties": {
|
|
@@ -618,7 +618,7 @@ export const HOSTED_DISCOVERY_EXTRA_TOOLS = [
|
|
|
618
618
|
},
|
|
619
619
|
{
|
|
620
620
|
"name": "get_serve_decision",
|
|
621
|
-
"description": "
|
|
621
|
+
"description": "Read one model’s current download decision and reason. Use when you need to check file availability. Example: {\"id\":\"model-id\"}. This read does not load or run a model.",
|
|
622
622
|
"inputSchema": {
|
|
623
623
|
"type": "object",
|
|
624
624
|
"required": [
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { installProxyAwareFetch } from "./proxy-fetch.mjs";
|
|
4
|
+
import { boundMcpAnswer, compactAgentDiscovery, mcpAnswerText, mcpAnswerSource, withCompactAnswerSchema } from "./compact-answers.mjs";
|
|
4
5
|
import {
|
|
5
6
|
MCP_RELEASE_VERSION,
|
|
6
7
|
MCP_SUPPORTED_PROTOCOL_VERSIONS,
|
|
@@ -18,12 +19,20 @@ import { createMcpStdioReader } from "./mcp-stdio-framing.mjs";
|
|
|
18
19
|
import { mcpStdioLimitsFromEnv, mcpRequestDeadlineMs } from "./mcp-stdio-limits.mjs";
|
|
19
20
|
import { mcpSanitizeClientErrorMessage, mcpSanitizeClientErrorData } from "./mcp-stdio-client-errors.mjs";
|
|
20
21
|
import { withStdioToolMetadata } from "./tool-descriptions.mjs";
|
|
21
|
-
import { REQUEST_MISSING_TOOL, validateRequestMissing } from "./request-missing.mjs";
|
|
22
|
+
import { REQUEST_MISSING_TOOL, validateRequestMissing, requestMissingTool } from "./request-missing.mjs";
|
|
22
23
|
import { tagMcpDownloadUrls } from "./mcp-download-via.mjs";
|
|
23
24
|
import { HOSTED_DISCOVERY_EXTRA_TOOLS } from "./hosted-discovery-contracts.mjs";
|
|
24
25
|
import { RUN_LOCAL_TOOL, createLocalRunner } from "./run-local.mjs";
|
|
25
26
|
import { localTeach } from "./local-teach.mjs";
|
|
27
|
+
import { MCP_ARTIFACT_RESOURCE_TEMPLATES, MCP_REPO_RESOURCE_TEMPLATES, parseMcpArtifactResource, parseMcpRepoResource, artifactResourcePath, artifactResources, artifactRunKitResource } from "./mcp-resources.mjs";
|
|
28
|
+
import { MCP_PROMPTS, listMcpPrompts, renderMcpPrompt, mcpPromptResource } from "./mcp-prompts.mjs";
|
|
29
|
+
import { withMcpV2ToolSchema, paginateMcpDiscovery, callMcpListTool } from "./mcp-v2-contracts.mjs";
|
|
30
|
+
|
|
31
|
+
// Egress-proxy-only machines (agent sandboxes, corporate networks): Node's fetch ignores HTTPS_PROXY.
|
|
32
|
+
installProxyAwareFetch();
|
|
26
33
|
const apiBase = process.env.HUGGING_BAY_API || "https://huggingbay.xyz";
|
|
34
|
+
const mcpV2Enabled = process.env.HUGGING_BAY_MCP_V2 === "1";
|
|
35
|
+
const searchV3Enabled = process.env.HUGGING_BAY_SEARCH_V3 === "1";
|
|
27
36
|
const token =
|
|
28
37
|
process.env.HUGGING_BAY_TOKEN ||
|
|
29
38
|
process.env.HUGGING_BAY_ADMIN_TOKEN ||
|
|
@@ -45,7 +54,7 @@ const HOSTED_DISCOVERY_TOOL_NAMES = MCP_PROFILE_MANIFEST.profiles.discovery.tool
|
|
|
45
54
|
const discoveryProfileOnly = mcpProfile === "discovery";
|
|
46
55
|
const runProofDiscoveryEnabled = mcpProfile === "verify"
|
|
47
56
|
&& process.env.HUGGING_BAY_MCP_ENABLE_UNRELEASED_RUN_PROOF === "1";
|
|
48
|
-
const serverCapabilities = mcpServerCapabilities({ surface: "stdio", resources:
|
|
57
|
+
const serverCapabilities = mcpServerCapabilities({ surface: "stdio", resources: true, prompts: true });
|
|
49
58
|
const RUN_PROOF_ID_RE = /^hbrp_[a-f0-9]{64}$/;
|
|
50
59
|
const ARTIFACT_ID_RE = /^[a-z0-9][a-z0-9-]{2,150}$/;
|
|
51
60
|
const SHA256_RE = /^sha256:[a-f0-9]{64}$/;
|
|
@@ -97,7 +106,7 @@ const tools = [
|
|
|
97
106
|
properties: { job_id: { type: "string", pattern: "^teach_[a-f0-9]{32}$" } },
|
|
98
107
|
},
|
|
99
108
|
},
|
|
100
|
-
|
|
109
|
+
requestMissingTool(),
|
|
101
110
|
{
|
|
102
111
|
name: "blackboard",
|
|
103
112
|
description: [
|
|
@@ -214,6 +223,15 @@ const tools = [
|
|
|
214
223
|
additionalProperties: false,
|
|
215
224
|
},
|
|
216
225
|
},
|
|
226
|
+
{
|
|
227
|
+
name: "list_warm_models",
|
|
228
|
+
description: "List warm Bay Run models from the Hugging Bay curated pool with sample curl for GET /api/agents/bay-run-warm-models and a sample embeddings run. Requires HUGGING_BAY_BAYRUN_TRUST=1 on the hosted server.",
|
|
229
|
+
inputSchema: {
|
|
230
|
+
type: "object",
|
|
231
|
+
properties: {},
|
|
232
|
+
additionalProperties: false,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
217
235
|
{
|
|
218
236
|
name: "get_health",
|
|
219
237
|
description: "Return Hugging Bay public health and persistence state.",
|
|
@@ -603,6 +621,13 @@ const tools = [
|
|
|
603
621
|
additionalProperties: false,
|
|
604
622
|
},
|
|
605
623
|
},
|
|
624
|
+
{
|
|
625
|
+
name: "list_collections",
|
|
626
|
+
description: "List six curated model collections from current hosted-file, licence and run evidence. Memory fit is an estimate.",
|
|
627
|
+
inputSchema: {
|
|
628
|
+
type: "object", properties: { slug: { type: "string", minLength: 1, maxLength: 64, pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$" } }, additionalProperties: false,
|
|
629
|
+
},
|
|
630
|
+
},
|
|
606
631
|
{
|
|
607
632
|
name: "list_stacks",
|
|
608
633
|
description: "List practical Hugging Bay AI stack packs for RAG, local LLMs, agent tools, commercial-safe AI, verified downloads, and research/code discovery.",
|
|
@@ -705,6 +730,7 @@ const tools = [
|
|
|
705
730
|
source: { type: "string" },
|
|
706
731
|
commercial: { type: "string", enum: ["1", "true"] },
|
|
707
732
|
semantic: { type: "string", enum: ["1", "true"] },
|
|
733
|
+
...(searchV3Enabled ? { mode: { type: "string", enum: ["lexical", "hybrid"], description: "Hybrid combines keywords and local embeddings. Lexical uses keyword search." } } : {}),
|
|
708
734
|
explain: { type: "string", enum: ["1", "true"] },
|
|
709
735
|
},
|
|
710
736
|
additionalProperties: false,
|
|
@@ -1545,7 +1571,14 @@ const tools = [
|
|
|
1545
1571
|
},
|
|
1546
1572
|
},
|
|
1547
1573
|
];
|
|
1548
|
-
for (let i = 0; i < tools.length; i++)
|
|
1574
|
+
for (let i = 0; i < tools.length; i++) {
|
|
1575
|
+
tools[i] = withStdioToolMetadata(withCompactAnswerSchema(tools[i]));
|
|
1576
|
+
if (mcpV2Enabled) tools[i] = withMcpV2ToolSchema(tools[i]);
|
|
1577
|
+
if (tools[i].name === "request_missing" && process.env.HUGGING_BAY_MODEL_REQUESTS_V2 === "1") {
|
|
1578
|
+
const contract = requestMissingTool();
|
|
1579
|
+
tools[i] = { ...tools[i], description: contract.description, inputSchema: contract.inputSchema };
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1549
1582
|
|
|
1550
1583
|
// `deployment_plan` already exists in the hosted discovery profile, but is
|
|
1551
1584
|
// served in-process by the catalog and therefore was never part of the older
|
|
@@ -1564,7 +1597,7 @@ const hostedProfileOnlyTools = Object.freeze([
|
|
|
1564
1597
|
additionalProperties: false,
|
|
1565
1598
|
},
|
|
1566
1599
|
},
|
|
1567
|
-
].map(withStdioToolMetadata));
|
|
1600
|
+
].map((tool) => (mcpV2Enabled ? withMcpV2ToolSchema(withStdioToolMetadata(tool)) : withStdioToolMetadata(tool))));
|
|
1568
1601
|
const runProofToolNames = new Set(["get_accepted_run_proof"]);
|
|
1569
1602
|
const discoveryRank = new Map(HOSTED_DISCOVERY_TOOL_NAMES.map((name, index) => [name, index]));
|
|
1570
1603
|
const orderedTools = [...tools].sort((a, b) => (discoveryRank.get(a.name) ?? HOSTED_DISCOVERY_TOOL_NAMES.length) - (discoveryRank.get(b.name) ?? HOSTED_DISCOVERY_TOOL_NAMES.length));
|
|
@@ -1595,9 +1628,10 @@ const localRunEnabled = process.env.HUGGING_BAY_MCP_ENABLE_RUN_LOCAL === "1";
|
|
|
1595
1628
|
const localTeachNames = new Set(["fine_tune", "fine_tune_status"]);
|
|
1596
1629
|
const localTeachEnabled = process.env.HBAY_TEACH_LOCAL === "1";
|
|
1597
1630
|
const listedTools = (runProofDiscoveryEnabled ? profileTools : profileTools.filter((tool) => !runProofToolNames.has(tool.name)))
|
|
1598
|
-
.filter(tool => !localTeachNames.has(tool.name) && (tool.name !== "run_local" || localRunEnabled));
|
|
1599
|
-
if (localRunEnabled && !listedTools.some(tool => tool.name === "run_local")) listedTools.push(RUN_LOCAL_TOOL);
|
|
1631
|
+
.filter(tool => (tool.name !== "list_collections" || process.env.HUGGING_BAY_COLLECTIONS === "1") && !localTeachNames.has(tool.name) && (tool.name !== "run_local" || localRunEnabled));
|
|
1632
|
+
if (localRunEnabled && !listedTools.some(tool => tool.name === "run_local")) listedTools.push((mcpV2Enabled ? withMcpV2ToolSchema(withStdioToolMetadata(RUN_LOCAL_TOOL)) : withStdioToolMetadata(RUN_LOCAL_TOOL)));
|
|
1600
1633
|
if (localTeachEnabled) listedTools.push(...tools.filter(tool => localTeachNames.has(tool.name)));
|
|
1634
|
+
if (process.env.HUGGING_BAY_COLLECTIONS === "1" && ["discovery", "verify"].includes(mcpProfile)) listedTools.push(tools.find(tool => tool.name === "list_collections"));
|
|
1601
1635
|
const listedToolNames = new Set(listedTools.map((tool) => tool.name));
|
|
1602
1636
|
|
|
1603
1637
|
function apiUrl(path) {
|
|
@@ -1878,11 +1912,13 @@ async function remoteHostedMcpStructuredContent(name, input, signal) {
|
|
|
1878
1912
|
if (!response.ok || body?.error) {
|
|
1879
1913
|
const error = new Error(body?.error?.message || `hosted_mcp_proxy_http_${response.status}`);
|
|
1880
1914
|
error.rpcCode = body?.error?.code;
|
|
1881
|
-
error.payload = body?.error?.data;
|
|
1915
|
+
error.payload = body?.error?.data ?? (body && typeof body === "object" ? body : undefined);
|
|
1882
1916
|
throw error;
|
|
1883
1917
|
}
|
|
1884
1918
|
if (!body?.result || body.result.isError === true) {
|
|
1885
|
-
|
|
1919
|
+
const error = new Error(body?.result?.content?.find(item => item.type === "text")?.text || "hosted_mcp_proxy_failed");
|
|
1920
|
+
error.payload = body?.result?.structuredContent;
|
|
1921
|
+
throw error;
|
|
1886
1922
|
}
|
|
1887
1923
|
if (body?.result?.structuredContent !== undefined) return body.result.structuredContent;
|
|
1888
1924
|
if (body?.result?.content?.[0]?.type === "text") {
|
|
@@ -1901,7 +1937,8 @@ const localRunner = createLocalRunner();
|
|
|
1901
1937
|
process.once("exit", () => localRunner.stop());
|
|
1902
1938
|
process.once("SIGTERM", () => { localRunner.stop(); process.exit(0); });
|
|
1903
1939
|
process.once("SIGINT", () => { localRunner.stop(); process.exit(0); });
|
|
1904
|
-
|
|
1940
|
+
// Let Node reap the local child before exiting when the client closes stdio.
|
|
1941
|
+
process.stdin.once("end", () => { localRunner.stop(); });
|
|
1905
1942
|
async function callTool(name, input, signal) {
|
|
1906
1943
|
if (name !== "request_missing") input ||= {};
|
|
1907
1944
|
const apiRequest = (path, options = {}) => mcpApiRequest(path, { ...options, ...(signal ? { signal } : {}) });
|
|
@@ -1955,6 +1992,7 @@ async function callTool(name, input, signal) {
|
|
|
1955
1992
|
const params = paramsFrom(input, ["task", "limit", "commercial"]);
|
|
1956
1993
|
return apiRequest(`/api/recommend-specialist?${params}`);
|
|
1957
1994
|
}
|
|
1995
|
+
if (name === "list_warm_models") return apiRequest("/api/agents/bay-run-warm-models");
|
|
1958
1996
|
if (name === "get_health") return apiRequest("/api/health", { acceptStatuses: [503] });
|
|
1959
1997
|
if (name === "get_catalog_coverage") return apiRequest("/api/catalog/coverage");
|
|
1960
1998
|
if (name === "get_open_source_radar") return apiRequest("/api/radar");
|
|
@@ -1966,7 +2004,7 @@ async function callTool(name, input, signal) {
|
|
|
1966
2004
|
return apiRequest(`/api/v1/trending?${params}`);
|
|
1967
2005
|
}
|
|
1968
2006
|
if (name === "get_traffic") return apiRequest("/api/traffic");
|
|
1969
|
-
if (name === "get_agent_discovery") return apiRequest("/api/agent-discovery");
|
|
2007
|
+
if (name === "get_agent_discovery") return compactAgentDiscovery(await apiRequest("/api/agent-discovery"), apiUrl("/api/agent-discovery"));
|
|
1970
2008
|
if (name === "get_ai_bot_allowlist") return apiRequest("/.well-known/ai-bot-allowlist.json");
|
|
1971
2009
|
if (name === "get_ai_search_guidance") return apiRequest("/api/ai-search");
|
|
1972
2010
|
if (name === "get_ai_mention_monitor") return apiRequest("/api/ai-mention-monitor");
|
|
@@ -2072,6 +2110,12 @@ async function callTool(name, input, signal) {
|
|
|
2072
2110
|
if (!params.has("limit")) params.set("limit", "50");
|
|
2073
2111
|
return apiRequest(`/api/mirror-readiness?${params}`);
|
|
2074
2112
|
}
|
|
2113
|
+
if (name === "list_collections") {
|
|
2114
|
+
if (process.env.HUGGING_BAY_COLLECTIONS !== "1") throw new Error("Unknown tool: list_collections");
|
|
2115
|
+
if (!input || typeof input !== "object" || Array.isArray(input) || Object.keys(input).some(key => key !== "slug")
|
|
2116
|
+
|| (input.slug !== undefined && (typeof input.slug !== "string" || input.slug.length > 64 || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(input.slug)))) throw new Error("Invalid collection arguments");
|
|
2117
|
+
return apiRequest(`/api/v1/collections${input.slug ? `?slug=${encodeURIComponent(input.slug)}` : ""}`);
|
|
2118
|
+
}
|
|
2075
2119
|
if (name === "list_stacks") return apiRequest("/api/stacks");
|
|
2076
2120
|
if (name === "get_stack") return apiRequest(`/api/stacks/${encodeURIComponent(input.slug)}`);
|
|
2077
2121
|
if (name === "list_answer_packs") return apiRequest("/api/answers");
|
|
@@ -2084,7 +2128,7 @@ async function callTool(name, input, signal) {
|
|
|
2084
2128
|
}
|
|
2085
2129
|
if (name === "get_ranking") return apiRequest(`/api/rankings/${encodeURIComponent(input.slug)}?summary=${input.detail === "full" ? "0" : "1"}`);
|
|
2086
2130
|
if (name === "search_artifacts") {
|
|
2087
|
-
const params = paramsFrom(input, ["q", "limit", "cursor", "sort", "type", "license", "task", "framework", "format", "hosting", "reviewStatus", "source", "commercial", "semantic", "explain"]);
|
|
2131
|
+
const params = paramsFrom(input, ["q", "limit", "cursor", "sort", "type", "license", "task", "framework", "format", "hosting", "reviewStatus", "source", "commercial", "semantic", ...(searchV3Enabled ? ["mode"] : []), "explain"]);
|
|
2088
2132
|
params.set("summary", input.detail === "full" ? "0" : "1");
|
|
2089
2133
|
if (!params.has("limit")) params.set("limit", "50");
|
|
2090
2134
|
return apiRequest(`/api/v1/search?${params}`);
|
|
@@ -2495,6 +2539,50 @@ function errorResult(id, code, message, data) {
|
|
|
2495
2539
|
writeMessage({ jsonrpc: "2.0", id, error: { code, message, ...(data === undefined ? {} : { data }) } });
|
|
2496
2540
|
}
|
|
2497
2541
|
|
|
2542
|
+
function toolFailure(name, error) {
|
|
2543
|
+
const payload = error?.payload && typeof error.payload === "object" && !Array.isArray(error.payload)
|
|
2544
|
+
? mcpSanitizeClientErrorData(error.payload, { redact: token }) : {};
|
|
2545
|
+
const message = mcpSanitizeClientErrorMessage(error instanceof Error ? error.message : "Tool failed", { redact: token });
|
|
2546
|
+
const code = typeof payload.code === "string" ? payload.code
|
|
2547
|
+
: typeof payload.error === "string" ? payload.error : "tool_failed";
|
|
2548
|
+
const guidance = typeof payload.guidance === "string" ? payload.guidance
|
|
2549
|
+
: Number.isFinite(payload.retryAfterSeconds) && payload.retryAfterSeconds > 0
|
|
2550
|
+
? "Wait for the retry interval in this error, then retry."
|
|
2551
|
+
: /auth|unauthor|forbidden|token|permission/i.test(`${code} ${message}`)
|
|
2552
|
+
? "Check HUGGING_BAY_TOKEN and its role, then retry."
|
|
2553
|
+
: /not_found|not found|404/.test(`${code} ${message}`)
|
|
2554
|
+
? "Resolve the artifact or list the available records, then retry with a returned id."
|
|
2555
|
+
: /timeout|timed out|fetch failed|unavailable|429|503/i.test(`${code} ${message}`)
|
|
2556
|
+
? "Retry after a short wait. Use a smaller limit for list calls."
|
|
2557
|
+
: "Check the tool input schema and retry. If this continues, check the service health.";
|
|
2558
|
+
return { ...payload, code, message, guidance, tool: name };
|
|
2559
|
+
}
|
|
2560
|
+
|
|
2561
|
+
async function readArtifactResource(uri, signal) {
|
|
2562
|
+
const parsed = parseMcpArtifactResource(uri) || parseMcpRepoResource(uri);
|
|
2563
|
+
if (!parsed) {
|
|
2564
|
+
throw Object.assign(new Error("Unknown resource URI"), { rpcCode: -32602,
|
|
2565
|
+
payload: { guidance: "Call resources/templates/list, then use an artifact id in a listed URI template." } });
|
|
2566
|
+
}
|
|
2567
|
+
let artifactId = parsed.reference;
|
|
2568
|
+
if (artifactId.includes("/")) {
|
|
2569
|
+
const resolved = await apiRequest(`/api/v1/resolve?${new URLSearchParams({ repo: artifactId, summary: "1" })}`, { signal });
|
|
2570
|
+
artifactId = resolved?.artifactId || resolved?.artifact?.id || resolved?.id;
|
|
2571
|
+
if (typeof artifactId !== "string" || !artifactId) {
|
|
2572
|
+
throw Object.assign(new Error("Artifact resource not found"), { rpcCode: -32002,
|
|
2573
|
+
payload: { guidance: "Call resolve_artifact and retry with the returned artifact id." } });
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
const path = artifactResourcePath(artifactId, parsed.section);
|
|
2577
|
+
let text;
|
|
2578
|
+
if (parsed.mimeType === "text/markdown") text = await apiText(path, { signal });
|
|
2579
|
+
else {
|
|
2580
|
+
const doc = await apiRequest(path, { signal });
|
|
2581
|
+
text = JSON.stringify(parsed.section === "run-kit" ? artifactRunKitResource(doc) : doc);
|
|
2582
|
+
}
|
|
2583
|
+
return { uri, mimeType: parsed.mimeType, text };
|
|
2584
|
+
}
|
|
2585
|
+
|
|
2498
2586
|
const pendingRequests = new Map();
|
|
2499
2587
|
async function handleMessage(message) {
|
|
2500
2588
|
if (!message || typeof message !== "object") return;
|
|
@@ -2521,8 +2609,23 @@ async function handleMessage(message) {
|
|
|
2521
2609
|
if (typeof requestDeadline.unref === "function") requestDeadline.unref();
|
|
2522
2610
|
pendingRequests.set(id, entry);
|
|
2523
2611
|
let replySent = false;
|
|
2612
|
+
let progressTimer;
|
|
2613
|
+
let progress = 0;
|
|
2614
|
+
const progressToken = message.params?._meta?.progressToken;
|
|
2615
|
+
const canReportProgress = mcpV2Enabled && (typeof progressToken === "string" || (typeof progressToken === "number" && Number.isFinite(progressToken)));
|
|
2616
|
+
const reportProgress = (text) => {
|
|
2617
|
+
if (!canReportProgress || replySent || controller.signal.aborted) return;
|
|
2618
|
+
writeMessage({ jsonrpc: "2.0", method: "notifications/progress", params: { progressToken, progress: progress++, message: text } });
|
|
2619
|
+
};
|
|
2620
|
+
const beginProgress = () => {
|
|
2621
|
+
if (!canReportProgress) return;
|
|
2622
|
+
reportProgress("Working on the request.");
|
|
2623
|
+
progressTimer = setInterval(() => reportProgress("The request is still running."), 1000);
|
|
2624
|
+
progressTimer.unref?.();
|
|
2625
|
+
};
|
|
2524
2626
|
const emit = (payload) => {
|
|
2525
2627
|
if (replySent) return;
|
|
2628
|
+
clearInterval(progressTimer);
|
|
2526
2629
|
replySent = true;
|
|
2527
2630
|
writeMessage(mcpResultForProtocol(message, payload, {
|
|
2528
2631
|
...protocol,
|
|
@@ -2547,6 +2650,7 @@ async function handleMessage(message) {
|
|
|
2547
2650
|
errorResult(id, -32000, reason === "timeout" ? "Request timed out" : "Request cancelled", {
|
|
2548
2651
|
code: reason === "timeout" ? "stdio_request_timeout" : "stdio_request_cancelled",
|
|
2549
2652
|
...(reason === "timeout" ? { deadlineMs } : {}),
|
|
2653
|
+
guidance: reason === "timeout" ? "Retry with a smaller limit or a longer request timeout." : "Start a new request if this work is still needed.",
|
|
2550
2654
|
});
|
|
2551
2655
|
controller.abort();
|
|
2552
2656
|
};
|
|
@@ -2584,31 +2688,49 @@ async function handleMessage(message) {
|
|
|
2584
2688
|
return;
|
|
2585
2689
|
}
|
|
2586
2690
|
if (message.method === "prompts/list") {
|
|
2587
|
-
result(id, { prompts: [] });
|
|
2691
|
+
if (!mcpV2Enabled) { result(id, { prompts: [] }); return; }
|
|
2692
|
+
result(id, paginateMcpDiscovery("prompts", listMcpPrompts(MCP_PROMPTS), message.params, mcpProfile));
|
|
2588
2693
|
return;
|
|
2589
2694
|
}
|
|
2590
2695
|
if (message.method === "prompts/get") {
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2696
|
+
if (!mcpV2Enabled) { errorResult(id, -32602, "Unknown prompt"); return; }
|
|
2697
|
+
const { resourceUris, ...rendered } = renderMcpPrompt(message.params?.name, message.params?.arguments);
|
|
2698
|
+
for (const uri of resourceUris) {
|
|
2699
|
+
if (!mcpV2Enabled) { errorResult(id, -32602, "Unknown resource URI"); return; }
|
|
2700
|
+
const resource = await readArtifactResource(uri, controller.signal);
|
|
2701
|
+
rendered.messages.push({ role: "user", content: { type: "resource", resource: mcpPromptResource(resource) } });
|
|
2702
|
+
}
|
|
2703
|
+
result(id, rendered);
|
|
2595
2704
|
return;
|
|
2596
2705
|
}
|
|
2597
2706
|
if (message.method === "tools/list") {
|
|
2598
|
-
|
|
2707
|
+
const page = mcpV2Enabled ? paginateMcpDiscovery("tools", { tools: listedTools }, message.params, mcpProfile) : { tools: listedTools };
|
|
2708
|
+
result(id, mcpProfile === "full" ? page : projectPublicNote(page, { appendNote: true }));
|
|
2599
2709
|
return;
|
|
2600
2710
|
}
|
|
2601
2711
|
if (message.method === "tools/call") {
|
|
2602
2712
|
if (protocol.version !== "2025-06-18") {
|
|
2603
2713
|
const tool = listedTools.find((tool) => tool.name === message.params?.name);
|
|
2604
|
-
if (!tool) { errorResult(id, -32602, "Unknown tool"
|
|
2714
|
+
if (!tool) { errorResult(id, -32602, "Unknown tool", {
|
|
2715
|
+
guidance: "Call tools/list for this profile, then use a returned tool name.",
|
|
2716
|
+
}); return; }
|
|
2605
2717
|
if (tool.name !== "request_missing") {
|
|
2606
2718
|
const invalid = mcpInvalidToolArgumentsResult(tool.name, tool.inputSchema, message.params?.arguments ?? {});
|
|
2607
2719
|
if (invalid) { result(id, invalid); return; }
|
|
2608
2720
|
}
|
|
2609
2721
|
}
|
|
2722
|
+
beginProgress();
|
|
2610
2723
|
// HB download URLs handed out here carry ?via=mcp (download metrics door attribution).
|
|
2611
|
-
const
|
|
2724
|
+
const tool = listedTools.find((tool) => tool.name === message.params?.name);
|
|
2725
|
+
let rawCalled;
|
|
2726
|
+
const called = message.params?.name === "request_missing"
|
|
2727
|
+
? await callTool(message.params.name, message.params.arguments, controller.signal)
|
|
2728
|
+
: await callMcpListTool(message.params?.name, message.params?.arguments,
|
|
2729
|
+
async (input) => {
|
|
2730
|
+
rawCalled = await callTool(message.params?.name, input, controller.signal);
|
|
2731
|
+
return rawCalled;
|
|
2732
|
+
}, { scope: mcpProfile, schema: tool?.inputSchema });
|
|
2733
|
+
reportProgress("Request complete.");
|
|
2612
2734
|
// A local signed receipt is immutable protocol data. Public-copy scrubbers
|
|
2613
2735
|
// and URL attribution would invalidate its signature.
|
|
2614
2736
|
if (message.params?.name === "run_local") {
|
|
@@ -2617,30 +2739,57 @@ async function handleMessage(message) {
|
|
|
2617
2739
|
}
|
|
2618
2740
|
const output = tagMcpDownloadUrls(called);
|
|
2619
2741
|
const publicOutput = projectPublicNote(boundMcpAnswer(output, mcpAnswerSource(message.params?.name, message.params?.arguments || {}, output, apiBase)), { appendNote: true });
|
|
2620
|
-
|
|
2742
|
+
const legacyArrayText = Array.isArray(rawCalled) && output?.nextCursor == null
|
|
2743
|
+
&& message.params?.arguments?.cursor === undefined && message.params?.arguments?.limit === undefined;
|
|
2744
|
+
const textOutput = legacyArrayText
|
|
2745
|
+
? projectPublicNote(boundMcpAnswer(tagMcpDownloadUrls(rawCalled), mcpAnswerSource(message.params?.name, message.params?.arguments || {}, rawCalled, apiBase)), { appendNote: true })
|
|
2746
|
+
: publicOutput;
|
|
2747
|
+
// Public objects carry the note in both representations, read independently.
|
|
2621
2748
|
result(id, {
|
|
2622
|
-
content: [{ type: "text", text: mcpAnswerText(
|
|
2623
|
-
structuredContent: publicOutput
|
|
2749
|
+
content: [{ type: "text", text: mcpAnswerText(textOutput) }],
|
|
2750
|
+
structuredContent: Array.isArray(publicOutput) ? { rows: publicOutput }
|
|
2751
|
+
: publicOutput && typeof publicOutput === "object" ? publicOutput : { value: publicOutput ?? null },
|
|
2624
2752
|
isError: false,
|
|
2625
2753
|
});
|
|
2626
2754
|
return;
|
|
2627
2755
|
}
|
|
2628
|
-
if (message.method === "resources/templates/list"
|
|
2629
|
-
|
|
2756
|
+
if (message.method === "resources/templates/list") {
|
|
2757
|
+
const resourceTemplates = [...(runProofDiscoveryEnabled ? [RUN_PROOF_RESOURCE_TEMPLATE] : []),
|
|
2758
|
+
...(mcpV2Enabled ? [...MCP_ARTIFACT_RESOURCE_TEMPLATES, ...MCP_REPO_RESOURCE_TEMPLATES] : [])];
|
|
2759
|
+
result(id, paginateMcpDiscovery("resourceTemplates", { resourceTemplates }, message.params, mcpProfile));
|
|
2630
2760
|
return;
|
|
2631
2761
|
}
|
|
2632
|
-
if (message.method === "resources/list"
|
|
2633
|
-
result(id, { resources: [] });
|
|
2762
|
+
if (message.method === "resources/list") {
|
|
2763
|
+
if (!mcpV2Enabled) { result(id, { resources: [] }); return; }
|
|
2764
|
+
const cursor = message.params?.cursor;
|
|
2765
|
+
if (cursor !== undefined && (typeof cursor !== "string" || !/^\d{1,12}$/.test(cursor))) {
|
|
2766
|
+
throw Object.assign(new Error("Invalid resource cursor"), { rpcCode: -32602,
|
|
2767
|
+
payload: { code: "invalid_cursor", guidance: "Call resources/list without a cursor, then use its nextCursor." } });
|
|
2768
|
+
}
|
|
2769
|
+
const params = new URLSearchParams({ limit: "20", summary: "1" });
|
|
2770
|
+
if (cursor !== undefined) params.set("cursor", cursor);
|
|
2771
|
+
const sample = await apiRequest(`/api/v1/search?${params}`, { signal: controller.signal });
|
|
2772
|
+
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) : []);
|
|
2775
|
+
result(id, { resources, ...(sample?.nextCursor != null ? { nextCursor: String(sample.nextCursor) } : {}) });
|
|
2634
2776
|
return;
|
|
2635
2777
|
}
|
|
2636
|
-
if (message.method === "resources/read"
|
|
2778
|
+
if (message.method === "resources/read") {
|
|
2779
|
+
beginProgress();
|
|
2637
2780
|
const uri = message.params?.uri;
|
|
2638
2781
|
const match = typeof uri === "string" ? uri.match(/^huggingbay:\/\/run-proof\/(hbrp_[a-f0-9]{64})$/) : null;
|
|
2639
|
-
if (
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2782
|
+
if (runProofDiscoveryEnabled && typeof uri === "string" && uri.startsWith("huggingbay://run-proof/")) {
|
|
2783
|
+
if (!match) throw runProofError("accepted_run_proof_resource_uri_invalid");
|
|
2784
|
+
const output = await getAcceptedRunProof({ proofId: match[1] }, controller.signal);
|
|
2785
|
+
reportProgress("Request complete.");
|
|
2786
|
+
result(id, { contents: [{ uri, mimeType: "application/json", text: JSON.stringify(output) }] });
|
|
2787
|
+
return;
|
|
2788
|
+
}
|
|
2789
|
+
if (!mcpV2Enabled) { errorResult(id, -32602, "Unknown resource URI"); return; }
|
|
2790
|
+
const resource = await readArtifactResource(uri, controller.signal);
|
|
2791
|
+
reportProgress("Request complete.");
|
|
2792
|
+
result(id, { contents: [resource] });
|
|
2644
2793
|
return;
|
|
2645
2794
|
}
|
|
2646
2795
|
if (message.method === "ping") {
|
|
@@ -2654,22 +2803,21 @@ async function handleMessage(message) {
|
|
|
2654
2803
|
errorResult(id, -32000, "Request timed out", {
|
|
2655
2804
|
code: "stdio_request_timeout",
|
|
2656
2805
|
deadlineMs,
|
|
2806
|
+
guidance: "Retry with a smaller limit or a longer request timeout.",
|
|
2657
2807
|
});
|
|
2658
2808
|
return;
|
|
2659
2809
|
}
|
|
2660
2810
|
if (!replySent && entry.abortReason === "cancelled") {
|
|
2661
|
-
errorResult(id, -32000, "Request cancelled", { code: "stdio_request_cancelled" });
|
|
2811
|
+
errorResult(id, -32000, "Request cancelled", { code: "stdio_request_cancelled", guidance: "Start a new request if this work is still needed." });
|
|
2662
2812
|
return;
|
|
2663
2813
|
}
|
|
2664
2814
|
if (message.method === "tools/call" && protocol.version !== MCP_LEGACY_PROTOCOL_VERSIONS.at(-1) && listedTools.some((tool) => tool.name === message.params?.name)) {
|
|
2815
|
+
const failure = toolFailure(message.params?.name, error);
|
|
2665
2816
|
const missingPayload = message.params?.name === "request_missing" && error?.payload
|
|
2666
2817
|
? mcpSanitizeClientErrorData(error.payload, { redact: token }) : null;
|
|
2667
|
-
const failureText = missingPayload
|
|
2668
|
-
? JSON.stringify(missingPayload)
|
|
2669
|
-
: mcpSanitizeClientErrorMessage(error instanceof Error ? error.message : "Tool failed", { redact: token });
|
|
2670
2818
|
result(id, {
|
|
2671
|
-
content: [{ type: "text", text:
|
|
2672
|
-
|
|
2819
|
+
content: [{ type: "text", text: JSON.stringify(missingPayload || failure) }],
|
|
2820
|
+
structuredContent: failure,
|
|
2673
2821
|
isError: true,
|
|
2674
2822
|
});
|
|
2675
2823
|
return;
|
|
@@ -2678,12 +2826,24 @@ async function handleMessage(message) {
|
|
|
2678
2826
|
errorResult(id, -32000, entry.abortReason === "cancelled" ? "Request cancelled" : "Request timed out", {
|
|
2679
2827
|
code: entry.abortReason === "cancelled" ? "stdio_request_cancelled" : "stdio_request_timeout",
|
|
2680
2828
|
deadlineMs,
|
|
2829
|
+
guidance: entry.abortReason === "cancelled" ? "Start a new request if this work is still needed." : "Retry with a smaller limit or a longer request timeout.",
|
|
2830
|
+
});
|
|
2831
|
+
return;
|
|
2832
|
+
}
|
|
2833
|
+
if (message.method === "resources/read") {
|
|
2834
|
+
const payload = error?.payload && typeof error.payload === "object" && !Array.isArray(error.payload) ? error.payload : {};
|
|
2835
|
+
errorResult(id, error?.rpcCode ?? -32000, error instanceof Error ? error.message : "Resource read failed", {
|
|
2836
|
+
...payload,
|
|
2837
|
+
guidance: payload.guidance || (parseMcpArtifactResource(message.params?.uri)?.section === "run-kit"
|
|
2838
|
+
? "Read the artifact download plan again when the service is available. Do not run a file without its current hash and tested commands."
|
|
2839
|
+
: "Check the artifact id and service health, then retry the resource read."),
|
|
2681
2840
|
});
|
|
2682
2841
|
return;
|
|
2683
2842
|
}
|
|
2684
2843
|
errorResult(id, error?.rpcCode ?? -32000, error instanceof Error ? error.message : "Tool failed", error?.payload);
|
|
2685
2844
|
}
|
|
2686
2845
|
} finally {
|
|
2846
|
+
clearInterval(progressTimer);
|
|
2687
2847
|
clearTimeout(requestDeadline);
|
|
2688
2848
|
if (pendingRequests.get(id) === entry) pendingRequests.delete(id);
|
|
2689
2849
|
}
|