@yawlabs/mcp 1.1.6 → 1.1.8
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/dist/index.js
CHANGED
|
@@ -127,7 +127,7 @@ import {
|
|
|
127
127
|
userConfigDir,
|
|
128
128
|
withFileLock,
|
|
129
129
|
yawModeOverlay
|
|
130
|
-
} from "./chunk-
|
|
130
|
+
} from "./chunk-7C5YSE4J.js";
|
|
131
131
|
|
|
132
132
|
// src/audit-cmd.ts
|
|
133
133
|
import { homedir as homedir6 } from "os";
|
|
@@ -3204,7 +3204,30 @@ function redactSecretsInOutput(text, env) {
|
|
|
3204
3204
|
function withConfigPointer(message, config) {
|
|
3205
3205
|
return `${message} -> Fix "${config.namespace}" in ${bundlesFileHint("defines-it")}, then activate it again -- the edit is picked up on the next mcp_connect_* call, with no client restart.`;
|
|
3206
3206
|
}
|
|
3207
|
+
function unstartableFileCode(err) {
|
|
3208
|
+
if (typeof err !== "object" || err === null) return null;
|
|
3209
|
+
const { code, syscall } = err;
|
|
3210
|
+
if (code === "EFTYPE") return "EFTYPE";
|
|
3211
|
+
if (code === "UNKNOWN" && typeof syscall === "string" && syscall.startsWith("spawn")) return "UNKNOWN";
|
|
3212
|
+
return null;
|
|
3213
|
+
}
|
|
3214
|
+
function winErrorOf(err) {
|
|
3215
|
+
const value = typeof err === "object" && err !== null ? err.winError : void 0;
|
|
3216
|
+
return typeof value === "number" ? value : void 0;
|
|
3217
|
+
}
|
|
3218
|
+
var WIN32_EXE_MACHINE_TYPE_MISMATCH = 216;
|
|
3219
|
+
function unstartableFileMessage(code, err, command) {
|
|
3220
|
+
if (code === "EFTYPE") {
|
|
3221
|
+
return `Command '${command}' could not be started: the OS does not recognise it as a program (spawn EFTYPE -- an empty, truncated or non-executable file). Reinstall or re-download it.`;
|
|
3222
|
+
}
|
|
3223
|
+
const winError = winErrorOf(err);
|
|
3224
|
+
if (winError === WIN32_EXE_MACHINE_TYPE_MISMATCH) {
|
|
3225
|
+
return `Command '${command}' could not be started: it is built for a CPU architecture this machine cannot run, or is not a valid program file (spawn UNKNOWN, Win32 error 216 ERROR_EXE_MACHINE_TYPE_MISMATCH). Install the build for this machine.`;
|
|
3226
|
+
}
|
|
3227
|
+
return `Command '${command}' could not be started: the OS refused to run it (spawn UNKNOWN${winError === void 0 ? "" : `, Win32 error ${winError}`}). Common causes: a binary built for another CPU architecture, a corrupt or partial download, or an application-control or antivirus block.`;
|
|
3228
|
+
}
|
|
3207
3229
|
function categorizeSpawnError(err) {
|
|
3230
|
+
if (unstartableFileCode(err)) return "spawn_failure";
|
|
3208
3231
|
const msg = err instanceof Error ? err.message : String(err);
|
|
3209
3232
|
if (/ENOENT|not found|cannot find|command failed to start/i.test(msg)) return "spawn_failure";
|
|
3210
3233
|
if (/EACCES|permission denied/i.test(msg)) return "spawn_failure";
|
|
@@ -3341,7 +3364,7 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3341
3364
|
if (downstreamCaps?.sampling) capabilities.sampling = downstreamCaps.sampling;
|
|
3342
3365
|
if (downstreamCaps?.roots) capabilities.roots = {};
|
|
3343
3366
|
const client = new Client(
|
|
3344
|
-
{ name: "yaw-mcp", version: true ? "1.1.
|
|
3367
|
+
{ name: "yaw-mcp", version: true ? "1.1.8" : "dev" },
|
|
3345
3368
|
{ capabilities }
|
|
3346
3369
|
);
|
|
3347
3370
|
if (bridge && capabilities.elicitation) {
|
|
@@ -3592,8 +3615,12 @@ async function connectToUpstreamOnce(config, onDisconnect, onListChanged, bridge
|
|
|
3592
3615
|
message = oomHint ? `Server "${config.namespace}" ran out of memory. ${oomHint} stderr: ${safe.slice(-500)}` : `Server "${config.namespace}" failed to start. stderr: ${safe.slice(-500)}`;
|
|
3593
3616
|
} else {
|
|
3594
3617
|
category = categorizeSpawnError(err);
|
|
3595
|
-
|
|
3596
|
-
|
|
3618
|
+
const unstartable = unstartableFileCode(err);
|
|
3619
|
+
const spawnedNote = spawnedCommand && spawnedCommand !== config.command ? ` The binary that actually failed to spawn was '${spawnedCommand}'.` : "";
|
|
3620
|
+
if (unstartable) {
|
|
3621
|
+
message = `${unstartableFileMessage(unstartable, err, config.command)}${spawnedNote}`;
|
|
3622
|
+
} else if (category === "spawn_failure") {
|
|
3623
|
+
message = `Command '${config.command}' is not on PATH or is not executable. Verify the runtime is installed (e.g. Node.js for npx, Python for uvx).${spawnedNote}`;
|
|
3597
3624
|
} else {
|
|
3598
3625
|
message = err instanceof Error ? err.message : String(err);
|
|
3599
3626
|
}
|
|
@@ -4681,15 +4708,15 @@ function renderList(print) {
|
|
|
4681
4708
|
print("");
|
|
4682
4709
|
const byCategory = /* @__PURE__ */ new Map();
|
|
4683
4710
|
for (const b of CURATED_BUNDLES) {
|
|
4684
|
-
const
|
|
4685
|
-
|
|
4686
|
-
byCategory.set(b.category,
|
|
4711
|
+
const list2 = byCategory.get(b.category) ?? [];
|
|
4712
|
+
list2.push(b);
|
|
4713
|
+
byCategory.set(b.category, list2);
|
|
4687
4714
|
}
|
|
4688
4715
|
const categories = [...byCategory.keys()].sort();
|
|
4689
4716
|
for (const cat of categories) {
|
|
4690
|
-
const
|
|
4717
|
+
const list2 = (byCategory.get(cat) ?? []).slice().sort((a, b) => a.id.localeCompare(b.id));
|
|
4691
4718
|
print(` [${cat}]`);
|
|
4692
|
-
for (const b of
|
|
4719
|
+
for (const b of list2) {
|
|
4693
4720
|
print(` ${b.id.padEnd(18)} ${b.name}`);
|
|
4694
4721
|
print(` ${b.description}`);
|
|
4695
4722
|
print(` -> ${bundleActivateHint(b)}`);
|
|
@@ -6567,9 +6594,9 @@ function cliToNamespaces() {
|
|
|
6567
6594
|
const map = /* @__PURE__ */ new Map();
|
|
6568
6595
|
for (const [namespace, shadows] of Object.entries(NAMESPACE_REGISTRY)) {
|
|
6569
6596
|
for (const s of shadows) {
|
|
6570
|
-
const
|
|
6571
|
-
|
|
6572
|
-
map.set(s.cli,
|
|
6597
|
+
const list2 = map.get(s.cli) ?? [];
|
|
6598
|
+
list2.push(namespace);
|
|
6599
|
+
map.set(s.cli, list2);
|
|
6573
6600
|
}
|
|
6574
6601
|
}
|
|
6575
6602
|
reverseIndexCache = map;
|
|
@@ -10757,7 +10784,7 @@ function foldBundleWarnings(warnings, probe) {
|
|
|
10757
10784
|
const prefix = `${probe.path}:`;
|
|
10758
10785
|
return warnings.filter((w) => !w.startsWith(prefix));
|
|
10759
10786
|
}
|
|
10760
|
-
var VERSION = true ? "1.1.
|
|
10787
|
+
var VERSION = true ? "1.1.8" : "dev";
|
|
10761
10788
|
var DOCTOR_USAGE = `Usage: yaw-mcp doctor [--json]
|
|
10762
10789
|
|
|
10763
10790
|
Print a diagnostic of your yaw-mcp setup.
|
|
@@ -12555,6 +12582,92 @@ var SUB_FLOOR_STOPWORDS = /* @__PURE__ */ new Set([
|
|
|
12555
12582
|
function tokenizeQuery(text) {
|
|
12556
12583
|
return tokenizeIdent(text).filter((t) => t.length >= MIN_TOKEN_LEN || !SUB_FLOOR_STOPWORDS.has(t));
|
|
12557
12584
|
}
|
|
12585
|
+
var ABBREVIATIONS = {
|
|
12586
|
+
pr: ["pull", "request"],
|
|
12587
|
+
prs: ["pull", "request"],
|
|
12588
|
+
k8s: ["kubernetes"],
|
|
12589
|
+
repo: ["repository"],
|
|
12590
|
+
repos: ["repository"],
|
|
12591
|
+
db: ["database"],
|
|
12592
|
+
dbs: ["database"],
|
|
12593
|
+
gh: ["github"],
|
|
12594
|
+
pkg: ["package"],
|
|
12595
|
+
pkgs: ["package"],
|
|
12596
|
+
dep: ["dependency"],
|
|
12597
|
+
deps: ["dependency"],
|
|
12598
|
+
dir: ["directory"],
|
|
12599
|
+
dirs: ["directory"],
|
|
12600
|
+
doc: ["documentation"],
|
|
12601
|
+
docs: ["documentation"],
|
|
12602
|
+
config: ["configuration"],
|
|
12603
|
+
configs: ["configuration"],
|
|
12604
|
+
cfg: ["configuration"],
|
|
12605
|
+
auth: ["authentication"],
|
|
12606
|
+
env: ["environment"],
|
|
12607
|
+
envs: ["environment"],
|
|
12608
|
+
cred: ["credential"],
|
|
12609
|
+
creds: ["credential"],
|
|
12610
|
+
cert: ["certificate"],
|
|
12611
|
+
certs: ["certificate"],
|
|
12612
|
+
msg: ["message"],
|
|
12613
|
+
msgs: ["message"],
|
|
12614
|
+
img: ["image"],
|
|
12615
|
+
imgs: ["image"],
|
|
12616
|
+
param: ["parameter"],
|
|
12617
|
+
params: ["parameter"],
|
|
12618
|
+
arg: ["argument"],
|
|
12619
|
+
args: ["argument"],
|
|
12620
|
+
info: ["information"],
|
|
12621
|
+
perf: ["performance"],
|
|
12622
|
+
stats: ["statistic"],
|
|
12623
|
+
prod: ["production"],
|
|
12624
|
+
mgmt: ["management"],
|
|
12625
|
+
txn: ["transaction"],
|
|
12626
|
+
js: ["javascript"],
|
|
12627
|
+
ts: ["typescript"],
|
|
12628
|
+
py: ["python"]
|
|
12629
|
+
};
|
|
12630
|
+
var STEM_EXCEPTIONS = /* @__PURE__ */ new Set(["news", "series", "species", "always", "perhaps"]);
|
|
12631
|
+
var VOWEL = /[aeiouy]/;
|
|
12632
|
+
function undouble(s) {
|
|
12633
|
+
const n = s.length;
|
|
12634
|
+
return n >= 4 && s[n - 1] === s[n - 2] && !/[aeiouylsz]/.test(s[n - 1]) ? s.slice(0, -1) : s;
|
|
12635
|
+
}
|
|
12636
|
+
function isShortCvc(s) {
|
|
12637
|
+
return s.length === 3 && !VOWEL.test(s[0]) && VOWEL.test(s[1]) && !VOWEL.test(s[2]);
|
|
12638
|
+
}
|
|
12639
|
+
function restoreE(stem) {
|
|
12640
|
+
const u = undouble(stem);
|
|
12641
|
+
if (u !== stem) return u;
|
|
12642
|
+
return isShortCvc(stem) && !/[wxy]$/.test(stem) ? `${stem}e` : stem;
|
|
12643
|
+
}
|
|
12644
|
+
function normalizeTerm(token) {
|
|
12645
|
+
if (token.length <= 3 || /\d/.test(token) || STEM_EXCEPTIONS.has(token)) return token;
|
|
12646
|
+
let s = token;
|
|
12647
|
+
if (s.endsWith("ies") && s.length > 4) s = `${s.slice(0, -3)}y`;
|
|
12648
|
+
else if (s.endsWith("sses")) s = s.slice(0, -2);
|
|
12649
|
+
else if (/(?:x|z|ch|sh)es$/.test(s)) s = s.slice(0, -2);
|
|
12650
|
+
else if (s.endsWith("s") && !/(?:ss|us|is)$/.test(s)) s = s.slice(0, -1);
|
|
12651
|
+
if (s.endsWith("ied") && s.length > 4) s = `${s.slice(0, -3)}y`;
|
|
12652
|
+
else if (s.endsWith("ing") && s.length >= 6 && VOWEL.test(s.slice(0, -3))) s = restoreE(s.slice(0, -3));
|
|
12653
|
+
else if (s.endsWith("ed") && !s.endsWith("eed") && s.length >= 5 && VOWEL.test(s.slice(0, -2))) {
|
|
12654
|
+
const stem = s.slice(0, -2);
|
|
12655
|
+
if (stem.length > 3 || isShortCvc(stem)) s = restoreE(stem);
|
|
12656
|
+
}
|
|
12657
|
+
if (s.endsWith("ability") && s.length >= 9) s = s.slice(0, -7);
|
|
12658
|
+
else if (s.endsWith("able") && s.length >= 7) s = s.slice(0, -4);
|
|
12659
|
+
if (s.endsWith("e") && s.length >= 5) s = s.slice(0, -1);
|
|
12660
|
+
return s.length >= 3 ? s : token;
|
|
12661
|
+
}
|
|
12662
|
+
function normalizeTokens(tokens) {
|
|
12663
|
+
const out = [];
|
|
12664
|
+
for (const t of tokens) {
|
|
12665
|
+
const expanded = ABBREVIATIONS[t];
|
|
12666
|
+
if (expanded) for (const e of expanded) out.push(normalizeTerm(e));
|
|
12667
|
+
else out.push(normalizeTerm(t));
|
|
12668
|
+
}
|
|
12669
|
+
return out;
|
|
12670
|
+
}
|
|
12558
12671
|
function emptyField() {
|
|
12559
12672
|
return { len: 0, counts: /* @__PURE__ */ new Map() };
|
|
12560
12673
|
}
|
|
@@ -12565,19 +12678,28 @@ function addTokens(field, tokens) {
|
|
|
12565
12678
|
field.len += tokens.length;
|
|
12566
12679
|
return field;
|
|
12567
12680
|
}
|
|
12568
|
-
function
|
|
12681
|
+
function buildDoc(server) {
|
|
12569
12682
|
const toolName = emptyField();
|
|
12570
12683
|
const toolDescription = emptyField();
|
|
12684
|
+
const tools = [];
|
|
12571
12685
|
for (const tool of server.tools) {
|
|
12572
|
-
|
|
12573
|
-
|
|
12686
|
+
const nameList = normalizeTokens(tokenizeIdent(tool.name));
|
|
12687
|
+
const descList = normalizeTokens(tokenize(tool.description));
|
|
12688
|
+
addTokens(toolName, nameList);
|
|
12689
|
+
addTokens(toolDescription, descList);
|
|
12690
|
+
tools.push({ name: new Set(nameList), nameList, desc: new Set(descList) });
|
|
12574
12691
|
}
|
|
12692
|
+
const namespaceTerms = normalizeTokens(tokenizeIdent(server.namespace));
|
|
12575
12693
|
return {
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12694
|
+
fields: {
|
|
12695
|
+
namespace: addTokens(emptyField(), namespaceTerms),
|
|
12696
|
+
name: addTokens(emptyField(), normalizeTokens(tokenizeIdent(server.name))),
|
|
12697
|
+
description: addTokens(emptyField(), normalizeTokens(tokenize(server.description))),
|
|
12698
|
+
toolName,
|
|
12699
|
+
toolDescription
|
|
12700
|
+
},
|
|
12701
|
+
tools,
|
|
12702
|
+
namespaceTerms
|
|
12581
12703
|
};
|
|
12582
12704
|
}
|
|
12583
12705
|
function bm25Score(queryTerms, fields, avgFieldLen, idfValues) {
|
|
@@ -12637,20 +12759,114 @@ function serverSignature(server) {
|
|
|
12637
12759
|
function indexKeyFor(docKeys) {
|
|
12638
12760
|
return digest(docKeys.join(""));
|
|
12639
12761
|
}
|
|
12640
|
-
function
|
|
12762
|
+
function docFor(docKey, server) {
|
|
12641
12763
|
const cached = docCache.get(docKey);
|
|
12642
12764
|
if (cached) {
|
|
12643
12765
|
touch(docCache, docKey, cached);
|
|
12644
12766
|
return cached;
|
|
12645
12767
|
}
|
|
12646
12768
|
docBuilds++;
|
|
12647
|
-
const
|
|
12648
|
-
putBounded(docCache, docKey,
|
|
12649
|
-
return
|
|
12769
|
+
const doc = buildDoc(server);
|
|
12770
|
+
putBounded(docCache, docKey, doc, MAX_CACHED_DOCS);
|
|
12771
|
+
return doc;
|
|
12772
|
+
}
|
|
12773
|
+
var ACTION_VERBS = /* @__PURE__ */ new Set([
|
|
12774
|
+
"get",
|
|
12775
|
+
"set",
|
|
12776
|
+
"list",
|
|
12777
|
+
"create",
|
|
12778
|
+
"delete",
|
|
12779
|
+
"update",
|
|
12780
|
+
"add",
|
|
12781
|
+
"remove",
|
|
12782
|
+
"read",
|
|
12783
|
+
"write",
|
|
12784
|
+
"run",
|
|
12785
|
+
"fetch",
|
|
12786
|
+
"search",
|
|
12787
|
+
"find",
|
|
12788
|
+
"check",
|
|
12789
|
+
"show",
|
|
12790
|
+
"open",
|
|
12791
|
+
"close",
|
|
12792
|
+
"start",
|
|
12793
|
+
"stop",
|
|
12794
|
+
"put",
|
|
12795
|
+
"post",
|
|
12796
|
+
"patch",
|
|
12797
|
+
"send",
|
|
12798
|
+
"describe",
|
|
12799
|
+
"query",
|
|
12800
|
+
"execute",
|
|
12801
|
+
"exec",
|
|
12802
|
+
"upload",
|
|
12803
|
+
"download",
|
|
12804
|
+
"install",
|
|
12805
|
+
"enable",
|
|
12806
|
+
"disable"
|
|
12807
|
+
]);
|
|
12808
|
+
var GENERIC_PRODUCT_WORDS = /* @__PURE__ */ new Set(["mcp", "server", "tool", "api", "client", "plugin", "service", "sdk", "app"]);
|
|
12809
|
+
var MIN_NUMERONYM_WORD = 8;
|
|
12810
|
+
function deriveAliases(servers, idf) {
|
|
12811
|
+
const phrases = /* @__PURE__ */ new Map();
|
|
12812
|
+
const fromName = /* @__PURE__ */ new Map();
|
|
12813
|
+
const note = (tokens, nameOf) => {
|
|
12814
|
+
for (let len = 2; len <= 3; len++) {
|
|
12815
|
+
for (let i = 0; i + len <= tokens.length; i++) {
|
|
12816
|
+
const words = tokens.slice(i, i + len);
|
|
12817
|
+
if (!words.every((w) => /^[a-z]{3,}$/.test(w) && !ACTION_VERBS.has(w) && !GENERIC_PRODUCT_WORDS.has(w)))
|
|
12818
|
+
continue;
|
|
12819
|
+
const acronym = words.map((w) => w[0]).join("");
|
|
12820
|
+
const key = normalizeTokens(words).join(" ");
|
|
12821
|
+
let byPhrase = phrases.get(acronym);
|
|
12822
|
+
if (!byPhrase) {
|
|
12823
|
+
byPhrase = /* @__PURE__ */ new Map();
|
|
12824
|
+
phrases.set(acronym, byPhrase);
|
|
12825
|
+
}
|
|
12826
|
+
byPhrase.set(key, (byPhrase.get(key) ?? 0) + (nameOf === void 0 ? 1 : 0));
|
|
12827
|
+
if (nameOf !== void 0) {
|
|
12828
|
+
let owners = fromName.get(key);
|
|
12829
|
+
if (!owners) {
|
|
12830
|
+
owners = /* @__PURE__ */ new Set();
|
|
12831
|
+
fromName.set(key, owners);
|
|
12832
|
+
}
|
|
12833
|
+
owners.add(nameOf);
|
|
12834
|
+
}
|
|
12835
|
+
}
|
|
12836
|
+
}
|
|
12837
|
+
};
|
|
12838
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
12839
|
+
const offer = (alias, terms) => {
|
|
12840
|
+
if (idf.has(alias) || ABBREVIATIONS[alias] || SUB_FLOOR_STOPWORDS.has(alias)) return;
|
|
12841
|
+
aliases.set(alias, terms);
|
|
12842
|
+
};
|
|
12843
|
+
for (const server of servers) {
|
|
12844
|
+
const nsTokens = tokenizeIdent(server.namespace);
|
|
12845
|
+
const nameTokens = tokenizeIdent(server.name);
|
|
12846
|
+
note(nsTokens, server.namespace);
|
|
12847
|
+
note(nameTokens, server.namespace);
|
|
12848
|
+
const own = /* @__PURE__ */ new Set([...nsTokens, ...nameTokens]);
|
|
12849
|
+
for (const tool of server.tools)
|
|
12850
|
+
note(
|
|
12851
|
+
tokenizeIdent(tool.name).map((w) => own.has(w) ? "" : w),
|
|
12852
|
+
void 0
|
|
12853
|
+
);
|
|
12854
|
+
for (const word of [...nsTokens, ...nameTokens]) {
|
|
12855
|
+
if (word.length >= MIN_NUMERONYM_WORD && /^[a-z]+$/.test(word)) {
|
|
12856
|
+
offer(`${word[0]}${word.length - 2}${word[word.length - 1]}`, normalizeTokens([word]));
|
|
12857
|
+
}
|
|
12858
|
+
}
|
|
12859
|
+
}
|
|
12860
|
+
for (const [acronym, byPhrase] of phrases) {
|
|
12861
|
+
if (byPhrase.size !== 1) continue;
|
|
12862
|
+
const [[key, count]] = [...byPhrase];
|
|
12863
|
+
if (count >= 2 || fromName.get(key)?.size === 1) offer(acronym, key.split(" "));
|
|
12864
|
+
}
|
|
12865
|
+
return aliases;
|
|
12650
12866
|
}
|
|
12651
12867
|
function buildIndex(servers, docKeys) {
|
|
12652
12868
|
indexBuilds++;
|
|
12653
|
-
const docs = servers.map((s, i) => ({ namespace: s.namespace,
|
|
12869
|
+
const docs = servers.map((s, i) => ({ namespace: s.namespace, ...docFor(docKeys[i], s) }));
|
|
12654
12870
|
const N = docs.length;
|
|
12655
12871
|
const df = /* @__PURE__ */ new Map();
|
|
12656
12872
|
for (const { fields } of docs) {
|
|
@@ -12686,7 +12902,38 @@ function buildIndex(servers, docKeys) {
|
|
|
12686
12902
|
toolName: totalLen.toolName / denom,
|
|
12687
12903
|
toolDescription: totalLen.toolDescription / denom
|
|
12688
12904
|
};
|
|
12689
|
-
return { docs, idf, avgFieldLen };
|
|
12905
|
+
return { docs, idf, avgFieldLen, aliases: deriveAliases(servers, idf) };
|
|
12906
|
+
}
|
|
12907
|
+
function indexFor(servers) {
|
|
12908
|
+
const docKeys = servers.map((s) => digest(serverSignature(s)));
|
|
12909
|
+
const indexKey = indexKeyFor(docKeys);
|
|
12910
|
+
let index = indexCache.get(indexKey);
|
|
12911
|
+
if (index === void 0) {
|
|
12912
|
+
index = buildIndex(servers, docKeys);
|
|
12913
|
+
putBounded(indexCache, indexKey, index, MAX_CACHED_INDEXES);
|
|
12914
|
+
} else {
|
|
12915
|
+
touch(indexCache, indexKey, index);
|
|
12916
|
+
}
|
|
12917
|
+
return index;
|
|
12918
|
+
}
|
|
12919
|
+
var QUERY_FUNCTION_WORDS = new Set(
|
|
12920
|
+
"the and for are that this with what which how does did was were have has had our your their its from into about can could would should will just any all some when where who why whether then than there here also very much many not but via you they them these those been being please thanks thank let lets since until while between among use using".split(" ")
|
|
12921
|
+
);
|
|
12922
|
+
function queryTermsFor(text, index, drop) {
|
|
12923
|
+
const out = [];
|
|
12924
|
+
for (const t of tokenizeQuery(text)) {
|
|
12925
|
+
if (drop?.has(t)) continue;
|
|
12926
|
+
const expanded = ABBREVIATIONS[t];
|
|
12927
|
+
if (expanded) {
|
|
12928
|
+
for (const e of expanded) out.push(normalizeTerm(e));
|
|
12929
|
+
continue;
|
|
12930
|
+
}
|
|
12931
|
+
const folded = normalizeTerm(t);
|
|
12932
|
+
const alias = index.idf.has(folded) ? void 0 : index.aliases.get(t);
|
|
12933
|
+
if (alias) out.push(...alias);
|
|
12934
|
+
else out.push(folded);
|
|
12935
|
+
}
|
|
12936
|
+
return out;
|
|
12690
12937
|
}
|
|
12691
12938
|
function scoreAgainstIndex(queryTerms, index) {
|
|
12692
12939
|
const results = [];
|
|
@@ -12699,45 +12946,76 @@ function scoreAgainstIndex(queryTerms, index) {
|
|
|
12699
12946
|
results.sort((a, b) => b.score - a.score || a.namespace.localeCompare(b.namespace));
|
|
12700
12947
|
return results;
|
|
12701
12948
|
}
|
|
12702
|
-
function queryNamesNamespace(queryTerms,
|
|
12703
|
-
|
|
12704
|
-
const parts = tokenizeIdent(namespace);
|
|
12705
|
-
return parts.length > 0 && parts.every((p) => queryTerms.has(p));
|
|
12949
|
+
function queryNamesNamespace(queryTerms, namespaceTerms) {
|
|
12950
|
+
return namespaceTerms.length > 0 && namespaceTerms.every((p) => queryTerms.has(p));
|
|
12706
12951
|
}
|
|
12707
12952
|
function rankTools(query, servers) {
|
|
12708
|
-
|
|
12709
|
-
|
|
12953
|
+
if (tokenizeQuery(query).length === 0 || servers.length === 0) return [];
|
|
12954
|
+
const index = indexFor(servers);
|
|
12955
|
+
const termList = queryTermsFor(query, index, QUERY_FUNCTION_WORDS);
|
|
12956
|
+
const queryTerms = new Set(termList);
|
|
12957
|
+
if (queryTerms.size === 0) return [];
|
|
12958
|
+
const serverScore = new Map(scoreAgainstIndex(termList, index).map((r) => [r.namespace, r.score]));
|
|
12710
12959
|
const out = [];
|
|
12711
|
-
|
|
12712
|
-
|
|
12713
|
-
|
|
12714
|
-
|
|
12960
|
+
servers.forEach((server, i) => {
|
|
12961
|
+
const doc = index.docs[i];
|
|
12962
|
+
const namedNamespace = queryNamesNamespace(queryTerms, doc.namespaceTerms);
|
|
12963
|
+
server.tools.forEach((tool, j) => {
|
|
12964
|
+
const terms = doc.tools[j];
|
|
12715
12965
|
let score = 0;
|
|
12966
|
+
let nameHits = 0;
|
|
12716
12967
|
for (const term of queryTerms) {
|
|
12717
|
-
if (
|
|
12718
|
-
|
|
12719
|
-
|
|
12720
|
-
|
|
12721
|
-
|
|
12722
|
-
|
|
12723
|
-
|
|
12724
|
-
|
|
12725
|
-
|
|
12968
|
+
if (terms.name.has(term)) {
|
|
12969
|
+
score += FIELD_WEIGHTS.toolName;
|
|
12970
|
+
nameHits++;
|
|
12971
|
+
} else if (terms.desc.has(term)) score += FIELD_WEIGHTS.toolDescription;
|
|
12972
|
+
}
|
|
12973
|
+
if (score === 0) return;
|
|
12974
|
+
if (namedNamespace) score += 0.5;
|
|
12975
|
+
const nameMisses = terms.nameList.filter((t) => !queryTerms.has(t)).length;
|
|
12976
|
+
out.push({
|
|
12977
|
+
namespace: server.namespace,
|
|
12978
|
+
name: tool.name,
|
|
12979
|
+
description: tool.description,
|
|
12980
|
+
score,
|
|
12981
|
+
serverScore: serverScore.get(server.namespace) ?? 0,
|
|
12982
|
+
nameHits,
|
|
12983
|
+
nameMisses,
|
|
12984
|
+
serverTools: server.tools.length
|
|
12985
|
+
});
|
|
12986
|
+
});
|
|
12987
|
+
});
|
|
12988
|
+
out.sort(
|
|
12989
|
+
(a, b) => b.score - a.score || b.serverScore - a.serverScore || b.nameHits - a.nameHits || a.nameMisses - b.nameMisses || a.serverTools - b.serverTools || a.namespace.localeCompare(b.namespace) || a.name.localeCompare(b.name)
|
|
12726
12990
|
);
|
|
12991
|
+
return out.map(({ namespace, name, description, score }) => ({ namespace, name, description, score }));
|
|
12727
12992
|
}
|
|
12728
12993
|
function rankServers(context, servers) {
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
|
|
12732
|
-
|
|
12733
|
-
|
|
12734
|
-
if (
|
|
12735
|
-
|
|
12736
|
-
|
|
12737
|
-
|
|
12738
|
-
|
|
12739
|
-
|
|
12740
|
-
|
|
12994
|
+
if (tokenizeQuery(context).length === 0 || servers.length === 0) return [];
|
|
12995
|
+
const index = indexFor(servers);
|
|
12996
|
+
return scoreAgainstIndex(queryTermsFor(context, index, QUERY_FUNCTION_WORDS), index);
|
|
12997
|
+
}
|
|
12998
|
+
function queryCoverage(query, servers) {
|
|
12999
|
+
if (servers.length === 0) return [];
|
|
13000
|
+
const index = indexFor(servers);
|
|
13001
|
+
const terms = [
|
|
13002
|
+
...new Set(queryTermsFor(query, index, QUERY_FUNCTION_WORDS).filter((t) => t.length >= 2 && !/^[0-9]+$/.test(t)))
|
|
13003
|
+
];
|
|
13004
|
+
const N = index.docs.length;
|
|
13005
|
+
const unseenIdf = Math.log((N + 0.5) / 0.5 + 1);
|
|
13006
|
+
const idfOf = (t) => index.idf.get(t) ?? unseenIdf;
|
|
13007
|
+
const total = terms.reduce((sum, t) => sum + idfOf(t), 0);
|
|
13008
|
+
return index.docs.map(({ namespace, fields }) => {
|
|
13009
|
+
let mass = 0;
|
|
13010
|
+
let matched = 0;
|
|
13011
|
+
for (const t of terms) {
|
|
13012
|
+
if (Object.keys(FIELD_WEIGHTS).some((f) => fields[f].counts.has(t))) {
|
|
13013
|
+
mass += idfOf(t);
|
|
13014
|
+
matched++;
|
|
13015
|
+
}
|
|
13016
|
+
}
|
|
13017
|
+
return { namespace, coverage: total > 0 ? mass / total : 0, matched, contentTerms: terms.length };
|
|
13018
|
+
});
|
|
12741
13019
|
}
|
|
12742
13020
|
|
|
12743
13021
|
// src/foundry.ts
|
|
@@ -15576,10 +15854,10 @@ function secretConsumersNotice(io, name, consumers, replacing, isFresh, referenc
|
|
|
15576
15854
|
}
|
|
15577
15855
|
const where2 = consumers.path ?? "bundles.json";
|
|
15578
15856
|
if (consumers.namespaces.length > 0) {
|
|
15579
|
-
const
|
|
15857
|
+
const list2 = consumers.namespaces.join(", ");
|
|
15580
15858
|
if (replacing) {
|
|
15581
15859
|
io.err(
|
|
15582
|
-
`yaw-mcp secrets: ${ref} is referenced by: ${
|
|
15860
|
+
`yaw-mcp secrets: ${ref} is referenced by: ${list2} (${where2}).
|
|
15583
15861
|
A running yaw-mcp keeps the OLD value in any of these it has already started, until it
|
|
15584
15862
|
restarts. Unload each one (mcp_connect_deactivate <namespace>; the next call starts it
|
|
15585
15863
|
with the new value), or reconnect yaw-mcp in your MCP client.
|
|
@@ -15587,7 +15865,7 @@ function secretConsumersNotice(io, name, consumers, replacing, isFresh, referenc
|
|
|
15587
15865
|
);
|
|
15588
15866
|
} else {
|
|
15589
15867
|
io.err(
|
|
15590
|
-
`yaw-mcp secrets: ${ref} is referenced by: ${
|
|
15868
|
+
`yaw-mcp secrets: ${ref} is referenced by: ${list2} (${where2}).
|
|
15591
15869
|
yaw-mcp reads the vault at each server start, so they pick it up the next time they start.
|
|
15592
15870
|
One a running yaw-mcp started before an earlier \`secrets remove\` of this name still holds
|
|
15593
15871
|
the value it started with: unload it (mcp_connect_deactivate <namespace>) or reconnect yaw-mcp.
|
|
@@ -17854,6 +18132,147 @@ function validateExecRefs(steps) {
|
|
|
17854
18132
|
return { ok: true };
|
|
17855
18133
|
}
|
|
17856
18134
|
|
|
18135
|
+
// src/fallback-tools.ts
|
|
18136
|
+
var list = (rows) => rows.map(([name, description]) => ({ name, description }));
|
|
18137
|
+
var GITHUB = list([
|
|
18138
|
+
["get_me", "Get details of the authenticated GitHub user"],
|
|
18139
|
+
["get_team_members", "Get member usernames of a specific team in an organization"],
|
|
18140
|
+
["get_teams", "Get details of the teams the user is a member of"],
|
|
18141
|
+
["add_issue_comment", "Add a comment and/or reaction to a specific issue or issue comment in a GitHub repository"],
|
|
18142
|
+
["get_label", "Get a specific label from a repository"],
|
|
18143
|
+
["issue_read", "Get information about a specific issue in a GitHub repository"],
|
|
18144
|
+
["issue_write", "Create a new or update an existing issue in a GitHub repository"],
|
|
18145
|
+
["list_issue_fields", "List issue fields for a repository or organization"],
|
|
18146
|
+
["list_issue_types", "List supported issue types for a repository or its owner organization"],
|
|
18147
|
+
["list_issues", "List issues in a GitHub repository"],
|
|
18148
|
+
["search_issues", "Search issues using natural-language semantic matching"],
|
|
18149
|
+
["sub_issue_write", "Add a sub-issue to a parent issue in a GitHub repository"],
|
|
18150
|
+
["update_issue_comment", "Update the body of an existing issue or pull request conversation comment"],
|
|
18151
|
+
["add_comment_to_pending_review", "Add review comment to the requester's latest pending pull request review"],
|
|
18152
|
+
["add_reply_to_pull_request_comment", "Add a reply and/or reaction to an existing pull request comment"],
|
|
18153
|
+
["create_pull_request", "Create a new pull request in a GitHub repository"],
|
|
18154
|
+
["list_pull_requests", "List pull requests in a GitHub repository"],
|
|
18155
|
+
["merge_pull_request", "Merge a pull request in a GitHub repository"],
|
|
18156
|
+
["pull_request_read", "Get information on a specific pull request in GitHub repository"],
|
|
18157
|
+
["pull_request_review_write", "Create and/or submit, delete review of a pull request"],
|
|
18158
|
+
[
|
|
18159
|
+
"search_pull_requests",
|
|
18160
|
+
"Search for pull requests in GitHub repositories using issues search syntax already scoped to is:pr"
|
|
18161
|
+
],
|
|
18162
|
+
["update_pull_request", "Update an existing pull request in a GitHub repository"],
|
|
18163
|
+
["update_pull_request_branch", "Update the branch of a pull request with the latest changes from the base branch"],
|
|
18164
|
+
["create_branch", "Create a new branch in a GitHub repository"],
|
|
18165
|
+
["create_or_update_file", "Create or update a single file in a GitHub repository"],
|
|
18166
|
+
["create_repository", "Create a new GitHub repository in your account or specified organization"],
|
|
18167
|
+
["delete_file", "Delete a file from a GitHub repository"],
|
|
18168
|
+
["delete_repository", "Delete a GitHub repository after the user confirms the exact owner/repository name"],
|
|
18169
|
+
["fork_repository", "Fork a GitHub repository to your account or specified organization"],
|
|
18170
|
+
["get_commit", "Get details for a commit from a GitHub repository"],
|
|
18171
|
+
["get_file_contents", "Get the contents of a file or directory from a GitHub repository"],
|
|
18172
|
+
["get_latest_release", "Get the latest release in a GitHub repository"],
|
|
18173
|
+
["get_release_by_tag", "Get a specific release by its tag name in a GitHub repository"],
|
|
18174
|
+
["get_tag", "Get details about a specific git tag in a GitHub repository"],
|
|
18175
|
+
["list_branches", "List branches in a GitHub repository"],
|
|
18176
|
+
["list_commits", "Get list of commits of a branch in a GitHub repository"],
|
|
18177
|
+
["list_releases", "List releases in a GitHub repository"],
|
|
18178
|
+
["list_repository_collaborators", "List collaborators of a GitHub repository"],
|
|
18179
|
+
["list_tags", "List git tags in a GitHub repository"],
|
|
18180
|
+
["push_files", "Push multiple files to a GitHub repository in a single commit"],
|
|
18181
|
+
["search_code", "Fast and precise code search across ALL GitHub repositories using GitHub's native search engine"],
|
|
18182
|
+
["search_commits", "Search for commits across GitHub repositories using GitHub's commit search syntax"],
|
|
18183
|
+
["search_repositories", "Find GitHub repositories by name, description, readme, topics, or other metadata"],
|
|
18184
|
+
["search_users", "Find GitHub users by username, real name, or other profile information"]
|
|
18185
|
+
]);
|
|
18186
|
+
var TERRAFORM = list([
|
|
18187
|
+
["get_latest_module_version", "Fetches the latest version of a Terraform module from the public registry"],
|
|
18188
|
+
["get_latest_provider_version", "Fetches the latest version of a Terraform provider from the public registry"],
|
|
18189
|
+
["get_module_details", "Fetches up-to-date documentation on how to use a Terraform module"],
|
|
18190
|
+
["get_policy_details", "Fetches up-to-date documentation for a specific policy from the Terraform registry"],
|
|
18191
|
+
[
|
|
18192
|
+
"get_provider_capabilities",
|
|
18193
|
+
"Get the capabilities of a Terraform provider including the types of resources, data sources, functions, guides, and other features it supports"
|
|
18194
|
+
],
|
|
18195
|
+
["get_provider_details", "Fetches up-to-date documentation for a specific service from a Terraform provider"],
|
|
18196
|
+
[
|
|
18197
|
+
"search_modules",
|
|
18198
|
+
"Resolves a Terraform module name to obtain a compatible module_id for the get_module_details tool and returns a list of matching Terraform modules"
|
|
18199
|
+
],
|
|
18200
|
+
["search_policies", "Searches for Terraform policies based on a query string"],
|
|
18201
|
+
[
|
|
18202
|
+
"search_provider_docs",
|
|
18203
|
+
"This tool retrieves a list of potential documents based on the 'service_slug' and 'provider_document_type' provided"
|
|
18204
|
+
]
|
|
18205
|
+
]);
|
|
18206
|
+
var VAULT = list([
|
|
18207
|
+
["list_mounts", "List the available mounted secrets engines on a Vault Server"],
|
|
18208
|
+
["create_mount", "Mount a new secrets engine on a specific path in Vault"],
|
|
18209
|
+
["delete_mount", "Delete a mounted secret engine in Vault"],
|
|
18210
|
+
["list_secrets", "List secrets in a KV mount under a specific path in Vault"],
|
|
18211
|
+
["read_secret", "Read a secret from a KV mount in at a specific path in Vault"],
|
|
18212
|
+
["write_secret", "Writes a secret value to a KV store in Vault using the specified path and mount"],
|
|
18213
|
+
["delete_secret", "Delete a secret from a KV mount in Vault using the specified path and mount"],
|
|
18214
|
+
[
|
|
18215
|
+
"enable_pki",
|
|
18216
|
+
"Enable the PKI (Public Key Infrastructure) secrets engine in Vault, allowing for the issuance and management of SSL/TLS certificates"
|
|
18217
|
+
],
|
|
18218
|
+
["create_pki_issuer", "Create a new PKI SSL certificate issuer in Vault"],
|
|
18219
|
+
[
|
|
18220
|
+
"list_pki_issuers",
|
|
18221
|
+
"Get a list of PKI issuers on a specific pki mount in Vault, allowing you to see all the configured issuers for that mount"
|
|
18222
|
+
],
|
|
18223
|
+
[
|
|
18224
|
+
"read_pki_issuer",
|
|
18225
|
+
"Read a PKI issuer details from a specific mount in Vault, allowing you to retrieve information about a specific PKI issuer"
|
|
18226
|
+
],
|
|
18227
|
+
[
|
|
18228
|
+
"list_pki_roles",
|
|
18229
|
+
"Get a list of PKI roles which are able to issue certificates, allowing you to see all the configured roles for a specific PKI mount in Vault"
|
|
18230
|
+
],
|
|
18231
|
+
["read_pki_role", "Read a PKI role details from a specific mount in Vault"],
|
|
18232
|
+
["create_pki_role", "Create a new PKI SSL certificate role in Vault"],
|
|
18233
|
+
["delete_pki_role", "Delete a PKI SSL role in Vault"],
|
|
18234
|
+
[
|
|
18235
|
+
"issue_pki_certificate",
|
|
18236
|
+
"Create a new PKI SSL certificate issuer in Vault, allowing for the issuance of SSL/TLS certificates"
|
|
18237
|
+
]
|
|
18238
|
+
]);
|
|
18239
|
+
var ENTRIES = [
|
|
18240
|
+
{ images: ["ghcr.io/github/github-mcp-server"], binaries: ["github-mcp-server"], tools: GITHUB },
|
|
18241
|
+
{
|
|
18242
|
+
images: ["hashicorp/terraform-mcp-server", "docker.io/hashicorp/terraform-mcp-server"],
|
|
18243
|
+
binaries: ["terraform-mcp-server"],
|
|
18244
|
+
tools: TERRAFORM
|
|
18245
|
+
},
|
|
18246
|
+
{
|
|
18247
|
+
images: ["hashicorp/vault-mcp-server", "docker.io/hashicorp/vault-mcp-server"],
|
|
18248
|
+
binaries: ["vault-mcp-server"],
|
|
18249
|
+
tools: VAULT
|
|
18250
|
+
}
|
|
18251
|
+
];
|
|
18252
|
+
function imageRepository(arg) {
|
|
18253
|
+
const noDigest = arg.split("@")[0];
|
|
18254
|
+
const slash = noDigest.lastIndexOf("/");
|
|
18255
|
+
const colon = noDigest.lastIndexOf(":");
|
|
18256
|
+
return (colon > slash ? noDigest.slice(0, colon) : noDigest).toLowerCase();
|
|
18257
|
+
}
|
|
18258
|
+
function binaryName(command) {
|
|
18259
|
+
const base = command.split(/[\\/]/).pop() ?? command;
|
|
18260
|
+
return base.replace(/\.exe$/i, "").toLowerCase();
|
|
18261
|
+
}
|
|
18262
|
+
function fallbackToolsFor(server) {
|
|
18263
|
+
if (!server.command) return void 0;
|
|
18264
|
+
const bin = binaryName(server.command);
|
|
18265
|
+
const args = server.args ?? [];
|
|
18266
|
+
const containerRuntime = bin === "docker" || bin === "podman";
|
|
18267
|
+
for (const entry of ENTRIES) {
|
|
18268
|
+
if (entry.binaries.includes(bin)) return entry.tools;
|
|
18269
|
+
if (containerRuntime && args.some((a) => !a.startsWith("-") && entry.images.includes(imageRepository(a)))) {
|
|
18270
|
+
return entry.tools;
|
|
18271
|
+
}
|
|
18272
|
+
}
|
|
18273
|
+
return void 0;
|
|
18274
|
+
}
|
|
18275
|
+
|
|
17857
18276
|
// src/idle-ttl.ts
|
|
17858
18277
|
var ADAPTIVE_WINDOW_MS = 5 * 60 * 1e3;
|
|
17859
18278
|
var ADAPTIVE_LOOKBACK = 20;
|
|
@@ -17972,7 +18391,8 @@ var PENALTY_RATE_PCT = Math.round(PENALTY_RATE_THRESHOLD * 100);
|
|
|
17972
18391
|
var FIND_TOOL_MAX_LIMIT = 50;
|
|
17973
18392
|
var SERVER_INSTRUCTIONS = [
|
|
17974
18393
|
"yaw-mcp fronts every MCP server the user installed; tools/list shows the mcp_connect_* meta-tools plus servers loaded THIS session. Each load adds tools to your context: unload (mcp_connect_deactivate) when done.",
|
|
17975
|
-
"Concrete task: mcp_connect_dispatch loads the best server in one call. Browsing: mcp_connect_discover. Known 2-4 step chain: mcp_connect_exec (calls a cached server's tool by name, no load needed).",
|
|
18394
|
+
"Concrete task: mcp_connect_dispatch loads the best server in one call; its description (find_tool's when dispatch is unlisted) names the installed servers. Browsing: mcp_connect_discover. Known 2-4 step chain: mcp_connect_exec (calls a cached server's tool by name, no load needed).",
|
|
18395
|
+
"Answer general-knowledge questions directly, without routing. If mcp_connect_find_tool finds nothing, retry with mcp_connect_dispatch in the user's own words. A just-loaded tool reported missing: call it through mcp_connect_exec.",
|
|
17976
18396
|
"Prefer a server over the CLI it shadows. Read yaw-mcp://guide first when listed: this project's routing rules."
|
|
17977
18397
|
].join(" ");
|
|
17978
18398
|
var META_TOOLS = {
|
|
@@ -18099,7 +18519,7 @@ var META_TOOLS = {
|
|
|
18099
18519
|
routeEffort: {
|
|
18100
18520
|
type: "string",
|
|
18101
18521
|
enum: ["off", "auto", "aggressive"],
|
|
18102
|
-
description: 'Per-call routing-effort dial: "off" never asks the client LLM to break a ranking tie, "auto" (default) asks once on genuine ambiguity, "aggressive" samples best-of-3 on milder ambiguity. Falls back to YAW_MCP_ROUTE_EFFORT. Budget 1 only.'
|
|
18522
|
+
description: 'Per-call routing-effort dial: "off" never asks the client LLM to break a ranking tie, "auto" (default) asks once on genuine ambiguity, "aggressive" samples best-of-3 on milder ambiguity. No effect without client MCP sampling. Falls back to YAW_MCP_ROUTE_EFFORT. Budget 1 only.'
|
|
18103
18523
|
}
|
|
18104
18524
|
},
|
|
18105
18525
|
required: ["intent"]
|
|
@@ -18305,291 +18725,99 @@ function computeSecretsReport(servers, vaultKeys) {
|
|
|
18305
18725
|
}
|
|
18306
18726
|
var META_TOOL_NAMES = new Set(Object.values(META_TOOLS).map((m) => m.name));
|
|
18307
18727
|
|
|
18308
|
-
// src/
|
|
18309
|
-
var
|
|
18310
|
-
|
|
18311
|
-
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
|
|
18728
|
+
// src/proxy.ts
|
|
18729
|
+
var DEFERRED_INPUT_SCHEMA = {
|
|
18730
|
+
type: "object",
|
|
18731
|
+
properties: {},
|
|
18732
|
+
additionalProperties: true
|
|
18733
|
+
};
|
|
18734
|
+
function deferredDescription(server, cachedDesc) {
|
|
18735
|
+
const base = cachedDesc?.trim();
|
|
18736
|
+
const suffix = `[yaw-mcp: server "${server.namespace}" not yet connected \u2014 first call activates it]`;
|
|
18737
|
+
return base ? `${base}
|
|
18738
|
+
|
|
18739
|
+
${suffix}` : suffix;
|
|
18317
18740
|
}
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
|
|
18322
|
-
|
|
18323
|
-
|
|
18324
|
-
|
|
18741
|
+
function compareNamespaces(a, b) {
|
|
18742
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
18743
|
+
}
|
|
18744
|
+
function connectionsInOrder(activeConnections) {
|
|
18745
|
+
return [...activeConnections.values()].sort((a, b) => compareNamespaces(a.config.namespace, b.config.namespace));
|
|
18746
|
+
}
|
|
18747
|
+
function serversInOrder(servers) {
|
|
18748
|
+
return [...servers].sort((a, b) => compareNamespaces(a.namespace, b.namespace));
|
|
18749
|
+
}
|
|
18750
|
+
function buildToolList(activeConnections, inactiveWithCache = [], toolFilters, exposure = "full", exposedNamespaces, isDenied) {
|
|
18751
|
+
const tools = [];
|
|
18752
|
+
const seen = /* @__PURE__ */ new Set();
|
|
18753
|
+
for (const meta of Object.values(META_TOOLS)) {
|
|
18754
|
+
if (exposure === "lite" && !LITE_META_TOOL_NAMES.has(meta.name)) continue;
|
|
18755
|
+
tools.push({
|
|
18756
|
+
name: meta.name,
|
|
18757
|
+
description: meta.description,
|
|
18758
|
+
inputSchema: meta.inputSchema,
|
|
18759
|
+
annotations: meta.annotations
|
|
18760
|
+
});
|
|
18761
|
+
seen.add(meta.name);
|
|
18325
18762
|
}
|
|
18326
|
-
|
|
18327
|
-
if (
|
|
18328
|
-
|
|
18329
|
-
|
|
18330
|
-
|
|
18331
|
-
|
|
18332
|
-
|
|
18763
|
+
for (const conn of connectionsInOrder(activeConnections)) {
|
|
18764
|
+
if (exposure !== "full" && !exposedNamespaces?.has(conn.config.namespace)) continue;
|
|
18765
|
+
const filter = toolFilters?.get(conn.config.namespace);
|
|
18766
|
+
for (const tool of conn.tools) {
|
|
18767
|
+
if (filter && !filter.has(tool.name)) continue;
|
|
18768
|
+
if (isDenied?.(tool.namespacedName)) continue;
|
|
18769
|
+
if (seen.has(tool.namespacedName)) continue;
|
|
18770
|
+
tools.push({
|
|
18771
|
+
name: tool.namespacedName,
|
|
18772
|
+
title: tool.title,
|
|
18773
|
+
description: tool.description,
|
|
18774
|
+
inputSchema: tool.inputSchema,
|
|
18775
|
+
outputSchema: tool.outputSchema,
|
|
18776
|
+
annotations: tool.annotations,
|
|
18777
|
+
_meta: tool._meta
|
|
18778
|
+
});
|
|
18779
|
+
seen.add(tool.namespacedName);
|
|
18333
18780
|
}
|
|
18334
18781
|
}
|
|
18335
|
-
|
|
18336
|
-
|
|
18337
|
-
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
|
|
18341
|
-
|
|
18342
|
-
|
|
18343
|
-
|
|
18344
|
-
if (
|
|
18345
|
-
|
|
18346
|
-
|
|
18347
|
-
|
|
18348
|
-
|
|
18349
|
-
|
|
18350
|
-
|
|
18351
|
-
} else {
|
|
18352
|
-
packCounts.set(id, {
|
|
18353
|
-
namespaces: [...burst.namespaces],
|
|
18354
|
-
frequency: 1,
|
|
18355
|
-
lastSeenAt: burst.lastAt
|
|
18356
|
-
});
|
|
18357
|
-
}
|
|
18782
|
+
for (const server of serversInOrder(inactiveWithCache)) {
|
|
18783
|
+
if (activeConnections.has(server.namespace)) continue;
|
|
18784
|
+
if (!server.toolCache || server.toolCache.length === 0) continue;
|
|
18785
|
+
if (exposure !== "full") continue;
|
|
18786
|
+
const filter = toolFilters?.get(server.namespace);
|
|
18787
|
+
for (const cached of server.toolCache) {
|
|
18788
|
+
if (filter && !filter.has(cached.name)) continue;
|
|
18789
|
+
const namespacedName = `${server.namespace}_${cached.name}`;
|
|
18790
|
+
if (isDenied?.(namespacedName)) continue;
|
|
18791
|
+
if (seen.has(namespacedName)) continue;
|
|
18792
|
+
tools.push({
|
|
18793
|
+
name: namespacedName,
|
|
18794
|
+
description: deferredDescription(server, cached.description),
|
|
18795
|
+
inputSchema: DEFERRED_INPUT_SCHEMA
|
|
18796
|
+
});
|
|
18797
|
+
seen.add(namespacedName);
|
|
18358
18798
|
}
|
|
18359
|
-
|
|
18360
|
-
|
|
18361
|
-
|
|
18362
|
-
|
|
18363
|
-
|
|
18364
|
-
|
|
18365
|
-
|
|
18366
|
-
|
|
18799
|
+
}
|
|
18800
|
+
return tools;
|
|
18801
|
+
}
|
|
18802
|
+
function buildToolRoutes(activeConnections, inactiveWithCache = [], quiet = false) {
|
|
18803
|
+
const routes = /* @__PURE__ */ new Map();
|
|
18804
|
+
for (const conn of connectionsInOrder(activeConnections)) {
|
|
18805
|
+
for (const tool of conn.tools) {
|
|
18806
|
+
const existing = routes.get(tool.namespacedName);
|
|
18807
|
+
if (existing && existing.namespace !== conn.config.namespace) {
|
|
18808
|
+
if (!quiet) {
|
|
18809
|
+
log("warn", "Tool route collision; keeping the first upstream, ignoring the later one", {
|
|
18810
|
+
tool: tool.namespacedName,
|
|
18811
|
+
keptNamespace: existing.namespace,
|
|
18812
|
+
ignoredNamespace: conn.config.namespace
|
|
18813
|
+
});
|
|
18814
|
+
}
|
|
18815
|
+
continue;
|
|
18367
18816
|
}
|
|
18368
|
-
|
|
18369
|
-
|
|
18370
|
-
|
|
18371
|
-
|
|
18372
|
-
// 1. the gap to the previous call exceeds maxGapMs (idle boundary);
|
|
18373
|
-
// 2. the burst has already spanned maxGapMs * BURST_SPAN_FACTOR
|
|
18374
|
-
// (span boundary -- see the constant for why a continuous session
|
|
18375
|
-
// must be sliced for recurrence to be countable); or
|
|
18376
|
-
// 3. the call would add a namespace past MAX_NAMESPACES (overflow
|
|
18377
|
-
// boundary). detectChains drops an over-wide burst entirely, so
|
|
18378
|
-
// without this cut a single visit to a 4th namespace poisoned the
|
|
18379
|
-
// whole burst and the recurring trio inside it was never counted.
|
|
18380
|
-
// Cutting at the overflow keeps each burst representable as a
|
|
18381
|
-
// pack; a wider rotation surfaces as its recurring 3-subsets, the
|
|
18382
|
-
// best answer the MAX_NAMESPACES pack-size cap can express. SLOWLY,
|
|
18383
|
-
// though: the cuts walk the rotation, so each 3-subset recurs only
|
|
18384
|
-
// once per full pass over it. A strict a,b,c,d loop segments as
|
|
18385
|
-
// [a,b,c] [d,a,b] [c,d,a] [b,c,d] [a,b,c] ..., and {a,b,c} reaches
|
|
18386
|
-
// MIN_RECURRENCES at the 15th call -- all of which must land inside
|
|
18387
|
-
// one span window and one maxGapMs cadence.
|
|
18388
|
-
// Within a burst, each namespace is recorded only once
|
|
18389
|
-
// (order-of-first-appearance); the "last seen" timestamp tracks the
|
|
18390
|
-
// most recent call in the burst so recency ranking is truthful even
|
|
18391
|
-
// when the burst has many calls.
|
|
18392
|
-
segmentBursts() {
|
|
18393
|
-
const bursts = [];
|
|
18394
|
-
const maxBurstSpanMs = this.maxGapMs * BURST_SPAN_FACTOR;
|
|
18395
|
-
let current = null;
|
|
18396
|
-
let prevAt = 0;
|
|
18397
|
-
for (const call of this.history) {
|
|
18398
|
-
const gapExceeded = call.at - prevAt > this.maxGapMs;
|
|
18399
|
-
const spanExceeded = current !== null && call.at - current.startAt > maxBurstSpanMs;
|
|
18400
|
-
const wentBackwards = current !== null && call.at < prevAt;
|
|
18401
|
-
const wouldOverflow = current !== null && current.namespaces.length >= MAX_NAMESPACES && !current.namespaces.includes(call.namespace);
|
|
18402
|
-
if (!current || gapExceeded || spanExceeded || wentBackwards || wouldOverflow) {
|
|
18403
|
-
current = { namespaces: [call.namespace], startAt: call.at, lastAt: call.at };
|
|
18404
|
-
bursts.push(current);
|
|
18405
|
-
} else {
|
|
18406
|
-
if (!current.namespaces.includes(call.namespace)) {
|
|
18407
|
-
current.namespaces.push(call.namespace);
|
|
18408
|
-
}
|
|
18409
|
-
current.lastAt = call.at;
|
|
18410
|
-
}
|
|
18411
|
-
prevAt = call.at;
|
|
18412
|
-
}
|
|
18413
|
-
return bursts;
|
|
18414
|
-
}
|
|
18415
|
-
// Exposed for tests.
|
|
18416
|
-
getHistory() {
|
|
18417
|
-
return this.history;
|
|
18418
|
-
}
|
|
18419
|
-
reset() {
|
|
18420
|
-
this.history = [];
|
|
18421
|
-
}
|
|
18422
|
-
// Return a defensive copy of history for persistence. Each entry is a
|
|
18423
|
-
// fresh object, safe to JSON.stringify without worrying about later
|
|
18424
|
-
// mutations to the detector's internal array.
|
|
18425
|
-
exportSnapshot() {
|
|
18426
|
-
return this.history.map((c) => ({ namespace: c.namespace, toolName: c.toolName, at: c.at }));
|
|
18427
|
-
}
|
|
18428
|
-
// Replace in-memory history with the given snapshot. Respects the
|
|
18429
|
-
// configured maxHistory cap — if the snapshot exceeds it, the oldest
|
|
18430
|
-
// entries are dropped, matching the cap behavior of recordCall.
|
|
18431
|
-
//
|
|
18432
|
-
// Entries are SORTED by `at` after cleaning. segmentBursts reads the history
|
|
18433
|
-
// as a time-ordered stream (see the boundary comparisons there), and the
|
|
18434
|
-
// snapshot comes off disk where a hand-edited, merged or torn file can carry
|
|
18435
|
-
// entries out of order; an out-of-order run would otherwise be segmented as
|
|
18436
|
-
// one welded burst plus spurious boundaries. Sorting is stable, so equal
|
|
18437
|
-
// timestamps keep their recorded order.
|
|
18438
|
-
//
|
|
18439
|
-
// `at` is validated as a finite number, not just present: the snapshot
|
|
18440
|
-
// comes off disk (persistence.ts) where a hand-edited or torn file can
|
|
18441
|
-
// carry null / "12345" / NaN. segmentBursts compares `call.at - prevAt >
|
|
18442
|
-
// maxGapMs`, and every comparison against NaN is false, so a single NaN
|
|
18443
|
-
// timestamp silently welds the whole history into one giant burst and
|
|
18444
|
-
// manufactures packs that never happened.
|
|
18445
|
-
loadSnapshot(snapshot) {
|
|
18446
|
-
const clean = [];
|
|
18447
|
-
for (const c of snapshot) {
|
|
18448
|
-
if (!c?.namespace || !c.toolName) continue;
|
|
18449
|
-
if (typeof c.at !== "number" || !Number.isFinite(c.at)) continue;
|
|
18450
|
-
clean.push({ namespace: c.namespace, toolName: c.toolName, at: c.at });
|
|
18451
|
-
}
|
|
18452
|
-
clean.sort((a, b) => a.at - b.at);
|
|
18453
|
-
if (clean.length > this.maxHistory) {
|
|
18454
|
-
this.history = clean.slice(clean.length - this.maxHistory);
|
|
18455
|
-
} else {
|
|
18456
|
-
this.history = clean;
|
|
18457
|
-
}
|
|
18458
|
-
}
|
|
18459
|
-
};
|
|
18460
|
-
|
|
18461
|
-
// src/progress.ts
|
|
18462
|
-
function isProgressRequested(ctx) {
|
|
18463
|
-
const token = ctx?.mcpReq?._meta?.progressToken;
|
|
18464
|
-
return token !== void 0 && token !== null && typeof ctx?.mcpReq?.notify === "function";
|
|
18465
|
-
}
|
|
18466
|
-
function createProgressReporter(ctx) {
|
|
18467
|
-
if (!isProgressRequested(ctx)) {
|
|
18468
|
-
return () => {
|
|
18469
|
-
};
|
|
18470
|
-
}
|
|
18471
|
-
const token = ctx?.mcpReq?._meta?.progressToken;
|
|
18472
|
-
const send = ctx?.mcpReq?.notify;
|
|
18473
|
-
const EPSILON = 1e-3;
|
|
18474
|
-
let lastEmitted = -EPSILON;
|
|
18475
|
-
return (message, progress, total) => {
|
|
18476
|
-
let emitted;
|
|
18477
|
-
let emittedTotal;
|
|
18478
|
-
if (progress !== void 0) {
|
|
18479
|
-
emitted = progress > lastEmitted ? progress : lastEmitted + EPSILON;
|
|
18480
|
-
emittedTotal = total !== void 0 && emitted <= total ? total : void 0;
|
|
18481
|
-
} else {
|
|
18482
|
-
emitted = lastEmitted + EPSILON;
|
|
18483
|
-
emittedTotal = void 0;
|
|
18484
|
-
}
|
|
18485
|
-
const params = {
|
|
18486
|
-
progressToken: token,
|
|
18487
|
-
progress: emitted,
|
|
18488
|
-
message
|
|
18489
|
-
};
|
|
18490
|
-
if (emittedTotal !== void 0) params.total = emittedTotal;
|
|
18491
|
-
lastEmitted = emitted;
|
|
18492
|
-
send({ method: "notifications/progress", params }).catch((err) => {
|
|
18493
|
-
log("warn", "Progress notification send failed", {
|
|
18494
|
-
error: err instanceof Error ? err.message : String(err)
|
|
18495
|
-
});
|
|
18496
|
-
});
|
|
18497
|
-
};
|
|
18498
|
-
}
|
|
18499
|
-
|
|
18500
|
-
// src/proxy.ts
|
|
18501
|
-
var DEFERRED_INPUT_SCHEMA = {
|
|
18502
|
-
type: "object",
|
|
18503
|
-
properties: {},
|
|
18504
|
-
additionalProperties: true
|
|
18505
|
-
};
|
|
18506
|
-
function deferredDescription(server, cachedDesc) {
|
|
18507
|
-
const base = cachedDesc?.trim();
|
|
18508
|
-
const suffix = `[yaw-mcp: server "${server.namespace}" not yet connected \u2014 first call activates it]`;
|
|
18509
|
-
return base ? `${base}
|
|
18510
|
-
|
|
18511
|
-
${suffix}` : suffix;
|
|
18512
|
-
}
|
|
18513
|
-
function compareNamespaces(a, b) {
|
|
18514
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
18515
|
-
}
|
|
18516
|
-
function connectionsInOrder(activeConnections) {
|
|
18517
|
-
return [...activeConnections.values()].sort((a, b) => compareNamespaces(a.config.namespace, b.config.namespace));
|
|
18518
|
-
}
|
|
18519
|
-
function serversInOrder(servers) {
|
|
18520
|
-
return [...servers].sort((a, b) => compareNamespaces(a.namespace, b.namespace));
|
|
18521
|
-
}
|
|
18522
|
-
function buildToolList(activeConnections, inactiveWithCache = [], toolFilters, exposure = "full", exposedNamespaces, isDenied) {
|
|
18523
|
-
const tools = [];
|
|
18524
|
-
const seen = /* @__PURE__ */ new Set();
|
|
18525
|
-
for (const meta of Object.values(META_TOOLS)) {
|
|
18526
|
-
if (exposure === "lite" && !LITE_META_TOOL_NAMES.has(meta.name)) continue;
|
|
18527
|
-
tools.push({
|
|
18528
|
-
name: meta.name,
|
|
18529
|
-
description: meta.description,
|
|
18530
|
-
inputSchema: meta.inputSchema,
|
|
18531
|
-
annotations: meta.annotations
|
|
18532
|
-
});
|
|
18533
|
-
seen.add(meta.name);
|
|
18534
|
-
}
|
|
18535
|
-
for (const conn of connectionsInOrder(activeConnections)) {
|
|
18536
|
-
if (exposure !== "full" && !exposedNamespaces?.has(conn.config.namespace)) continue;
|
|
18537
|
-
const filter = toolFilters?.get(conn.config.namespace);
|
|
18538
|
-
for (const tool of conn.tools) {
|
|
18539
|
-
if (filter && !filter.has(tool.name)) continue;
|
|
18540
|
-
if (isDenied?.(tool.namespacedName)) continue;
|
|
18541
|
-
if (seen.has(tool.namespacedName)) continue;
|
|
18542
|
-
tools.push({
|
|
18543
|
-
name: tool.namespacedName,
|
|
18544
|
-
title: tool.title,
|
|
18545
|
-
description: tool.description,
|
|
18546
|
-
inputSchema: tool.inputSchema,
|
|
18547
|
-
outputSchema: tool.outputSchema,
|
|
18548
|
-
annotations: tool.annotations,
|
|
18549
|
-
_meta: tool._meta
|
|
18550
|
-
});
|
|
18551
|
-
seen.add(tool.namespacedName);
|
|
18552
|
-
}
|
|
18553
|
-
}
|
|
18554
|
-
for (const server of serversInOrder(inactiveWithCache)) {
|
|
18555
|
-
if (activeConnections.has(server.namespace)) continue;
|
|
18556
|
-
if (!server.toolCache || server.toolCache.length === 0) continue;
|
|
18557
|
-
if (exposure !== "full") continue;
|
|
18558
|
-
const filter = toolFilters?.get(server.namespace);
|
|
18559
|
-
for (const cached of server.toolCache) {
|
|
18560
|
-
if (filter && !filter.has(cached.name)) continue;
|
|
18561
|
-
const namespacedName = `${server.namespace}_${cached.name}`;
|
|
18562
|
-
if (isDenied?.(namespacedName)) continue;
|
|
18563
|
-
if (seen.has(namespacedName)) continue;
|
|
18564
|
-
tools.push({
|
|
18565
|
-
name: namespacedName,
|
|
18566
|
-
description: deferredDescription(server, cached.description),
|
|
18567
|
-
inputSchema: DEFERRED_INPUT_SCHEMA
|
|
18568
|
-
});
|
|
18569
|
-
seen.add(namespacedName);
|
|
18570
|
-
}
|
|
18571
|
-
}
|
|
18572
|
-
return tools;
|
|
18573
|
-
}
|
|
18574
|
-
function buildToolRoutes(activeConnections, inactiveWithCache = [], quiet = false) {
|
|
18575
|
-
const routes = /* @__PURE__ */ new Map();
|
|
18576
|
-
for (const conn of connectionsInOrder(activeConnections)) {
|
|
18577
|
-
for (const tool of conn.tools) {
|
|
18578
|
-
const existing = routes.get(tool.namespacedName);
|
|
18579
|
-
if (existing && existing.namespace !== conn.config.namespace) {
|
|
18580
|
-
if (!quiet) {
|
|
18581
|
-
log("warn", "Tool route collision; keeping the first upstream, ignoring the later one", {
|
|
18582
|
-
tool: tool.namespacedName,
|
|
18583
|
-
keptNamespace: existing.namespace,
|
|
18584
|
-
ignoredNamespace: conn.config.namespace
|
|
18585
|
-
});
|
|
18586
|
-
}
|
|
18587
|
-
continue;
|
|
18588
|
-
}
|
|
18589
|
-
routes.set(tool.namespacedName, {
|
|
18590
|
-
namespace: conn.config.namespace,
|
|
18591
|
-
originalName: tool.name
|
|
18592
|
-
});
|
|
18817
|
+
routes.set(tool.namespacedName, {
|
|
18818
|
+
namespace: conn.config.namespace,
|
|
18819
|
+
originalName: tool.name
|
|
18820
|
+
});
|
|
18593
18821
|
}
|
|
18594
18822
|
}
|
|
18595
18823
|
for (const server of serversInOrder(inactiveWithCache)) {
|
|
@@ -18844,6 +19072,257 @@ async function routeToolCall(toolName, args, toolRoutes, activeConnections, opti
|
|
|
18844
19072
|
}
|
|
18845
19073
|
}
|
|
18846
19074
|
|
|
19075
|
+
// src/installed-summary.ts
|
|
19076
|
+
var INSTALLED_LINE_MAX_CHARS = 800;
|
|
19077
|
+
var TIERS = [
|
|
19078
|
+
{ words: 4, shadow: true },
|
|
19079
|
+
{ words: 3, shadow: true },
|
|
19080
|
+
{ words: 2, shadow: true },
|
|
19081
|
+
{ words: 1, shadow: true },
|
|
19082
|
+
{ words: 0, shadow: true },
|
|
19083
|
+
{ words: 0, shadow: false }
|
|
19084
|
+
];
|
|
19085
|
+
var FILLER = new Set(
|
|
19086
|
+
"the and for are that this with what which how does from into about can any all some when where you your our its their them they via using use through over also just only more most other get list create update delete search set add remove read write run find fetch query info new edit covering manage management configure execute talk directly provide provides access tool tools server servers mcp assistant assistants model models intelligence development data date demand pulled up-to-date".split(" ")
|
|
19087
|
+
);
|
|
19088
|
+
var CONTROL_CHARS = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
19089
|
+
function serverKeywords(server) {
|
|
19090
|
+
const ns = server.namespace.toLowerCase();
|
|
19091
|
+
const source = server.description ? server.description : [server.name ?? "", ...(server.toolCache ?? []).map((t) => t.name)].join(" ");
|
|
19092
|
+
const out = [];
|
|
19093
|
+
for (const raw of source.replace(CONTROL_CHARS, " ").toLowerCase().split(/[^a-z0-9]+/)) {
|
|
19094
|
+
if (raw.length < 3 || /^[0-9]+$/.test(raw) || FILLER.has(raw) || raw === ns) continue;
|
|
19095
|
+
const singular = raw.endsWith("s") ? raw.slice(0, -1) : raw;
|
|
19096
|
+
if (out.includes(raw) || out.includes(singular) || out.includes(`${raw}s`)) continue;
|
|
19097
|
+
out.push(raw);
|
|
19098
|
+
}
|
|
19099
|
+
return out;
|
|
19100
|
+
}
|
|
19101
|
+
function formatInstalledEntry(server, words = TIERS[0].words, shadow = true) {
|
|
19102
|
+
const keywords = words > 0 ? serverKeywords(server).slice(0, words) : [];
|
|
19103
|
+
const clis = shadow ? resolveShadowedClis(server).map((s) => `\`${s.cli}\``) : [];
|
|
19104
|
+
const parts = [keywords.join(", "), clis.length > 0 ? `over ${clis.join(", ")}` : ""].filter(Boolean);
|
|
19105
|
+
return parts.length > 0 ? `${server.namespace} (${parts.join("; ")})` : server.namespace;
|
|
19106
|
+
}
|
|
19107
|
+
function formatInstalledServers(servers, maxChars = INSTALLED_LINE_MAX_CHARS) {
|
|
19108
|
+
if (servers.length === 0) return null;
|
|
19109
|
+
const sorted = [...servers].sort((a, b) => compareNamespaces(a.namespace, b.namespace));
|
|
19110
|
+
const head = "Installed servers: ";
|
|
19111
|
+
for (const tier of TIERS) {
|
|
19112
|
+
const line2 = `${head}${sorted.map((s) => formatInstalledEntry(s, tier.words, tier.shadow)).join(", ")}.`;
|
|
19113
|
+
if (line2.length <= maxChars) return line2;
|
|
19114
|
+
}
|
|
19115
|
+
const more = (n) => ` +${n} more (mcp_connect_discover lists all).`;
|
|
19116
|
+
let line = head;
|
|
19117
|
+
let shown = 0;
|
|
19118
|
+
for (const server of sorted) {
|
|
19119
|
+
const sep2 = shown === 0 ? "" : ", ";
|
|
19120
|
+
const reserve = more(sorted.length - shown - 1).length;
|
|
19121
|
+
if (line.length + sep2.length + server.namespace.length + reserve > maxChars) break;
|
|
19122
|
+
line += sep2 + server.namespace;
|
|
19123
|
+
shown++;
|
|
19124
|
+
}
|
|
19125
|
+
if (shown === 0) return `${head}${sorted.length} (mcp_connect_discover lists them).`;
|
|
19126
|
+
return line + more(sorted.length - shown);
|
|
19127
|
+
}
|
|
19128
|
+
function withInstalledServers(tools, line, exposure) {
|
|
19129
|
+
if (!line) return tools;
|
|
19130
|
+
const target = exposure === "lite" ? META_TOOLS.findTool.name : META_TOOLS.dispatch.name;
|
|
19131
|
+
return tools.map((t) => t.name === target ? { ...t, description: `${t.description ?? ""} ${line}`.trim() } : t);
|
|
19132
|
+
}
|
|
19133
|
+
|
|
19134
|
+
// src/pack-detect.ts
|
|
19135
|
+
var DEFAULT_MAX_HISTORY = 100;
|
|
19136
|
+
var DEFAULT_MAX_GAP_MS = 12e4;
|
|
19137
|
+
var MIN_NAMESPACES = 2;
|
|
19138
|
+
var MAX_NAMESPACES = 3;
|
|
19139
|
+
var MIN_RECURRENCES = 2;
|
|
19140
|
+
var BURST_SPAN_FACTOR = 5;
|
|
19141
|
+
function packIdFromNamespaces(namespaces) {
|
|
19142
|
+
return Array.from(new Set(namespaces)).sort().join("|");
|
|
19143
|
+
}
|
|
19144
|
+
var PackDetector = class {
|
|
19145
|
+
maxHistory;
|
|
19146
|
+
maxGapMs;
|
|
19147
|
+
history = [];
|
|
19148
|
+
constructor(options = {}) {
|
|
19149
|
+
this.maxHistory = options.maxHistory ?? DEFAULT_MAX_HISTORY;
|
|
19150
|
+
this.maxGapMs = options.maxGapMs ?? DEFAULT_MAX_GAP_MS;
|
|
19151
|
+
}
|
|
19152
|
+
recordCall(namespace, toolName, at) {
|
|
19153
|
+
if (!namespace || !toolName) return;
|
|
19154
|
+
if (typeof at !== "number" || !Number.isFinite(at)) return;
|
|
19155
|
+
this.history.push({ namespace, toolName, at });
|
|
19156
|
+
if (this.history.length > this.maxHistory) {
|
|
19157
|
+
const overflow = this.history.length - this.maxHistory;
|
|
19158
|
+
this.history = this.history.slice(overflow);
|
|
19159
|
+
}
|
|
19160
|
+
}
|
|
19161
|
+
// Walk the history, segmenting it into "bursts" (see segmentBursts for
|
|
19162
|
+
// the three boundaries). Each burst with ≥2 distinct namespaces is a
|
|
19163
|
+
// candidate pack. A pack is returned when the same namespace set
|
|
19164
|
+
// appears in ≥MIN_RECURRENCES bursts.
|
|
19165
|
+
detectChains() {
|
|
19166
|
+
if (this.history.length < 2) return [];
|
|
19167
|
+
const bursts = this.segmentBursts();
|
|
19168
|
+
const packCounts = /* @__PURE__ */ new Map();
|
|
19169
|
+
for (const burst of bursts) {
|
|
19170
|
+
if (burst.namespaces.length < MIN_NAMESPACES) continue;
|
|
19171
|
+
if (burst.namespaces.length > MAX_NAMESPACES) continue;
|
|
19172
|
+
const id = packIdFromNamespaces(burst.namespaces);
|
|
19173
|
+
const prev = packCounts.get(id);
|
|
19174
|
+
if (prev) {
|
|
19175
|
+
prev.frequency += 1;
|
|
19176
|
+
if (burst.lastAt > prev.lastSeenAt) prev.lastSeenAt = burst.lastAt;
|
|
19177
|
+
} else {
|
|
19178
|
+
packCounts.set(id, {
|
|
19179
|
+
namespaces: [...burst.namespaces],
|
|
19180
|
+
frequency: 1,
|
|
19181
|
+
lastSeenAt: burst.lastAt
|
|
19182
|
+
});
|
|
19183
|
+
}
|
|
19184
|
+
}
|
|
19185
|
+
const packs = [];
|
|
19186
|
+
for (const entry of packCounts.values()) {
|
|
19187
|
+
if (entry.frequency >= MIN_RECURRENCES) {
|
|
19188
|
+
packs.push({
|
|
19189
|
+
namespaces: entry.namespaces,
|
|
19190
|
+
frequency: entry.frequency,
|
|
19191
|
+
lastSeenAt: entry.lastSeenAt
|
|
19192
|
+
});
|
|
19193
|
+
}
|
|
19194
|
+
}
|
|
19195
|
+
return packs;
|
|
19196
|
+
}
|
|
19197
|
+
// Segment the call history into bursts. A new burst starts whenever:
|
|
19198
|
+
// 1. the gap to the previous call exceeds maxGapMs (idle boundary);
|
|
19199
|
+
// 2. the burst has already spanned maxGapMs * BURST_SPAN_FACTOR
|
|
19200
|
+
// (span boundary -- see the constant for why a continuous session
|
|
19201
|
+
// must be sliced for recurrence to be countable); or
|
|
19202
|
+
// 3. the call would add a namespace past MAX_NAMESPACES (overflow
|
|
19203
|
+
// boundary). detectChains drops an over-wide burst entirely, so
|
|
19204
|
+
// without this cut a single visit to a 4th namespace poisoned the
|
|
19205
|
+
// whole burst and the recurring trio inside it was never counted.
|
|
19206
|
+
// Cutting at the overflow keeps each burst representable as a
|
|
19207
|
+
// pack; a wider rotation surfaces as its recurring 3-subsets, the
|
|
19208
|
+
// best answer the MAX_NAMESPACES pack-size cap can express. SLOWLY,
|
|
19209
|
+
// though: the cuts walk the rotation, so each 3-subset recurs only
|
|
19210
|
+
// once per full pass over it. A strict a,b,c,d loop segments as
|
|
19211
|
+
// [a,b,c] [d,a,b] [c,d,a] [b,c,d] [a,b,c] ..., and {a,b,c} reaches
|
|
19212
|
+
// MIN_RECURRENCES at the 15th call -- all of which must land inside
|
|
19213
|
+
// one span window and one maxGapMs cadence.
|
|
19214
|
+
// Within a burst, each namespace is recorded only once
|
|
19215
|
+
// (order-of-first-appearance); the "last seen" timestamp tracks the
|
|
19216
|
+
// most recent call in the burst so recency ranking is truthful even
|
|
19217
|
+
// when the burst has many calls.
|
|
19218
|
+
segmentBursts() {
|
|
19219
|
+
const bursts = [];
|
|
19220
|
+
const maxBurstSpanMs = this.maxGapMs * BURST_SPAN_FACTOR;
|
|
19221
|
+
let current = null;
|
|
19222
|
+
let prevAt = 0;
|
|
19223
|
+
for (const call of this.history) {
|
|
19224
|
+
const gapExceeded = call.at - prevAt > this.maxGapMs;
|
|
19225
|
+
const spanExceeded = current !== null && call.at - current.startAt > maxBurstSpanMs;
|
|
19226
|
+
const wentBackwards = current !== null && call.at < prevAt;
|
|
19227
|
+
const wouldOverflow = current !== null && current.namespaces.length >= MAX_NAMESPACES && !current.namespaces.includes(call.namespace);
|
|
19228
|
+
if (!current || gapExceeded || spanExceeded || wentBackwards || wouldOverflow) {
|
|
19229
|
+
current = { namespaces: [call.namespace], startAt: call.at, lastAt: call.at };
|
|
19230
|
+
bursts.push(current);
|
|
19231
|
+
} else {
|
|
19232
|
+
if (!current.namespaces.includes(call.namespace)) {
|
|
19233
|
+
current.namespaces.push(call.namespace);
|
|
19234
|
+
}
|
|
19235
|
+
current.lastAt = call.at;
|
|
19236
|
+
}
|
|
19237
|
+
prevAt = call.at;
|
|
19238
|
+
}
|
|
19239
|
+
return bursts;
|
|
19240
|
+
}
|
|
19241
|
+
// Exposed for tests.
|
|
19242
|
+
getHistory() {
|
|
19243
|
+
return this.history;
|
|
19244
|
+
}
|
|
19245
|
+
reset() {
|
|
19246
|
+
this.history = [];
|
|
19247
|
+
}
|
|
19248
|
+
// Return a defensive copy of history for persistence. Each entry is a
|
|
19249
|
+
// fresh object, safe to JSON.stringify without worrying about later
|
|
19250
|
+
// mutations to the detector's internal array.
|
|
19251
|
+
exportSnapshot() {
|
|
19252
|
+
return this.history.map((c) => ({ namespace: c.namespace, toolName: c.toolName, at: c.at }));
|
|
19253
|
+
}
|
|
19254
|
+
// Replace in-memory history with the given snapshot. Respects the
|
|
19255
|
+
// configured maxHistory cap — if the snapshot exceeds it, the oldest
|
|
19256
|
+
// entries are dropped, matching the cap behavior of recordCall.
|
|
19257
|
+
//
|
|
19258
|
+
// Entries are SORTED by `at` after cleaning. segmentBursts reads the history
|
|
19259
|
+
// as a time-ordered stream (see the boundary comparisons there), and the
|
|
19260
|
+
// snapshot comes off disk where a hand-edited, merged or torn file can carry
|
|
19261
|
+
// entries out of order; an out-of-order run would otherwise be segmented as
|
|
19262
|
+
// one welded burst plus spurious boundaries. Sorting is stable, so equal
|
|
19263
|
+
// timestamps keep their recorded order.
|
|
19264
|
+
//
|
|
19265
|
+
// `at` is validated as a finite number, not just present: the snapshot
|
|
19266
|
+
// comes off disk (persistence.ts) where a hand-edited or torn file can
|
|
19267
|
+
// carry null / "12345" / NaN. segmentBursts compares `call.at - prevAt >
|
|
19268
|
+
// maxGapMs`, and every comparison against NaN is false, so a single NaN
|
|
19269
|
+
// timestamp silently welds the whole history into one giant burst and
|
|
19270
|
+
// manufactures packs that never happened.
|
|
19271
|
+
loadSnapshot(snapshot) {
|
|
19272
|
+
const clean = [];
|
|
19273
|
+
for (const c of snapshot) {
|
|
19274
|
+
if (!c?.namespace || !c.toolName) continue;
|
|
19275
|
+
if (typeof c.at !== "number" || !Number.isFinite(c.at)) continue;
|
|
19276
|
+
clean.push({ namespace: c.namespace, toolName: c.toolName, at: c.at });
|
|
19277
|
+
}
|
|
19278
|
+
clean.sort((a, b) => a.at - b.at);
|
|
19279
|
+
if (clean.length > this.maxHistory) {
|
|
19280
|
+
this.history = clean.slice(clean.length - this.maxHistory);
|
|
19281
|
+
} else {
|
|
19282
|
+
this.history = clean;
|
|
19283
|
+
}
|
|
19284
|
+
}
|
|
19285
|
+
};
|
|
19286
|
+
|
|
19287
|
+
// src/progress.ts
|
|
19288
|
+
function isProgressRequested(ctx) {
|
|
19289
|
+
const token = ctx?.mcpReq?._meta?.progressToken;
|
|
19290
|
+
return token !== void 0 && token !== null && typeof ctx?.mcpReq?.notify === "function";
|
|
19291
|
+
}
|
|
19292
|
+
function createProgressReporter(ctx) {
|
|
19293
|
+
if (!isProgressRequested(ctx)) {
|
|
19294
|
+
return () => {
|
|
19295
|
+
};
|
|
19296
|
+
}
|
|
19297
|
+
const token = ctx?.mcpReq?._meta?.progressToken;
|
|
19298
|
+
const send = ctx?.mcpReq?.notify;
|
|
19299
|
+
const EPSILON = 1e-3;
|
|
19300
|
+
let lastEmitted = -EPSILON;
|
|
19301
|
+
return (message, progress, total) => {
|
|
19302
|
+
let emitted;
|
|
19303
|
+
let emittedTotal;
|
|
19304
|
+
if (progress !== void 0) {
|
|
19305
|
+
emitted = progress > lastEmitted ? progress : lastEmitted + EPSILON;
|
|
19306
|
+
emittedTotal = total !== void 0 && emitted <= total ? total : void 0;
|
|
19307
|
+
} else {
|
|
19308
|
+
emitted = lastEmitted + EPSILON;
|
|
19309
|
+
emittedTotal = void 0;
|
|
19310
|
+
}
|
|
19311
|
+
const params = {
|
|
19312
|
+
progressToken: token,
|
|
19313
|
+
progress: emitted,
|
|
19314
|
+
message
|
|
19315
|
+
};
|
|
19316
|
+
if (emittedTotal !== void 0) params.total = emittedTotal;
|
|
19317
|
+
lastEmitted = emitted;
|
|
19318
|
+
send({ method: "notifications/progress", params }).catch((err) => {
|
|
19319
|
+
log("warn", "Progress notification send failed", {
|
|
19320
|
+
error: err instanceof Error ? err.message : String(err)
|
|
19321
|
+
});
|
|
19322
|
+
});
|
|
19323
|
+
};
|
|
19324
|
+
}
|
|
19325
|
+
|
|
18847
19326
|
// src/prune.ts
|
|
18848
19327
|
var MIN_SAVINGS_RATIO = 0.02;
|
|
18849
19328
|
var MAX_PRUNE_CHARS = 2e6;
|
|
@@ -19799,10 +20278,10 @@ function evaluateServerCap(namespace, loaded, cap, context = {}) {
|
|
|
19799
20278
|
if (b.idleCount !== a.idleCount) return b.idleCount - a.idleCount;
|
|
19800
20279
|
return a.namespace.localeCompare(b.namespace);
|
|
19801
20280
|
});
|
|
19802
|
-
const
|
|
20281
|
+
const list2 = sorted.map(describeSlot).join(", ");
|
|
19803
20282
|
return {
|
|
19804
20283
|
allow: false,
|
|
19805
|
-
message: `Cannot load "${namespace}" \u2014 already at the ${cap}-server concurrent cap. Loaded: ${
|
|
20284
|
+
message: `Cannot load "${namespace}" \u2014 already at the ${cap}-server concurrent cap. Loaded: ${list2}. Free a slot with mcp_connect_deactivate, or use mcp_connect_read_tool to inspect one tool without loading its server. Ops can change the limit via YAW_MCP_SERVER_CAP.`
|
|
19806
20285
|
};
|
|
19807
20286
|
}
|
|
19808
20287
|
function describeSlot(s) {
|
|
@@ -19818,9 +20297,9 @@ function tokenRefusal(namespace, loaded, candidateTokens, loadedTokens, tokenCap
|
|
|
19818
20297
|
if (bt !== at) return bt - at;
|
|
19819
20298
|
return a.namespace.localeCompare(b.namespace);
|
|
19820
20299
|
});
|
|
19821
|
-
const
|
|
20300
|
+
const list2 = sorted.map(describeSlot).join(", ");
|
|
19822
20301
|
const over = loadedTokens + candidateTokens - tokenCap;
|
|
19823
|
-
return `Cannot load "${namespace}" \u2014 its ~${candidateTokens} tokens of tools would put the loaded surface at ~${loadedTokens + candidateTokens}, over the ~${tokenCap}-token ceiling by ~${over}. Loaded, most expensive first: ${
|
|
20302
|
+
return `Cannot load "${namespace}" \u2014 its ~${candidateTokens} tokens of tools would put the loaded surface at ~${loadedTokens + candidateTokens}, over the ~${tokenCap}-token ceiling by ~${over}. Loaded, most expensive first: ${list2}. Free the budget with mcp_connect_deactivate, or use mcp_connect_read_tool to inspect one tool without loading its server. Ops can change the limit via YAW_MCP_TOOL_TOKEN_CAP.`;
|
|
19824
20303
|
}
|
|
19825
20304
|
|
|
19826
20305
|
// src/server.ts
|
|
@@ -19916,6 +20395,116 @@ function resolveIdleThreshold() {
|
|
|
19916
20395
|
function isAutoActivateEnabled() {
|
|
19917
20396
|
return !isFeatureDisabled("YAW_MCP_AUTO_ACTIVATE");
|
|
19918
20397
|
}
|
|
20398
|
+
var AUTO_ACTIVATE_MIN_SCORE_BM25 = 1;
|
|
20399
|
+
var AUTO_ACTIVATE_MARGIN_BM25 = 1.3;
|
|
20400
|
+
var AUTO_ACTIVATE_MIN_COVERAGE = 0.38;
|
|
20401
|
+
var AUTO_ACTIVATE_COVERAGE_MIN_SERVERS = 5;
|
|
20402
|
+
function pickAutoWarmWinner(ranked) {
|
|
20403
|
+
const top = ranked[0];
|
|
20404
|
+
const second = ranked[1];
|
|
20405
|
+
const topWinsDecisively = top !== void 0 && top.score >= AUTO_ACTIVATE_MIN_SCORE_BM25 && (top.coverage === void 0 || top.coverage >= AUTO_ACTIVATE_MIN_COVERAGE) && (second === void 0 || top.score / (second.score || 1e-6) >= AUTO_ACTIVATE_MARGIN_BM25);
|
|
20406
|
+
return topWinsDecisively ? top : void 0;
|
|
20407
|
+
}
|
|
20408
|
+
var DISPATCH_MAX_FALLBACKS = 2;
|
|
20409
|
+
function runnerUpCanReplace(failed, next) {
|
|
20410
|
+
if (next.score * AUTO_ACTIVATE_MARGIN_BM25 < failed.score) return false;
|
|
20411
|
+
return !coverageIsLow(failed, failed.score / (next.score || 1e-6));
|
|
20412
|
+
}
|
|
20413
|
+
var CONFIDENCE_NOTE_RUNNERS_UP = 2;
|
|
20414
|
+
var DISPATCH_LOW_COVERAGE_MARGIN = 2;
|
|
20415
|
+
function coverageIsLow(pick, lead) {
|
|
20416
|
+
return pick.coverage !== void 0 && pick.coverage < AUTO_ACTIVATE_MIN_COVERAGE && ((pick.matched ?? 0) <= 1 || lead < DISPATCH_LOW_COVERAGE_MARGIN);
|
|
20417
|
+
}
|
|
20418
|
+
function dispatchConfidenceNote(ranked, loaded, loadedSet, opts) {
|
|
20419
|
+
const pick = ranked.find((r) => r.namespace === loaded);
|
|
20420
|
+
if (!pick) return void 0;
|
|
20421
|
+
const others = ranked.filter((r) => !loadedSet.has(r.namespace) && r.score > 0);
|
|
20422
|
+
const best = others[0];
|
|
20423
|
+
const reasons = [];
|
|
20424
|
+
const lead = best === void 0 ? Number.POSITIVE_INFINITY : pick.score / (best.score || 1e-6);
|
|
20425
|
+
if (!opts.sampled && lead < AUTO_ACTIVATE_MARGIN_BM25) {
|
|
20426
|
+
reasons.push(
|
|
20427
|
+
`close call (${best.namespace} scored ${best.score.toFixed(2)} vs ${pick.score.toFixed(2)}${opts.noSampling ? "; this client cannot be asked to break the tie" : ""})`
|
|
20428
|
+
);
|
|
20429
|
+
}
|
|
20430
|
+
if (coverageIsLow(pick, lead)) {
|
|
20431
|
+
reasons.push(
|
|
20432
|
+
pick.contentTerms !== void 0 && pick.contentTerms > 0 ? `${loaded} matches ${pick.matched} of the request's ${pick.contentTerms} content words` : `the request has no content words to match`
|
|
20433
|
+
);
|
|
20434
|
+
}
|
|
20435
|
+
if (reasons.length === 0) return void 0;
|
|
20436
|
+
const runners = others.slice(0, CONFIDENCE_NOTE_RUNNERS_UP).map((r) => `${r.namespace} (${r.score.toFixed(2)})`).join(", ");
|
|
20437
|
+
return `Low confidence: ${reasons.join("; ")}.${runners ? ` Runners-up: ${runners}.` : ""} If ${loaded} does not fit, mcp_connect_activate a runner-up or dispatch a more specific intent; if the request needs no tool, answer it directly.`;
|
|
20438
|
+
}
|
|
20439
|
+
var DISPATCH_TOOL_HINTS = 3;
|
|
20440
|
+
var SIGNATURE_MAX_ARGS = 8;
|
|
20441
|
+
function isPlainObject2(v) {
|
|
20442
|
+
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
20443
|
+
}
|
|
20444
|
+
function schemaTypeLabel(prop) {
|
|
20445
|
+
if (!isPlainObject2(prop)) return "any";
|
|
20446
|
+
const t = prop.type;
|
|
20447
|
+
if (typeof t === "string") {
|
|
20448
|
+
if (t === "array" && isPlainObject2(prop.items) && typeof prop.items.type === "string")
|
|
20449
|
+
return `${prop.items.type}[]`;
|
|
20450
|
+
return t;
|
|
20451
|
+
}
|
|
20452
|
+
if (Array.isArray(t)) {
|
|
20453
|
+
const types = t.filter((x) => typeof x === "string" && x !== "null");
|
|
20454
|
+
if (types.length > 0) return types.join("|");
|
|
20455
|
+
}
|
|
20456
|
+
const union = Array.isArray(prop.anyOf) ? prop.anyOf : Array.isArray(prop.oneOf) ? prop.oneOf : void 0;
|
|
20457
|
+
if (union) {
|
|
20458
|
+
const labels = [...new Set(union.map(schemaTypeLabel).filter((l) => l !== "null"))];
|
|
20459
|
+
if (labels.length > 0) return labels.join("|");
|
|
20460
|
+
}
|
|
20461
|
+
if (Array.isArray(prop.enum)) return "enum";
|
|
20462
|
+
return "any";
|
|
20463
|
+
}
|
|
20464
|
+
function formatToolSignature(name, inputSchema, maxArgs = SIGNATURE_MAX_ARGS) {
|
|
20465
|
+
const schema = isPlainObject2(inputSchema) ? inputSchema : {};
|
|
20466
|
+
const props = isPlainObject2(schema.properties) ? schema.properties : {};
|
|
20467
|
+
const required = Array.isArray(schema.required) ? [...new Set(schema.required.filter((k) => typeof k === "string"))] : [];
|
|
20468
|
+
const optional = Object.keys(props).filter((k) => !required.includes(k));
|
|
20469
|
+
const args = [
|
|
20470
|
+
...required.map((k) => `${k}: ${schemaTypeLabel(props[k])}`),
|
|
20471
|
+
...optional.map((k) => `${k}?: ${schemaTypeLabel(props[k])}`)
|
|
20472
|
+
];
|
|
20473
|
+
const shown = args.slice(0, maxArgs);
|
|
20474
|
+
if (args.length > shown.length) shown.push(`+${args.length - shown.length} more`);
|
|
20475
|
+
return `${name}(${shown.join(", ")})`;
|
|
20476
|
+
}
|
|
20477
|
+
var SCHEMA_COMPOSITION_KEYS = [
|
|
20478
|
+
"allOf",
|
|
20479
|
+
"anyOf",
|
|
20480
|
+
"oneOf",
|
|
20481
|
+
"$ref",
|
|
20482
|
+
"if",
|
|
20483
|
+
"dependencies",
|
|
20484
|
+
"dependentSchemas",
|
|
20485
|
+
"patternProperties",
|
|
20486
|
+
"unevaluatedProperties"
|
|
20487
|
+
];
|
|
20488
|
+
function checkToolArgs(inputSchema, args) {
|
|
20489
|
+
if (!isPlainObject2(inputSchema)) return null;
|
|
20490
|
+
const props = isPlainObject2(inputSchema.properties) ? inputSchema.properties : void 0;
|
|
20491
|
+
const required = Array.isArray(inputSchema.required) ? inputSchema.required.filter((k) => typeof k === "string") : [];
|
|
20492
|
+
const has = (k) => Object.hasOwn(args, k);
|
|
20493
|
+
const missing = required.filter((k) => !has(k));
|
|
20494
|
+
const additional = inputSchema.additionalProperties;
|
|
20495
|
+
const listsKeys = props !== void 0 && Object.keys(props).length > 0 && (additional === void 0 || additional === false) && !SCHEMA_COMPOSITION_KEYS.some((k) => k in inputSchema);
|
|
20496
|
+
const unknownKeys = listsKeys ? Object.keys(args).filter((k) => !Object.hasOwn(props, k)) : [];
|
|
20497
|
+
if (missing.length === 0 && (additional !== false || unknownKeys.length === 0)) return null;
|
|
20498
|
+
const unsupplied = Object.keys(props ?? {}).filter((k) => !has(k));
|
|
20499
|
+
const squash = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
20500
|
+
const unknown = unknownKeys.map((key) => {
|
|
20501
|
+
const sameWord = unsupplied.find((p) => squash(p) === squash(key));
|
|
20502
|
+
const onlyPair = missing.length === 1 && unknownKeys.length === 1 ? missing[0] : void 0;
|
|
20503
|
+
const suggestion = sameWord ?? onlyPair ?? closestNames(key, unsupplied, 1)[0];
|
|
20504
|
+
return suggestion === void 0 ? { key } : { key, suggestion };
|
|
20505
|
+
});
|
|
20506
|
+
return { missing, unknown };
|
|
20507
|
+
}
|
|
19919
20508
|
var ROUTING_FAULT_TOOL_GONE = "no longer available";
|
|
19920
20509
|
var ROUTING_FAULT_RECONNECT_FAILED = "auto-reconnect failed";
|
|
19921
20510
|
var ROUTING_FAULT_LOAD_FAILED = "could not be loaded on first call";
|
|
@@ -20400,7 +20989,7 @@ var ConnectServer = class _ConnectServer {
|
|
|
20400
20989
|
* initialize handshake completes; see beginSession for why it waits. */
|
|
20401
20990
|
buildServer(era, supportedProtocolVersions) {
|
|
20402
20991
|
const s = new Server(
|
|
20403
|
-
{ name: "yaw-mcp", version: true ? "1.1.
|
|
20992
|
+
{ name: "yaw-mcp", version: true ? "1.1.8" : "dev" },
|
|
20404
20993
|
{
|
|
20405
20994
|
capabilities: {
|
|
20406
20995
|
tools: { listChanged: true },
|
|
@@ -20665,20 +21254,21 @@ var ConnectServer = class _ConnectServer {
|
|
|
20665
21254
|
};
|
|
20666
21255
|
handle("tools/list", async () => {
|
|
20667
21256
|
await this.ready;
|
|
20668
|
-
|
|
20669
|
-
|
|
20670
|
-
|
|
20671
|
-
|
|
20672
|
-
|
|
20673
|
-
|
|
20674
|
-
|
|
20675
|
-
|
|
20676
|
-
|
|
20677
|
-
|
|
20678
|
-
|
|
20679
|
-
|
|
20680
|
-
|
|
20681
|
-
|
|
21257
|
+
const exposure = this.currentExposure();
|
|
21258
|
+
const tools = buildToolList(
|
|
21259
|
+
this.connections,
|
|
21260
|
+
this.getDeferredServers(),
|
|
21261
|
+
this.toolFilters,
|
|
21262
|
+
exposure,
|
|
21263
|
+
this.sessionActivated,
|
|
21264
|
+
// Hidden here, refused at the gate, but still ROUTED: dropping the
|
|
21265
|
+
// route instead would make a call by name return `Unknown tool`,
|
|
21266
|
+
// which reads as a typo and sends the model hunting for a name that
|
|
21267
|
+
// is right there.
|
|
21268
|
+
(wireName) => this.isToolDenied(wireName)
|
|
21269
|
+
);
|
|
21270
|
+
const installed = formatInstalledServers(this.getProfiledActiveServers());
|
|
21271
|
+
return { tools: withInstalledServers(tools, installed, exposure) };
|
|
20682
21272
|
});
|
|
20683
21273
|
handle("tools/call", async (request2, ctx) => {
|
|
20684
21274
|
await this.ready;
|
|
@@ -20877,21 +21467,42 @@ var ConnectServer = class _ConnectServer {
|
|
|
20877
21467
|
* where the server has one, a tool that needs no arguments (read-only
|
|
20878
21468
|
* first), so `args: {}` runs as written. When every tool needs arguments
|
|
20879
21469
|
* the line says to fill them in rather than show a call that would fail. */
|
|
20880
|
-
execHintForNonRelistingClient(loaded) {
|
|
21470
|
+
execHintForNonRelistingClient(loaded, preferred) {
|
|
20881
21471
|
if (clientRelistsTools(this.clientSession().clientInfo)) return null;
|
|
21472
|
+
const example = this.execExample(loaded, preferred);
|
|
21473
|
+
if (example === null) return null;
|
|
21474
|
+
return `This client keeps the tool list it read at startup, so the tools just loaded are not in it and a direct call to one fails. Call them through mcp_connect_exec instead, e.g. ${example.call}${example.fill}`;
|
|
21475
|
+
}
|
|
21476
|
+
/** A ready-made exec call for a load reply: `preferred` (a namespaced
|
|
21477
|
+
* name) when it is a served tool of a loaded namespace, else a served --
|
|
21478
|
+
* not shadowed -- tool of the first namespace that loaded, preferring one
|
|
21479
|
+
* that needs no arguments (read-only first), so `args: {}` runs as
|
|
21480
|
+
* written. When the example needs arguments, `fill` says to supply them
|
|
21481
|
+
* rather than show a call that would fail. */
|
|
21482
|
+
execExample(loaded, preferred) {
|
|
20882
21483
|
const needsNoArgs = (t) => {
|
|
20883
21484
|
const required = t.inputSchema?.required;
|
|
20884
21485
|
return !Array.isArray(required) || required.length === 0;
|
|
20885
21486
|
};
|
|
21487
|
+
const render2 = (example) => ({
|
|
21488
|
+
call: JSON.stringify({ steps: [{ tool: example.namespacedName, args: {} }] }),
|
|
21489
|
+
fill: needsNoArgs(example) ? "" : ` (with the tool's own arguments in "args"; mcp_connect_read_tool shows a tool's arguments)`
|
|
21490
|
+
});
|
|
21491
|
+
if (preferred !== void 0) {
|
|
21492
|
+
for (const ns of loaded) {
|
|
21493
|
+
const conn = this.connections.get(ns);
|
|
21494
|
+
if (!conn) continue;
|
|
21495
|
+
const hit = this.splitShadowedTools(ns, conn.tools).served.find((t) => t.namespacedName === preferred);
|
|
21496
|
+
if (hit) return render2(hit);
|
|
21497
|
+
}
|
|
21498
|
+
}
|
|
20886
21499
|
for (const ns of loaded) {
|
|
20887
21500
|
const conn = this.connections.get(ns);
|
|
20888
21501
|
if (!conn) continue;
|
|
20889
21502
|
const served = this.splitShadowedTools(ns, conn.tools).served;
|
|
20890
21503
|
const example = served.find((t) => needsNoArgs(t) && t.annotations?.readOnlyHint === true) ?? served.find(needsNoArgs) ?? served[0];
|
|
20891
21504
|
if (example === void 0) continue;
|
|
20892
|
-
|
|
20893
|
-
const fill = needsNoArgs(example) ? "" : ` (with the tool's own arguments in "args"; mcp_connect_read_tool shows a tool's arguments)`;
|
|
20894
|
-
return `This client keeps the tool list it read at startup, so the tools just loaded are not in it and a direct call to one fails. Call them through mcp_connect_exec instead, e.g. ${call}${fill}`;
|
|
21505
|
+
return render2(example);
|
|
20895
21506
|
}
|
|
20896
21507
|
return null;
|
|
20897
21508
|
}
|
|
@@ -22090,28 +22701,85 @@ var ConnectServer = class _ConnectServer {
|
|
|
22090
22701
|
// same server. mergeToolCache is idempotent, so callers that already pass a
|
|
22091
22702
|
// merged server (every current one does) pay one small clone and nothing
|
|
22092
22703
|
// else.
|
|
22704
|
+
//
|
|
22705
|
+
// Only when there is no real list at all -- no connection, no learned
|
|
22706
|
+
// entry (an EMPTY learned list counts: the server was spawned and offered
|
|
22707
|
+
// nothing), no non-empty curated list -- does it fall back to the bundled
|
|
22708
|
+
// list fallback-tools.ts keeps for a few well-known servers, matched by
|
|
22709
|
+
// the image or binary the entry launches. That fallback lives here and
|
|
22710
|
+
// nowhere else: it feeds ranking (dispatch, discover, find_tool) but never
|
|
22711
|
+
// hasKnownTools, getDeferredServers or a route, so pre-warm keeps trying to
|
|
22712
|
+
// learn the real list and no call is ever built from the bundled one.
|
|
22093
22713
|
rankableFor(server) {
|
|
22094
|
-
const connection = this.connections.get(server.namespace);
|
|
22095
|
-
const liveTools = connection?.tools.map((t) => ({ name: t.name, description: t.description }));
|
|
22096
22714
|
return {
|
|
22097
22715
|
namespace: server.namespace,
|
|
22098
22716
|
name: server.name,
|
|
22099
22717
|
description: server.description,
|
|
22100
|
-
tools:
|
|
22718
|
+
tools: this.rankableTools(server).tools
|
|
22101
22719
|
};
|
|
22102
22720
|
}
|
|
22721
|
+
// The tool list rankableFor ranks a server on, and where it came from:
|
|
22722
|
+
// "live" (connected), "known" (learned or curated -- possibly an empty
|
|
22723
|
+
// learned list), "bundled" (fallback-tools.ts, never confirmed on this
|
|
22724
|
+
// machine) or "none" (nothing at all; the server ranks on its name and
|
|
22725
|
+
// description only, and find_tool cannot see it).
|
|
22726
|
+
rankableTools(server) {
|
|
22727
|
+
const connection = this.connections.get(server.namespace);
|
|
22728
|
+
if (connection) {
|
|
22729
|
+
return { tools: connection.tools.map((t) => ({ name: t.name, description: t.description })), source: "live" };
|
|
22730
|
+
}
|
|
22731
|
+
const merged = this.mergeToolCache(server).toolCache;
|
|
22732
|
+
if (merged && merged.length > 0 || this.toolCache.has(server.namespace)) {
|
|
22733
|
+
return { tools: merged ?? [], source: "known" };
|
|
22734
|
+
}
|
|
22735
|
+
const bundled = fallbackToolsFor(server);
|
|
22736
|
+
if (bundled) return { tools: [...bundled], source: "bundled" };
|
|
22737
|
+
return { tools: merged ?? [], source: "none" };
|
|
22738
|
+
}
|
|
22103
22739
|
// BM25 shortlist cap — wider than the budget so downstream re-sorts
|
|
22104
22740
|
// (health penalty, learning boost, sampling tiebreak) have room to
|
|
22105
22741
|
// promote a server BM25 ranked below the head of the list.
|
|
22106
22742
|
static BM25_TOP_K = 25;
|
|
22107
|
-
// Local BM25 ranking over the profiled active servers
|
|
22108
|
-
//
|
|
22109
|
-
//
|
|
22743
|
+
// Local BM25 ranking over the profiled active servers, each entry carrying
|
|
22744
|
+
// its queryCoverage for the same query (same RankableServer views, so the
|
|
22745
|
+
// same cached index) once there are AUTO_ACTIVATE_COVERAGE_MIN_SERVERS of
|
|
22746
|
+
// them. Raw: routingCandidates applies the health and
|
|
22747
|
+
// learning multipliers on top.
|
|
22110
22748
|
async rankIntentCandidates(context, servers) {
|
|
22111
22749
|
const bm25Input = servers.map((s) => this.rankableFor(s));
|
|
22112
22750
|
const bm25 = rankServers(context, bm25Input);
|
|
22113
22751
|
if (bm25.length === 0) return [];
|
|
22114
|
-
|
|
22752
|
+
const top = bm25.slice(0, _ConnectServer.BM25_TOP_K);
|
|
22753
|
+
if (bm25Input.length < AUTO_ACTIVATE_COVERAGE_MIN_SERVERS) {
|
|
22754
|
+
return top.map((r) => ({ namespace: r.namespace, score: r.score }));
|
|
22755
|
+
}
|
|
22756
|
+
const coverage = new Map(queryCoverage(context, bm25Input).map((c) => [c.namespace, c]));
|
|
22757
|
+
return top.map((r) => {
|
|
22758
|
+
const c = coverage.get(r.namespace);
|
|
22759
|
+
return {
|
|
22760
|
+
namespace: r.namespace,
|
|
22761
|
+
score: r.score,
|
|
22762
|
+
coverage: c?.coverage ?? 0,
|
|
22763
|
+
matched: c?.matched ?? 0,
|
|
22764
|
+
contentTerms: c?.contentTerms ?? 0
|
|
22765
|
+
};
|
|
22766
|
+
});
|
|
22767
|
+
}
|
|
22768
|
+
// The ranking both routing DECISIONS use -- dispatch's pick and discover's
|
|
22769
|
+
// auto-warm -- so the two choose the same server for the same intent:
|
|
22770
|
+
// rankIntentCandidates' BM25 score times the health penalty (recent
|
|
22771
|
+
// activation failures and high error rates shrink it, so routing prefers
|
|
22772
|
+
// servers that work when several match; healthFactor never exceeds 1) times
|
|
22773
|
+
// the learning boost, re-sorted. Coverage is passed through untouched.
|
|
22774
|
+
// discover's rendered listing and its `(relevance: X)` numbers stay raw
|
|
22775
|
+
// BM25 (buildDiscoverOutput): that body is memoized under a key that does
|
|
22776
|
+
// not cover health or learning state.
|
|
22777
|
+
async routingCandidates(context, servers) {
|
|
22778
|
+
const raw = await this.rankIntentCandidates(context, servers);
|
|
22779
|
+
return raw.map((r) => ({
|
|
22780
|
+
...r,
|
|
22781
|
+
score: r.score * healthFactor(this.connections.get(r.namespace)?.health, this.activationFailures.get(r.namespace)) * this.learning.boostFactor(r.namespace)
|
|
22782
|
+
})).sort((a, b) => b.score - a.score);
|
|
22115
22783
|
}
|
|
22116
22784
|
// Auto-warm confidence gate — applied to discover(context) so a single
|
|
22117
22785
|
// clearly-winning server gets activated without the LLM needing to
|
|
@@ -22119,13 +22787,9 @@ var ConnectServer = class _ConnectServer {
|
|
|
22119
22787
|
// YAW_MCP_AUTO_ACTIVATE=0 if it causes surprise. The env read lives in
|
|
22120
22788
|
// the module-level isAutoActivateEnabled() (re-read per call) rather
|
|
22121
22789
|
// than a static initializer, which would latch the value at import.
|
|
22122
|
-
//
|
|
22123
|
-
//
|
|
22124
|
-
//
|
|
22125
|
-
// positive numbers. Tuned by intuition; revisit when we have real
|
|
22126
|
-
// usage data.
|
|
22127
|
-
static AUTO_ACTIVATE_MIN_SCORE_BM25 = 1;
|
|
22128
|
-
static AUTO_ACTIVATE_MARGIN_BM25 = 1.3;
|
|
22790
|
+
// The score floor, coverage floor and runner-up margin live in the
|
|
22791
|
+
// module-level pickAutoWarmWinner (AUTO_ACTIVATE_MIN_SCORE_BM25 /
|
|
22792
|
+
// _MIN_COVERAGE / _MARGIN_BM25).
|
|
22129
22793
|
// Below this installed-server count, discover() appends a one-line
|
|
22130
22794
|
// marketplace pointer so sparse-config users see where to add more.
|
|
22131
22795
|
// At or above the threshold we stay silent — power users already know
|
|
@@ -22200,14 +22864,10 @@ var ConnectServer = class _ConnectServer {
|
|
|
22200
22864
|
if (!context || !isAutoActivateEnabled()) return this.handleDiscover(context, focusNamespace);
|
|
22201
22865
|
const activeServers = this.getProfiledActiveServers();
|
|
22202
22866
|
if (activeServers.length === 0) return this.handleDiscover(context, focusNamespace);
|
|
22203
|
-
const ranked = await this.
|
|
22867
|
+
const ranked = await this.routingCandidates(context, activeServers);
|
|
22204
22868
|
if (ranked.length === 0) return this.handleDiscover(context, focusNamespace);
|
|
22205
|
-
const top = ranked
|
|
22206
|
-
|
|
22207
|
-
const minScore = _ConnectServer.AUTO_ACTIVATE_MIN_SCORE_BM25;
|
|
22208
|
-
const margin = _ConnectServer.AUTO_ACTIVATE_MARGIN_BM25;
|
|
22209
|
-
const topWinsDecisively = top !== void 0 && top.score >= minScore && (second === void 0 || top.score / (second.score || 1e-6) >= margin);
|
|
22210
|
-
if (!topWinsDecisively || !top) return this.handleDiscover(context, focusNamespace);
|
|
22869
|
+
const top = pickAutoWarmWinner(ranked);
|
|
22870
|
+
if (!top) return this.handleDiscover(context, focusNamespace);
|
|
22211
22871
|
const existing = this.connections.get(top.namespace);
|
|
22212
22872
|
if (existing && existing.status === "connected") {
|
|
22213
22873
|
this.prewarmNamespaces.delete(top.namespace);
|
|
@@ -22305,7 +22965,7 @@ var ConnectServer = class _ConnectServer {
|
|
|
22305
22965
|
const blocked = profile ? servers.filter((s) => s.isActive && !profileAllows(profile, s.namespace)) : [];
|
|
22306
22966
|
const parts = ["No servers enabled."];
|
|
22307
22967
|
if (profile && blocked.length > 0) {
|
|
22308
|
-
const quote = (
|
|
22968
|
+
const quote = (list2) => list2.map((s) => `"${s.namespace}"`).join(", ");
|
|
22309
22969
|
const denied = blocked.filter((s) => profile.blocked?.includes(s.namespace));
|
|
22310
22970
|
const unlisted = blocked.filter((s) => !profile.blocked?.includes(s.namespace));
|
|
22311
22971
|
const edits = [];
|
|
@@ -23860,11 +24520,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
23860
24520
|
};
|
|
23861
24521
|
}
|
|
23862
24522
|
progress?.(`Ranking ${activeServers.length} ${activeServers.length === 1 ? "server" : "servers"}\u2026`);
|
|
23863
|
-
const
|
|
23864
|
-
const ranked = rankedRaw.map((r) => ({
|
|
23865
|
-
namespace: r.namespace,
|
|
23866
|
-
score: r.score * healthFactor(this.connections.get(r.namespace)?.health, this.activationFailures.get(r.namespace)) * this.learning.boostFactor(r.namespace)
|
|
23867
|
-
})).sort((a, b) => b.score - a.score);
|
|
24523
|
+
const ranked = await this.routingCandidates(trimmed, activeServers);
|
|
23868
24524
|
if (ranked.length === 0) {
|
|
23869
24525
|
return {
|
|
23870
24526
|
content: [
|
|
@@ -23882,6 +24538,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
23882
24538
|
const clientCanSample = era === "legacy" && this.pushCapabilities()?.sampling !== void 0;
|
|
23883
24539
|
const wantsTiebreak = safeBudget === 1 && shouldSample(ranked, effort);
|
|
23884
24540
|
if (wantsTiebreak && !clientCanSample) noteNoSamplingCapability2(era);
|
|
24541
|
+
let sampledPick = false;
|
|
23885
24542
|
if (wantsTiebreak && clientCanSample) {
|
|
23886
24543
|
progress?.("Top candidates close \u2014 asking LLM to pick\u2026");
|
|
23887
24544
|
const serversByNamespace = new Map(activeServers.map((s) => [s.namespace, s]));
|
|
@@ -23895,6 +24552,7 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
23895
24552
|
const rest = ranked.filter((r) => r.namespace !== picked);
|
|
23896
24553
|
ranked.length = 0;
|
|
23897
24554
|
ranked.push(winner, ...rest);
|
|
24555
|
+
sampledPick = true;
|
|
23898
24556
|
progress?.(`LLM chose ${picked}`);
|
|
23899
24557
|
}
|
|
23900
24558
|
}
|
|
@@ -23924,25 +24582,111 @@ Name collision: ${subject} of "${namespace}" cannot be called. ${entries}${more}
|
|
|
23924
24582
|
const results = [];
|
|
23925
24583
|
const tally = newExplicitLoadTally();
|
|
23926
24584
|
const dispatchedOk = [];
|
|
24585
|
+
const attempted = new Set(winners.map((w) => w.namespace));
|
|
24586
|
+
const fallbackPool = ranked.slice(safeBudget).filter((r) => r.score > 0);
|
|
24587
|
+
let fallbacksLeft = DISPATCH_MAX_FALLBACKS;
|
|
24588
|
+
const rescues = [];
|
|
23927
24589
|
let i = 0;
|
|
23928
24590
|
for (const winner of winners) {
|
|
23929
24591
|
i += 1;
|
|
23930
24592
|
progress?.(`Loading ${winner.namespace} (${i}/${winners.length})`, i - 1, winners.length);
|
|
23931
24593
|
const r = await this.activateOne(winner.namespace, progress);
|
|
23932
24594
|
results.push(`${winner.namespace} (score ${winner.score.toFixed(2)}): ${r.message}`);
|
|
23933
|
-
|
|
23934
|
-
if (r.ok
|
|
24595
|
+
const head = fallbackPool[0];
|
|
24596
|
+
if (r.ok || r.capped || fallbacksLeft === 0 || head === void 0 || !runnerUpCanReplace(winner, head)) {
|
|
24597
|
+
this.recordExplicitLoad(tally, winner.namespace, r);
|
|
24598
|
+
if (r.ok) dispatchedOk.push(winner.namespace);
|
|
24599
|
+
continue;
|
|
24600
|
+
}
|
|
24601
|
+
const failed = [{ namespace: winner.namespace, r }];
|
|
24602
|
+
let rescued = false;
|
|
24603
|
+
while (fallbacksLeft > 0 && fallbackPool.length > 0 && runnerUpCanReplace(winner, fallbackPool[0])) {
|
|
24604
|
+
const next = fallbackPool.shift();
|
|
24605
|
+
fallbacksLeft -= 1;
|
|
24606
|
+
attempted.add(next.namespace);
|
|
24607
|
+
progress?.(`${winner.namespace} failed to load; trying runner-up ${next.namespace}`);
|
|
24608
|
+
const fr = await this.activateOne(next.namespace, progress);
|
|
24609
|
+
results.push(
|
|
24610
|
+
`${next.namespace} (score ${next.score.toFixed(2)}, runner-up tried because ${winner.namespace} failed to load): ${fr.message}`
|
|
24611
|
+
);
|
|
24612
|
+
if (fr.ok) {
|
|
24613
|
+
this.recordExplicitLoad(tally, next.namespace, fr);
|
|
24614
|
+
dispatchedOk.push(next.namespace);
|
|
24615
|
+
this.lastIntentByNamespace.set(next.namespace, trimmed);
|
|
24616
|
+
rescues.push(`${winner.namespace} failed to load; loaded runner-up ${next.namespace} instead.`);
|
|
24617
|
+
rescued = true;
|
|
24618
|
+
break;
|
|
24619
|
+
}
|
|
24620
|
+
if (fr.capped) {
|
|
24621
|
+
this.recordExplicitLoad(tally, next.namespace, fr);
|
|
24622
|
+
break;
|
|
24623
|
+
}
|
|
24624
|
+
failed.push({ namespace: next.namespace, r: fr });
|
|
24625
|
+
}
|
|
24626
|
+
if (rescued) {
|
|
24627
|
+
if (failed.some((f) => f.r.isChanged)) tally.anyChanged = true;
|
|
24628
|
+
} else {
|
|
24629
|
+
for (const f of failed) this.recordExplicitLoad(tally, f.namespace, f.r);
|
|
24630
|
+
}
|
|
23935
24631
|
}
|
|
23936
24632
|
await this.announceExplicitLoads(tally);
|
|
23937
|
-
const
|
|
24633
|
+
const toolHints = this.dispatchToolHints(trimmed, dispatchedOk);
|
|
24634
|
+
if (toolHints.lines.length > 0) {
|
|
24635
|
+
results.push("Best tools for this request (arguments: required first, optional marked ?):", ...toolHints.lines);
|
|
24636
|
+
}
|
|
24637
|
+
const loadedPrimary = dispatchedOk[0];
|
|
24638
|
+
if (loadedPrimary) {
|
|
24639
|
+
const note = dispatchConfidenceNote(ranked, loadedPrimary, /* @__PURE__ */ new Set([...attempted, ...dispatchedOk]), {
|
|
24640
|
+
sampled: sampledPick && loadedPrimary === winners[0]?.namespace,
|
|
24641
|
+
noSampling: !clientCanSample && effort !== "off"
|
|
24642
|
+
});
|
|
24643
|
+
if (note) results.push(note);
|
|
24644
|
+
}
|
|
24645
|
+
const execHint = this.execHintForNonRelistingClient(dispatchedOk, toolHints.top);
|
|
23938
24646
|
if (execHint) results.push(execHint);
|
|
23939
|
-
const
|
|
24647
|
+
const runnersUpTried = attempted.size - winners.length;
|
|
24648
|
+
const tried = runnersUpTried > 0 ? `${attempted.size} (the top ${winners.length}, then ${runnersUpTried} ${runnersUpTried === 1 ? "runner-up" : "runners-up"})` : `the top ${winners.length}`;
|
|
24649
|
+
const header = `Dispatched "${trimmed}" \u2014 tried ${tried} of the ${ranked.length} server${ranked.length === 1 ? "" : "s"} ranked for it.${rescues.length > 0 ? ` ${rescues.join(" ")}` : ""}
|
|
23940
24650
|
`;
|
|
23941
24651
|
return {
|
|
23942
24652
|
content: [{ type: "text", text: header + results.join("\n") }],
|
|
23943
24653
|
isError: explicitLoadIsError(tally)
|
|
23944
24654
|
};
|
|
23945
24655
|
}
|
|
24656
|
+
/** For a dispatch reply: the DISPATCH_TOOL_HINTS tools of the namespaces
|
|
24657
|
+
* in `loaded` that rankTools ranks highest for `intent`, each as a
|
|
24658
|
+
* formatToolSignature line from its live inputSchema. Only served tools
|
|
24659
|
+
* (not shadowed by another namespace's wire name) that the profile does
|
|
24660
|
+
* not block. `top` is the first one's namespaced name, for the exec
|
|
24661
|
+
* example. Empty when no loaded tool shares a word with the intent --
|
|
24662
|
+
* the server then matched on its name or description, and naming three
|
|
24663
|
+
* arbitrary tools would be a guess. */
|
|
24664
|
+
dispatchToolHints(intent, loaded) {
|
|
24665
|
+
const views = [];
|
|
24666
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
24667
|
+
for (const ns of loaded) {
|
|
24668
|
+
const conn = this.connections.get(ns);
|
|
24669
|
+
if (!conn) continue;
|
|
24670
|
+
const tools = this.splitShadowedTools(ns, conn.tools).served.filter((t) => !this.isToolDenied(t.namespacedName));
|
|
24671
|
+
for (const t of tools) byKey.set(`${ns}\0${t.name}`, t);
|
|
24672
|
+
views.push({
|
|
24673
|
+
namespace: ns,
|
|
24674
|
+
name: conn.config.name,
|
|
24675
|
+
description: conn.config.description,
|
|
24676
|
+
tools: tools.map((t) => ({ name: t.name, description: t.description }))
|
|
24677
|
+
});
|
|
24678
|
+
}
|
|
24679
|
+
if (views.length === 0) return { lines: [] };
|
|
24680
|
+
const lines = [];
|
|
24681
|
+
let top;
|
|
24682
|
+
for (const hit of rankTools(intent, views).slice(0, DISPATCH_TOOL_HINTS)) {
|
|
24683
|
+
const tool = byKey.get(`${hit.namespace}\0${hit.name}`);
|
|
24684
|
+
if (!tool) continue;
|
|
24685
|
+
top ??= tool.namespacedName;
|
|
24686
|
+
lines.push(` ${formatToolSignature(tool.namespacedName, tool.inputSchema)}`);
|
|
24687
|
+
}
|
|
24688
|
+
return { lines, top };
|
|
24689
|
+
}
|
|
23946
24690
|
// Drop every per-namespace bit of session state after its connection has
|
|
23947
24691
|
// been closed. Called by all four teardown sites -- explicit deactivate,
|
|
23948
24692
|
// the idle reaper, reconcileConfig's unload of a server a bundles.json
|
|
@@ -24382,7 +25126,18 @@ Cross-session reliability (dormant, <${flakyPct}% success):`);
|
|
|
24382
25126
|
this.getProfiledActiveServers().map((s) => this.rankableFor(s))
|
|
24383
25127
|
);
|
|
24384
25128
|
}
|
|
25129
|
+
const unseen = this.unseenToolListMatches(query);
|
|
24385
25130
|
if (ranked.length === 0) {
|
|
25131
|
+
if (unseen.none.length > 0) {
|
|
25132
|
+
return {
|
|
25133
|
+
content: [
|
|
25134
|
+
{
|
|
25135
|
+
type: "text",
|
|
25136
|
+
text: `No known tool matches "${query}". ${this.unseenToolListLine(query, unseen.none)}`
|
|
25137
|
+
}
|
|
25138
|
+
]
|
|
25139
|
+
};
|
|
25140
|
+
}
|
|
24386
25141
|
return {
|
|
24387
25142
|
content: [
|
|
24388
25143
|
{
|
|
@@ -24401,7 +25156,8 @@ Cross-session reliability (dormant, <${flakyPct}% success):`);
|
|
|
24401
25156
|
for (const hit of usable) {
|
|
24402
25157
|
const connection = this.connections.get(hit.namespace);
|
|
24403
25158
|
const live = connection?.status === "connected" ? connection.tools.find((t) => t.name === hit.name) : void 0;
|
|
24404
|
-
|
|
25159
|
+
const bundled = unseen.bundled.includes(hit.namespace);
|
|
25160
|
+
lines.push(` ${hit.namespace}_${hit.name}${live ? " [loaded]" : bundled ? " [bundled list]" : ""}`);
|
|
24405
25161
|
if (hit.description) lines.push(` ${hit.description}`);
|
|
24406
25162
|
if (live) {
|
|
24407
25163
|
lines.push(` input schema: ${JSON.stringify(live.inputSchema)}`);
|
|
@@ -24429,8 +25185,40 @@ Cross-session reliability (dormant, <${flakyPct}% success):`);
|
|
|
24429
25185
|
"",
|
|
24430
25186
|
primary === void 0 ? `Every match shown is blocked by the profile's "blockedTools" list.` : alsoTry.length > 0 ? `To use one: mcp_connect_activate with server "${primary}" (or ${alsoTry.join(", ")}).` : `To use one: mcp_connect_activate with server "${primary}".`
|
|
24431
25187
|
);
|
|
25188
|
+
const bundledShown = [...new Set(usable.map((h) => h.namespace).filter((ns) => unseen.bundled.includes(ns)))];
|
|
25189
|
+
if (bundledShown.length > 0) {
|
|
25190
|
+
lines.push(
|
|
25191
|
+
`[bundled list]: ${bundledShown.join(", ")} has never loaded on this machine, so its tools above come from yaw-mcp's bundled copy of the upstream list and are unconfirmed; loading it replaces them with what it really serves.`
|
|
25192
|
+
);
|
|
25193
|
+
}
|
|
25194
|
+
if (unseen.none.length > 0) lines.push(this.unseenToolListLine(query, unseen.none));
|
|
24432
25195
|
return { content: [{ type: "text", text: lines.join("\n") }] };
|
|
24433
25196
|
}
|
|
25197
|
+
// How many of the query's best-ranked servers find_tool checks for an
|
|
25198
|
+
// unknown tool list. Wider would name servers that share one weak word
|
|
25199
|
+
// with the query; the point is the plausible ones.
|
|
25200
|
+
static FIND_TOOL_UNSEEN_TOP = 5;
|
|
25201
|
+
/** For find_tool: among the servers rankServers puts in its top
|
|
25202
|
+
* FIND_TOOL_UNSEEN_TOP for `query`, the ones whose tool list is unknown
|
|
25203
|
+
* (`none`, in ranking order); and every server ranked on the bundled list
|
|
25204
|
+
* (`bundled`), so its hits can be labelled. */
|
|
25205
|
+
unseenToolListMatches(query) {
|
|
25206
|
+
const servers = this.getProfiledActiveServers();
|
|
25207
|
+
const sources = new Map(servers.map((s) => [s.namespace, this.rankableTools(s).source]));
|
|
25208
|
+
const top = rankServers(
|
|
25209
|
+
query,
|
|
25210
|
+
servers.map((s) => this.rankableFor(s))
|
|
25211
|
+
).slice(0, _ConnectServer.FIND_TOOL_UNSEEN_TOP);
|
|
25212
|
+
return {
|
|
25213
|
+
none: top.filter((r) => sources.get(r.namespace) === "none").map((r) => r.namespace),
|
|
25214
|
+
bundled: servers.filter((s) => sources.get(s.namespace) === "bundled").map((s) => s.namespace)
|
|
25215
|
+
};
|
|
25216
|
+
}
|
|
25217
|
+
unseenToolListLine(query, namespaces) {
|
|
25218
|
+
const plural = namespaces.length > 1;
|
|
25219
|
+
const call = JSON.stringify({ intent: query });
|
|
25220
|
+
return `Not searched: ${namespaces.join(", ")} match${plural ? "" : "es"} this request by name or description, but ${plural ? "their tool lists are" : "its tool list is"} unknown until ${plural ? "they have" : "it has"} loaded once. mcp_connect_dispatch ${call} loads the best match and lists its tools.`;
|
|
25221
|
+
}
|
|
24434
25222
|
// Pack suggestion. Surfaces recurring multi-server tool-call sequences from
|
|
24435
25223
|
// the pack history, which persists across restarts (see persistence.ts).
|
|
24436
25224
|
// Observation only — never activates anything. Ranked by frequency
|
|
@@ -24652,6 +25440,33 @@ Cross-session reliability (dormant, <${flakyPct}% success):`);
|
|
|
24652
25440
|
isError: true
|
|
24653
25441
|
};
|
|
24654
25442
|
}
|
|
25443
|
+
for (let i = 0; i < steps.length; i++) {
|
|
25444
|
+
const step = steps[i];
|
|
25445
|
+
const route = this.toolRoutes.get(step.tool);
|
|
25446
|
+
if (!route || route.deferred || isRefNode(step.args)) continue;
|
|
25447
|
+
const tool = this.connections.get(route.namespace)?.tools.find((t) => t.name === route.originalName);
|
|
25448
|
+
if (!tool) continue;
|
|
25449
|
+
const mismatch = checkToolArgs(tool.inputSchema, step.args);
|
|
25450
|
+
if (!mismatch) continue;
|
|
25451
|
+
const key = stepBindingKey(step, i);
|
|
25452
|
+
const parts = [];
|
|
25453
|
+
if (mismatch.missing.length > 0) parts.push(`Missing required: ${mismatch.missing.join(", ")}.`);
|
|
25454
|
+
if (mismatch.unknown.length > 0) {
|
|
25455
|
+
const listed = mismatch.unknown.map(
|
|
25456
|
+
(u) => u.suggestion ? `${u.key} (did you mean "${u.suggestion}"?)` : u.key
|
|
25457
|
+
);
|
|
25458
|
+
parts.push(`Not in the schema: ${listed.join(", ")}.`);
|
|
25459
|
+
}
|
|
25460
|
+
return {
|
|
25461
|
+
content: [
|
|
25462
|
+
{
|
|
25463
|
+
type: "text",
|
|
25464
|
+
text: `exec: step "${key}": the arguments do not fit "${step.tool}"; no step ran. ${parts.join(" ")} Expected: ${formatToolSignature(step.tool, tool.inputSchema, Number.POSITIVE_INFINITY)}`
|
|
25465
|
+
}
|
|
25466
|
+
],
|
|
25467
|
+
isError: true
|
|
25468
|
+
};
|
|
25469
|
+
}
|
|
24655
25470
|
const bindings = {};
|
|
24656
25471
|
const echoed = {};
|
|
24657
25472
|
const stepKeys = [];
|
|
@@ -24917,7 +25732,7 @@ function registerShutdownTriggers(shutdown, targets) {
|
|
|
24917
25732
|
// src/status-cmd.ts
|
|
24918
25733
|
import { existsSync as existsSync10 } from "fs";
|
|
24919
25734
|
import { homedir as homedir23 } from "os";
|
|
24920
|
-
var VERSION2 = true ? "1.1.
|
|
25735
|
+
var VERSION2 = true ? "1.1.8" : "dev";
|
|
24921
25736
|
var STATUS_SCHEMA_VERSION = 1;
|
|
24922
25737
|
var STATUS_USAGE = `Usage: yaw-mcp status [--json]
|
|
24923
25738
|
|
|
@@ -25535,7 +26350,9 @@ if (subcommand === "compliance") {
|
|
|
25535
26350
|
with the client LLM: \`off\` | \`auto\` |
|
|
25536
26351
|
\`aggressive\` (default auto). The dispatch
|
|
25537
26352
|
tool's \`routeEffort\` argument overrides this
|
|
25538
|
-
per call.
|
|
26353
|
+
per call. Needs a client that supports MCP
|
|
26354
|
+
sampling (2025 protocol); without one it has
|
|
26355
|
+
no effect.
|
|
25539
26356
|
YAW_MCP_REWARD_GRADER Set to \`1\` to OPT IN to the LLM reward
|
|
25540
26357
|
grader: uncertain dispatch outcomes get a
|
|
25541
26358
|
second opinion via client sampling. It spends
|
|
@@ -25634,7 +26451,7 @@ if (subcommand === "compliance") {
|
|
|
25634
26451
|
saturated machine (CPU >= 50% busy over the wait)
|
|
25635
26452
|
a still-running local child gets this deadline
|
|
25636
26453
|
once more, never longer (unknown load, as on
|
|
25637
|
-
oam
|
|
26454
|
+
oam before 0.19.2, counts as busy); a per-server
|
|
25638
26455
|
\`connectTimeoutMs\` is never extended.
|
|
25639
26456
|
MCP_LIST_TIMEOUT Milliseconds to wait for a server's tool/
|
|
25640
26457
|
resource/prompt inventory calls after the
|
|
@@ -25761,7 +26578,7 @@ if (subcommand === "compliance") {
|
|
|
25761
26578
|
`);
|
|
25762
26579
|
process.exitCode = 0;
|
|
25763
26580
|
} else if (subcommand === "--version" || subcommand === "-V") {
|
|
25764
|
-
process.stdout.write(`yaw-mcp ${true ? "1.1.
|
|
26581
|
+
process.stdout.write(`yaw-mcp ${true ? "1.1.8" : "dev"}
|
|
25765
26582
|
`);
|
|
25766
26583
|
process.exitCode = 0;
|
|
25767
26584
|
} else if (subcommand !== void 0 && !subcommand.startsWith("-")) {
|