lurqrun 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -13
- package/dist/auditHandler-JCOJSUYW.js +23 -0
- package/dist/bin/lurq.js +3085 -17723
- package/dist/browserAuth-B6G27USY.js +95 -0
- package/dist/cache-DKI34SVS.js +12 -0
- package/dist/check-2FDGUOV7.js +192 -0
- package/dist/checkUpgrade-F2WESBPM.js +103 -0
- package/dist/chunk-2VMOWSRY.js +300 -0
- package/dist/chunk-3GHJR7XR.js +2049 -0
- package/dist/chunk-3N3Q3DSW.js +214 -0
- package/dist/chunk-4ESO33J6.js +34 -0
- package/dist/chunk-4F7ZESPO.js +132 -0
- package/dist/chunk-4KCPOMG6.js +68 -0
- package/dist/chunk-4ZYCIMY4.js +155 -0
- package/dist/chunk-63MUJNZL.js +318 -0
- package/dist/chunk-6AAEVQ7I.js +6336 -0
- package/dist/chunk-6EQ3ARXA.js +304 -0
- package/dist/chunk-6L3U7DZ5.js +23 -0
- package/dist/chunk-AHBP533R.js +220 -0
- package/dist/chunk-B43LCXBM.js +223 -0
- package/dist/chunk-BCANRN5B.js +33 -0
- package/dist/chunk-BUALU27S.js +123 -0
- package/dist/chunk-BULZAX2U.js +1554 -0
- package/dist/chunk-BV32UNLL.js +154 -0
- package/dist/chunk-C6GLE626.js +160 -0
- package/dist/chunk-CIDWNUAP.js +145 -0
- package/dist/chunk-CUP36ND3.js +2126 -0
- package/dist/chunk-CW5HJ3LX.js +96 -0
- package/dist/chunk-DB2VF5UD.js +315 -0
- package/dist/chunk-DWAGCNEL.js +210 -0
- package/dist/chunk-EA3DP5HG.js +293 -0
- package/dist/chunk-ELGCAM7P.js +184 -0
- package/dist/chunk-FW6BD2NO.js +1915 -0
- package/dist/chunk-GE37NVLN.js +15 -0
- package/dist/chunk-GPTKSNR6.js +171 -0
- package/dist/chunk-GRJXQBQZ.js +793 -0
- package/dist/chunk-HWBBVLOT.js +92 -0
- package/dist/chunk-I2JUKN6Z.js +24 -0
- package/dist/chunk-I3M2KJXB.js +56 -0
- package/dist/chunk-IQ4SDKKY.js +733 -0
- package/dist/chunk-J5FZYN4A.js +116 -0
- package/dist/chunk-L6N4JFW2.js +263 -0
- package/dist/chunk-LBFGSSF2.js +126 -0
- package/dist/chunk-LEGPB7DO.js +81 -0
- package/dist/chunk-LO35HLQZ.js +219 -0
- package/dist/chunk-LRD4GBYE.js +73 -0
- package/dist/chunk-LUAKDHLZ.js +40 -0
- package/dist/chunk-LYMPYETA.js +965 -0
- package/dist/chunk-M6NYEXCW.js +38 -0
- package/dist/chunk-MHUEVBVO.js +35 -0
- package/dist/chunk-MYGSLK44.js +37 -0
- package/dist/chunk-NH5I4KHH.js +201 -0
- package/dist/chunk-OQS4GUSI.js +1391 -0
- package/dist/chunk-PSX3GIAN.js +176 -0
- package/dist/chunk-Q5VPF4WI.js +26 -0
- package/dist/chunk-QKGYDMWB.js +7409 -0
- package/dist/chunk-QSL6QN5X.js +115 -0
- package/dist/chunk-SHCEBP3J.js +107 -0
- package/dist/chunk-SJOVFF7B.js +201 -0
- package/dist/chunk-ST2X2GYN.js +373 -0
- package/dist/chunk-TNTXWSYA.js +19 -0
- package/dist/chunk-U5AT3TD4.js +2128 -0
- package/dist/chunk-UDVNA7EA.js +483 -0
- package/dist/chunk-VL2E5T2A.js +109 -0
- package/dist/chunk-VLRHFMGJ.js +58 -0
- package/dist/chunk-WHX2ZFCG.js +4048 -0
- package/dist/chunk-WQ23REYT.js +37 -0
- package/dist/chunk-XBIDMHSK.js +15425 -0
- package/dist/chunk-Y5GI7RL3.js +66 -0
- package/dist/client-IRKAMDYZ.js +15 -0
- package/dist/commands-FIL5ET6P.js +911 -0
- package/dist/compat-R3UTFQ5Q.js +201 -0
- package/dist/dashboardIssue-WYYMBFIB.js +192 -0
- package/dist/diff-GZA2774U.js +13 -0
- package/dist/dist-4XXIXHHZ.js +12945 -0
- package/dist/e2b-FVPHDULZ.js +172 -0
- package/dist/extract-NKGKLIVT.js +444 -0
- package/dist/fetch-QYTUJVG2.js +22 -0
- package/dist/firstTouch-QQTJH4QX.js +55 -0
- package/dist/handlers-GEJAVZDK.js +53 -0
- package/dist/http-ETPYMBGD.js +5360 -0
- package/dist/ingestQueue-VKN4KBIF.js +35 -0
- package/dist/install-EK3W2COX.js +20 -0
- package/dist/installSkill-VQJWJVCL.js +52 -0
- package/dist/inventory-5AWSLJYU.js +31 -0
- package/dist/local-XPZMRH5R.js +13 -0
- package/dist/mcp-3JHD5SUZ.js +472 -0
- package/dist/mcpHandlers-QFN4MCFL.js +22 -0
- package/dist/mcpScan-QZHWENIP.js +1871 -0
- package/dist/mcpScanWorkflow-JPYCBGC4.js +81 -0
- package/dist/mcpStack-BYJCZNIV.js +20 -0
- package/dist/packages-THVFMWFP.js +42 -0
- package/dist/plan-V4OEI3J4.js +463 -0
- package/dist/planView-JRXGCG2N.js +79 -0
- package/dist/policy-3P6BGRDN.js +115 -0
- package/dist/references-6N7VEPHT.js +14 -0
- package/dist/release-4U4ABNSJ.js +128 -0
- package/dist/remote-YGCXYI4V.js +32 -0
- package/dist/reportRuns-CKQQYLY4.js +64 -0
- package/dist/sandbox-MEZLAODF.js +39 -0
- package/dist/server-KFUD5X57.js +55 -0
- package/dist/surface-V62GE554.js +141 -0
- package/dist/surface-YL6O67W3.js +36 -0
- package/dist/surfaceHandlers-X2IZKA3E.js +20 -0
- package/dist/typecheck-X7U5ELMR.js +268 -0
- package/dist/types-M5JP2W3D.js +10 -0
- package/dist/uninstall-P7RGBX6G.js +174 -0
- package/dist/upgrade-NQ5IWFZB.js +596 -0
- package/dist/upgradePlan-A4LRKLEG.js +146 -0
- package/dist/userConfig-Z3GQE776.js +20 -0
- package/dist/watch-DGFMWUDL.js +214 -0
- package/package.json +41 -26
- package/templates/agent-rules.md +4 -4
- package/templates/skill-instructions.md +18 -14
- package/dist/bin/lurq.js.map +0 -1
- package/dist/index.d.ts +0 -764
- package/dist/index.js +0 -17992
- package/dist/index.js.map +0 -1
- package/drizzle/0000_confused_fabian_cortez.sql +0 -54
- package/drizzle/0001_aspiring_timeslip.sql +0 -15
- package/drizzle/0002_lyrical_lila_cheney.sql +0 -14
- package/drizzle/0003_violet_giant_girl.sql +0 -14
- package/drizzle/0004_slim_valeria_richards.sql +0 -15
- package/drizzle/0005_petite_luke_cage.sql +0 -12
- package/drizzle/0006_calm_nighthawk.sql +0 -3
- package/drizzle/0007_slimy_naoko.sql +0 -1
- package/drizzle/0008_peaceful_tigra.sql +0 -1
- package/drizzle/0009_smooth_harrier.sql +0 -10
- package/drizzle/0010_curved_amphibian.sql +0 -2
- package/drizzle/0011_compat_provenance_closures.sql +0 -11
- package/drizzle/0012_api_surfaces.sql +0 -9
- package/drizzle/0013_nice_thanos.sql +0 -1
- package/drizzle/0014_luxuriant_malcolm_colcord.sql +0 -10
- package/drizzle/0015_past_fat_cobra.sql +0 -11
- package/drizzle/0016_futuristic_junta.sql +0 -50
- package/drizzle/0017_absent_grandmaster.sql +0 -20
- package/drizzle/0018_rainy_proemial_gods.sql +0 -1
- package/drizzle/0019_dashing_korvac.sql +0 -11
- package/drizzle/0020_normal_vulture.sql +0 -3
- package/drizzle/0021_dazzling_blue_shield.sql +0 -17
- package/drizzle/0022_massive_ghost_rider.sql +0 -24
- package/drizzle/0023_next_shatterstar.sql +0 -1
- package/drizzle/0024_dusty_maelstrom.sql +0 -15
- package/drizzle/0025_gifted_harpoon.sql +0 -5
- package/drizzle/0026_awesome_mordo.sql +0 -1
- package/drizzle/0027_charming_ulik.sql +0 -2
- package/drizzle/0028_romantic_loners.sql +0 -2
- package/drizzle/0029_busy_korvac.sql +0 -16
- package/drizzle/0030_steady_mathemanic.sql +0 -6
- package/drizzle/0031_redundant_maginty.sql +0 -2
- package/drizzle/0032_stack_resolutions.sql +0 -14
- package/drizzle/0033_graceful_tyger_tiger.sql +0 -3
- package/drizzle/0034_api_key_scopes.sql +0 -1
- package/drizzle/0035_policy_audit.sql +0 -21
- package/drizzle/meta/0000_snapshot.json +0 -370
- package/drizzle/meta/0001_snapshot.json +0 -482
- package/drizzle/meta/0002_snapshot.json +0 -575
- package/drizzle/meta/0003_snapshot.json +0 -667
- package/drizzle/meta/0004_snapshot.json +0 -769
- package/drizzle/meta/0005_snapshot.json +0 -864
- package/drizzle/meta/0006_snapshot.json +0 -882
- package/drizzle/meta/0007_snapshot.json +0 -876
- package/drizzle/meta/0008_snapshot.json +0 -882
- package/drizzle/meta/0009_snapshot.json +0 -948
- package/drizzle/meta/0010_snapshot.json +0 -969
- package/drizzle/meta/0011_snapshot.json +0 -1049
- package/drizzle/meta/0012_snapshot.json +0 -1115
- package/drizzle/meta/0013_snapshot.json +0 -1121
- package/drizzle/meta/0014_snapshot.json +0 -1190
- package/drizzle/meta/0015_snapshot.json +0 -1280
- package/drizzle/meta/0016_snapshot.json +0 -1683
- package/drizzle/meta/0017_snapshot.json +0 -1834
- package/drizzle/meta/0018_snapshot.json +0 -1834
- package/drizzle/meta/0019_snapshot.json +0 -1909
- package/drizzle/meta/0020_snapshot.json +0 -1921
- package/drizzle/meta/0021_snapshot.json +0 -2045
- package/drizzle/meta/0022_snapshot.json +0 -2246
- package/drizzle/meta/0023_snapshot.json +0 -2252
- package/drizzle/meta/0024_snapshot.json +0 -2375
- package/drizzle/meta/0025_snapshot.json +0 -2407
- package/drizzle/meta/0026_snapshot.json +0 -2413
- package/drizzle/meta/0027_snapshot.json +0 -2425
- package/drizzle/meta/0028_snapshot.json +0 -2438
- package/drizzle/meta/0029_snapshot.json +0 -2546
- package/drizzle/meta/0030_snapshot.json +0 -2586
- package/drizzle/meta/0031_snapshot.json +0 -2598
- package/drizzle/meta/0032_snapshot.json +0 -2699
- package/drizzle/meta/0033_snapshot.json +0 -2712
- package/drizzle/meta/0034_snapshot.json +0 -2719
- package/drizzle/meta/0035_snapshot.json +0 -2869
- package/drizzle/meta/_journal.json +0 -258
- package/src/data/seed.json +0 -253
|
@@ -0,0 +1,1391 @@
|
|
|
1
|
+
import { createRequire as __lurqCreateRequire } from 'node:module'; const require = __lurqCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
AjvJsonSchemaValidator,
|
|
4
|
+
Protocol,
|
|
5
|
+
assertClientRequestTaskCapability,
|
|
6
|
+
assertToolsCallTaskCapability,
|
|
7
|
+
getObjectShape,
|
|
8
|
+
isZ4Schema,
|
|
9
|
+
mergeCapabilities,
|
|
10
|
+
safeParse
|
|
11
|
+
} from "./chunk-XBIDMHSK.js";
|
|
12
|
+
import {
|
|
13
|
+
CallToolResultSchema,
|
|
14
|
+
CompleteResultSchema,
|
|
15
|
+
CreateMessageRequestSchema,
|
|
16
|
+
CreateMessageResultSchema,
|
|
17
|
+
CreateMessageResultWithToolsSchema,
|
|
18
|
+
CreateTaskResultSchema,
|
|
19
|
+
ElicitRequestSchema,
|
|
20
|
+
ElicitResultSchema,
|
|
21
|
+
EmptyResultSchema,
|
|
22
|
+
ErrorCode,
|
|
23
|
+
GetPromptResultSchema,
|
|
24
|
+
InitializeResultSchema,
|
|
25
|
+
LATEST_PROTOCOL_VERSION,
|
|
26
|
+
ListChangedOptionsBaseSchema,
|
|
27
|
+
ListPromptsResultSchema,
|
|
28
|
+
ListResourceTemplatesResultSchema,
|
|
29
|
+
ListResourcesResultSchema,
|
|
30
|
+
ListToolsResultSchema,
|
|
31
|
+
McpError,
|
|
32
|
+
PromptListChangedNotificationSchema,
|
|
33
|
+
ReadResourceResultSchema,
|
|
34
|
+
ResourceListChangedNotificationSchema,
|
|
35
|
+
SUPPORTED_PROTOCOL_VERSIONS,
|
|
36
|
+
ToolListChangedNotificationSchema
|
|
37
|
+
} from "./chunk-6AAEVQ7I.js";
|
|
38
|
+
import {
|
|
39
|
+
SEVERITY_RANK
|
|
40
|
+
} from "./chunk-Q5VPF4WI.js";
|
|
41
|
+
import {
|
|
42
|
+
analyzeStack
|
|
43
|
+
} from "./chunk-VL2E5T2A.js";
|
|
44
|
+
import {
|
|
45
|
+
diffMcpSurfaces,
|
|
46
|
+
mcpSurface,
|
|
47
|
+
resolveAnnotations,
|
|
48
|
+
summarizeDrift,
|
|
49
|
+
surfaceHash
|
|
50
|
+
} from "./chunk-6EQ3ARXA.js";
|
|
51
|
+
import {
|
|
52
|
+
init_esm_shims
|
|
53
|
+
} from "./chunk-I3M2KJXB.js";
|
|
54
|
+
|
|
55
|
+
// src/mcpScan/analyze.ts
|
|
56
|
+
init_esm_shims();
|
|
57
|
+
var WRITE_CAPABILITIES = /* @__PURE__ */ new Set([
|
|
58
|
+
"shell.exec",
|
|
59
|
+
"code.exec",
|
|
60
|
+
"filesystem.write",
|
|
61
|
+
"messaging.send",
|
|
62
|
+
"payments",
|
|
63
|
+
"database.write",
|
|
64
|
+
"vcs.write"
|
|
65
|
+
]);
|
|
66
|
+
function words(name) {
|
|
67
|
+
return new Set(
|
|
68
|
+
name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").toLowerCase().split(/[^a-z0-9]+/).filter(Boolean)
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
var has = (w, ...xs) => xs.find((x) => w.has(x));
|
|
72
|
+
var both = (a, b) => a && b ? `${a} ${b}` : void 0;
|
|
73
|
+
var RULES = [
|
|
74
|
+
{
|
|
75
|
+
capability: "shell.exec",
|
|
76
|
+
name: (w) => has(w, "shell", "bash", "terminal", "powershell", "zsh") ?? both(has(w, "run", "execute", "exec"), has(w, "command", "commands", "script", "process")),
|
|
77
|
+
text: /\b(?:execut|run)\w*\s+(?:an?\s+|any\s+)?(?:arbitrary\s+)?(?:shell|terminal|bash|system)\s+commands?\b/i
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
capability: "code.exec",
|
|
81
|
+
name: (w) => has(w, "eval", "repl") ?? both(has(w, "run", "execute", "exec"), has(w, "code", "python", "javascript", "js", "notebook", "cell")),
|
|
82
|
+
text: /\b(?:execut|run|evaluat)\w*\s+(?:arbitrary\s+)?(?:python|javascript|typescript|js)?\s*code\b/i
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
capability: "filesystem.write",
|
|
86
|
+
name: (w) => both(
|
|
87
|
+
has(w, "write", "create", "delete", "remove", "move", "rename", "edit", "append", "mkdir", "rm", "save", "overwrite", "copy"),
|
|
88
|
+
has(w, "file", "files", "directory", "dir", "folder", "path")
|
|
89
|
+
),
|
|
90
|
+
text: /\b(?:writes?|creates?|deletes?|overwrites?|modif(?:y|ies)|moves?|renames?)\s+(?:a\s+|the\s+|new\s+)?(?:files?|director(?:y|ies)|folders?)\b/i
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
capability: "filesystem.read",
|
|
94
|
+
name: (w) => both(
|
|
95
|
+
has(w, "read", "list", "get", "search", "stat", "tree", "find", "glob", "view", "open"),
|
|
96
|
+
has(w, "file", "files", "directory", "directories", "dir", "folder")
|
|
97
|
+
),
|
|
98
|
+
text: /\b(?:reads?|lists?)\s+(?:the\s+)?(?:contents?\s+of\s+)?(?:a\s+|the\s+)?(?:files?|director(?:y|ies))\b/i
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
capability: "network.fetch",
|
|
102
|
+
name: (w) => has(w, "fetch", "http", "curl", "download", "scrape", "crawl", "webhook") ?? both(has(w, "get", "open", "read"), has(w, "url", "webpage", "website")),
|
|
103
|
+
param: /^(?:url|uri|endpoint|href|webhook_?url)$/i,
|
|
104
|
+
text: /\b(?:fetch|fetches|downloads?|requests?)\s+(?:a\s+|the\s+|any\s+)?(?:url|web\s?page|website|http)/i
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
capability: "browser.control",
|
|
108
|
+
name: (w) => has(w, "browser", "navigate", "click", "screenshot", "playwright", "puppeteer", "hover", "keypress")
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
capability: "messaging.send",
|
|
112
|
+
name: (w) => both(
|
|
113
|
+
has(w, "send", "post", "reply", "publish", "notify", "forward", "broadcast"),
|
|
114
|
+
has(w, "email", "mail", "message", "messages", "slack", "sms", "tweet", "dm", "chat", "channel", "comment", "notification")
|
|
115
|
+
),
|
|
116
|
+
text: /\b(?:sends?|posts?|publish(?:es)?)\s+(?:an?\s+|the\s+)?(?:email|message|slack\s+message|sms|tweet|notification)s?\b/i
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
capability: "payments",
|
|
120
|
+
name: (w) => has(w, "payment", "payments", "charge", "refund", "invoice", "payout", "checkout"),
|
|
121
|
+
text: /\b(?:charges?\s+(?:a\s+|the\s+)?(?:card|customer)|refunds?\s+(?:a\s+|the\s+)?(?:payment|charge)|transfers?\s+funds)\b/i
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
capability: "database.write",
|
|
125
|
+
name: (w) => both(
|
|
126
|
+
has(w, "insert", "update", "delete", "drop", "truncate", "upsert", "migrate", "alter"),
|
|
127
|
+
has(w, "row", "rows", "record", "records", "table", "tables", "database", "db", "sql", "collection")
|
|
128
|
+
) ?? both(has(w, "execute", "exec", "run", "apply"), has(w, "sql", "migration")),
|
|
129
|
+
text: /\b(?:execut|run)\w*\s+(?:a\s+|any\s+|arbitrary\s+|raw\s+)?sql\b/i
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
capability: "database.read",
|
|
133
|
+
name: (w) => has(w, "sql", "select") ?? both(has(w, "query", "list", "get", "describe"), has(w, "table", "tables", "schema", "database", "db", "rows"))
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
capability: "vcs.write",
|
|
137
|
+
name: (w) => has(w, "push", "merge", "commit") ?? both(has(w, "create", "delete", "update", "close"), has(w, "branch", "repository", "repo", "pull", "release", "tag"))
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
capability: "credentials",
|
|
141
|
+
name: (w) => has(w, "secret", "secrets", "credential", "credentials", "password", "passwords") ?? both(has(w, "get", "read", "list", "print", "dump"), has(w, "env", "environment")),
|
|
142
|
+
param: /^(?:password|passwd|secret|token|api_?key|private_?key|access_?token|client_?secret)$/i
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
function topParams(schema2) {
|
|
146
|
+
const props = schema2?.properties;
|
|
147
|
+
return props && typeof props === "object" && !Array.isArray(props) ? Object.keys(props) : [];
|
|
148
|
+
}
|
|
149
|
+
function toolCapabilities(tool) {
|
|
150
|
+
const w = words(tool.name);
|
|
151
|
+
const params = topParams(tool.inputSchema);
|
|
152
|
+
const desc = tool.description ?? "";
|
|
153
|
+
const hits = [];
|
|
154
|
+
for (const rule of RULES) {
|
|
155
|
+
const token = rule.name?.(w);
|
|
156
|
+
if (token) {
|
|
157
|
+
hits.push({ capability: rule.capability, evidence: `name "${tool.name}" (${token})` });
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
const param = rule.param ? params.find((p) => rule.param.test(p)) : void 0;
|
|
161
|
+
if (param) {
|
|
162
|
+
hits.push({ capability: rule.capability, evidence: `parameter "${param}"` });
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const m = rule.text?.exec(desc);
|
|
166
|
+
if (m) hits.push({ capability: rule.capability, evidence: `description: "${m[0]}"` });
|
|
167
|
+
}
|
|
168
|
+
return hits;
|
|
169
|
+
}
|
|
170
|
+
var TAG_CHARS = /[\u{E0000}-\u{E007F}]/gu;
|
|
171
|
+
var BIDI = /[\u202A-\u202E\u2066-\u2069]/g;
|
|
172
|
+
var INVISIBLE = /[\u200B\u200C\u200E\u200F\u2060-\u2064\uFEFF]/g;
|
|
173
|
+
var OVERRIDE = /\b(?:ignore|disregard|forget|override|bypass)\b[^.\n]{0,40}?\b(?:previous|prior|above|earlier|all|any|other|system|safety)\b[^.\n]{0,30}?\b(?:instructions?|prompts?|rules|guidelines|directives|messages|constraints)\b/i;
|
|
174
|
+
var ROLE_TAG = /<\s*\/?\s*(?:important|system|instructions?|secret|hidden|admin|override)\s*>/i;
|
|
175
|
+
var DIRECTIVE = /\b(?:before|prior\s+to)\s+(?:using|calling|invoking|running)\s+(?:this|any|other|the\s+\w+)\s+tools?\b[^.\n]{0,80}?\b(?:you\s+must|must|always|first)\b|\byou\s+must\s+(?:always\s+)?(?:first\s+)?(?:call|invoke|read|send|include|pass)\b[^.\n]{0,50}?\b(?:before|every\s+time|with\s+every|other\s+tools?)\b/i;
|
|
176
|
+
var CONCEAL = /\b(?:do\s+not|don't|never|avoid)\s+(?:tell|telling|inform|informing|mention|mentioning|reveal|revealing|notify|notifying|alert|alerting)\b[^.\n]{0,30}?\b(?:the\s+)?users?\b|\bwithout\s+(?:asking|telling|informing|notifying)\s+(?:the\s+)?users?\b/i;
|
|
177
|
+
var SENSITIVE = /~\/\.ssh\b|\bid_(?:rsa|ed25519|ecdsa)\b|\.aws\/credentials|(?:^|[\s"'`(/])\.env\b|\bmcp\.json\b|\.claude\.json\b|\.npmrc\b|\.netrc\b|\.git-credentials\b|\/etc\/(?:passwd|shadow)\b|\bprivate[_\s-]key\b/i;
|
|
178
|
+
var EXFIL = /\b(?:send|post|upload|forward|transmit|include|append|pass|copy)\b[^.\n]{0,40}?\b(?:conversation|chat\s+history|system\s+prompt|previous\s+messages|credentials|ssh\s+keys?|contents\s+of\s+(?:the\s+)?(?:~|\.|file|user))/i;
|
|
179
|
+
var COLLECTOR_HOST = /https?:\/\/[^\s"')]*(?:ngrok(?:-free)?\.(?:io|app|dev)|webhook\.site|requestbin|pipedream\.net|burpcollaborator|interact\.sh|oast\.(?:fun|live|site|pro|online|me))/i;
|
|
180
|
+
var RAW_IP_URL = /https?:\/\/(?:\d{1,3}\.){3}\d{1,3}(?::\d+)?\//i;
|
|
181
|
+
var OVERSIZED_DESCRIPTION = 8e3;
|
|
182
|
+
function visible(s) {
|
|
183
|
+
return s.replace(TAG_CHARS, (c) => `\\u{${c.codePointAt(0).toString(16).toUpperCase()}}`).replace(BIDI, (c) => `\\u${c.charCodeAt(0).toString(16).toUpperCase()}`).replace(INVISIBLE, (c) => `\\u${c.charCodeAt(0).toString(16).toUpperCase()}`).replace(/\s+/g, " ").trim();
|
|
184
|
+
}
|
|
185
|
+
function snippet(text2, index, length) {
|
|
186
|
+
const start = Math.max(0, index - 40);
|
|
187
|
+
const end = Math.min(text2.length, index + length + 40);
|
|
188
|
+
return `${start > 0 ? "\u2026" : ""}${visible(text2.slice(start, end))}${end < text2.length ? "\u2026" : ""}`.slice(0, 240);
|
|
189
|
+
}
|
|
190
|
+
function decodeTags(text2) {
|
|
191
|
+
let out = "";
|
|
192
|
+
for (const ch of text2) {
|
|
193
|
+
const cp = ch.codePointAt(0);
|
|
194
|
+
if (cp >= 917536 && cp <= 917630) out += String.fromCharCode(cp - 917504);
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
function toolTexts(tool) {
|
|
199
|
+
const sites = [];
|
|
200
|
+
if (tool.title) sites.push({ tool: tool.name, where: "title", text: tool.title });
|
|
201
|
+
if (tool.description) sites.push({ tool: tool.name, where: "description", text: tool.description });
|
|
202
|
+
for (const [root, schema2] of [["inputSchema", tool.inputSchema], ["outputSchema", tool.outputSchema]]) {
|
|
203
|
+
const stack = [[schema2, root, 0]];
|
|
204
|
+
while (stack.length && sites.length < 500) {
|
|
205
|
+
const [node, path, depth] = stack.pop();
|
|
206
|
+
if (!node || typeof node !== "object" || depth > 20) continue;
|
|
207
|
+
for (const [k, v] of Object.entries(node)) {
|
|
208
|
+
if ((k === "description" || k === "title") && typeof v === "string") {
|
|
209
|
+
sites.push({ tool: tool.name, where: `${path}.${k}`, text: v });
|
|
210
|
+
} else if (v && typeof v === "object") {
|
|
211
|
+
stack.push([v, `${path}.${k}`, depth + 1]);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return sites;
|
|
217
|
+
}
|
|
218
|
+
function promptTexts(p) {
|
|
219
|
+
const sites = [];
|
|
220
|
+
if (p.description) sites.push({ tool: null, where: `prompt ${p.name}`, text: p.description });
|
|
221
|
+
for (const a of p.arguments) {
|
|
222
|
+
if (a.description) sites.push({ tool: null, where: `prompt ${p.name}.${a.name}`, text: a.description });
|
|
223
|
+
}
|
|
224
|
+
return sites;
|
|
225
|
+
}
|
|
226
|
+
function scanText(site) {
|
|
227
|
+
const out = [];
|
|
228
|
+
const { text: text2, tool, where } = site;
|
|
229
|
+
const add = (kind, severity, detail, evidence) => out.push({ kind, severity, tool, where, detail, evidence });
|
|
230
|
+
const tags = text2.match(TAG_CHARS);
|
|
231
|
+
if (tags) {
|
|
232
|
+
const decoded = decodeTags(text2);
|
|
233
|
+
add(
|
|
234
|
+
"hidden_characters",
|
|
235
|
+
"high",
|
|
236
|
+
`${tags.length} invisible Unicode tag character(s); they decode to text the model reads and a human reviewer cannot see`,
|
|
237
|
+
decoded ? `decodes to: "${decoded.slice(0, 200)}"` : null
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
const bidi = BIDI.exec(text2);
|
|
241
|
+
BIDI.lastIndex = 0;
|
|
242
|
+
if (bidi) {
|
|
243
|
+
add("hidden_characters", "high", "bidirectional override characters reorder what a reviewer sees", snippet(text2, bidi.index, 1));
|
|
244
|
+
}
|
|
245
|
+
const invisible = text2.match(INVISIBLE);
|
|
246
|
+
if (invisible) {
|
|
247
|
+
add("hidden_characters", "moderate", `${invisible.length} zero-width character(s)`, snippet(text2, text2.search(INVISIBLE), 1));
|
|
248
|
+
}
|
|
249
|
+
const plain = text2.replace(TAG_CHARS, "").replace(BIDI, "").replace(INVISIBLE, "");
|
|
250
|
+
const match = (re) => re.exec(plain);
|
|
251
|
+
const override = match(OVERRIDE) ?? match(ROLE_TAG);
|
|
252
|
+
if (override) {
|
|
253
|
+
add("instruction_override", "high", "tells the model to set aside its other instructions", snippet(plain, override.index, override[0].length));
|
|
254
|
+
}
|
|
255
|
+
const conceal = match(CONCEAL);
|
|
256
|
+
if (conceal) {
|
|
257
|
+
add("concealment", "high", "tells the model to keep something from the user", snippet(plain, conceal.index, conceal[0].length));
|
|
258
|
+
}
|
|
259
|
+
const directive = match(DIRECTIVE);
|
|
260
|
+
if (directive) {
|
|
261
|
+
add("model_directive", "moderate", "instructs the model how to use other tools, not just this one", snippet(plain, directive.index, directive[0].length));
|
|
262
|
+
}
|
|
263
|
+
const exfil = match(EXFIL);
|
|
264
|
+
const sensitive = match(SENSITIVE);
|
|
265
|
+
if (exfil) {
|
|
266
|
+
add("exfiltration", "high", "asks for conversation or credential material to be sent through a tool", snippet(plain, exfil.index, exfil[0].length));
|
|
267
|
+
}
|
|
268
|
+
if (sensitive) {
|
|
269
|
+
const steering = override || conceal || directive || exfil;
|
|
270
|
+
add(
|
|
271
|
+
steering ? "exfiltration" : "sensitive_path",
|
|
272
|
+
steering ? "critical" : "low",
|
|
273
|
+
steering ? "names a credential file alongside instructions to the model \u2014 the tool-poisoning pattern" : "mentions a credential file or secret location",
|
|
274
|
+
snippet(plain, sensitive.index, sensitive[0].length)
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
const host = match(COLLECTOR_HOST);
|
|
278
|
+
if (host) {
|
|
279
|
+
add("suspicious_url", "high", "references a request-capture or tunnelling host", snippet(plain, host.index, host[0].length));
|
|
280
|
+
} else {
|
|
281
|
+
const ip = match(RAW_IP_URL);
|
|
282
|
+
if (ip) add("suspicious_url", "moderate", "references a raw IP address url", snippet(plain, ip.index, ip[0].length));
|
|
283
|
+
}
|
|
284
|
+
if (where === "description" && text2.length > OVERSIZED_DESCRIPTION) {
|
|
285
|
+
add("oversized_text", "info", `description is ${text2.length} characters, all of it in the model's context on every request`, null);
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
function analyzeServer(snapshot) {
|
|
290
|
+
const capabilities = {};
|
|
291
|
+
const findings = [];
|
|
292
|
+
const stats = { tools: snapshot.tools.length, writes: 0, destroys: 0, openWorld: 0, annotated: 0, capabilities: {} };
|
|
293
|
+
for (const tool of snapshot.tools) {
|
|
294
|
+
const ann = resolveAnnotations(tool.annotations);
|
|
295
|
+
if (!ann.readOnlyHint) stats.writes++;
|
|
296
|
+
if (ann.destructiveHint) stats.destroys++;
|
|
297
|
+
if (ann.openWorldHint) stats.openWorld++;
|
|
298
|
+
if (tool.annotations && Object.keys(tool.annotations).some((k) => k !== "title")) stats.annotated++;
|
|
299
|
+
const hits = toolCapabilities(tool);
|
|
300
|
+
if (hits.length) capabilities[tool.name] = hits;
|
|
301
|
+
for (const h of hits) stats.capabilities[h.capability] = (stats.capabilities[h.capability] ?? 0) + 1;
|
|
302
|
+
const writing = hits.find((h) => WRITE_CAPABILITIES.has(h.capability));
|
|
303
|
+
if (tool.annotations?.readOnlyHint === true && writing) {
|
|
304
|
+
findings.push({
|
|
305
|
+
kind: "annotation_mismatch",
|
|
306
|
+
severity: "moderate",
|
|
307
|
+
tool: tool.name,
|
|
308
|
+
where: "annotations.readOnlyHint",
|
|
309
|
+
detail: `declares itself read-only, but reads as ${writing.capability}; a client that auto-approves read-only tools would run it unasked`,
|
|
310
|
+
evidence: writing.evidence
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
const sites = toolTexts(tool);
|
|
314
|
+
for (const site of sites) findings.push(...scanText(site));
|
|
315
|
+
}
|
|
316
|
+
for (const p of snapshot.prompts) for (const site of promptTexts(p)) findings.push(...scanText(site));
|
|
317
|
+
for (const t of snapshot.resourceTemplates) {
|
|
318
|
+
if (t.description) findings.push(...scanText({ tool: null, where: `resource template ${t.name}`, text: t.description }));
|
|
319
|
+
}
|
|
320
|
+
if (snapshot.instructions) findings.push(...scanText({ tool: null, where: "instructions", text: snapshot.instructions }));
|
|
321
|
+
const dupes = snapshot.issues.filter((i) => i.kind === "duplicate");
|
|
322
|
+
if (dupes.length) {
|
|
323
|
+
findings.push({
|
|
324
|
+
kind: "parse_issues",
|
|
325
|
+
severity: "moderate",
|
|
326
|
+
tool: null,
|
|
327
|
+
where: "tools/list",
|
|
328
|
+
detail: `${dupes.length} name(s) listed twice; clients disagree on which copy an agent gets`,
|
|
329
|
+
evidence: dupes.map((d) => d.detail).slice(0, 3).join("; ")
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
const malformed = snapshot.issues.filter((i) => i.kind === "malformed" || i.kind === "stdout_noise");
|
|
333
|
+
if (malformed.length) {
|
|
334
|
+
findings.push({
|
|
335
|
+
kind: "parse_issues",
|
|
336
|
+
severity: "low",
|
|
337
|
+
tool: null,
|
|
338
|
+
where: "tools/list",
|
|
339
|
+
detail: `${malformed.length} protocol issue(s); stricter clients may reject this server's list`,
|
|
340
|
+
evidence: malformed.map((d) => d.detail).slice(0, 3).join("; ")
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
return { capabilities, findings: sortFindings(findings), stats };
|
|
344
|
+
}
|
|
345
|
+
function sortFindings(findings) {
|
|
346
|
+
return [...findings].sort(
|
|
347
|
+
(a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] || (a.tool ?? "").localeCompare(b.tool ?? "")
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
function worst(findings) {
|
|
351
|
+
return findings.reduce(
|
|
352
|
+
(w, f) => w === null || SEVERITY_RANK[f.severity] < SEVERITY_RANK[w] ? f.severity : w,
|
|
353
|
+
null
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
var distinctive = (name) => name.length >= 6 && /[_-]|[a-z][A-Z]/.test(name);
|
|
357
|
+
var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
358
|
+
function analyzeStackScan(members) {
|
|
359
|
+
const stack = analyzeStack(
|
|
360
|
+
members.map((m) => ({
|
|
361
|
+
server: m.alias,
|
|
362
|
+
version: null,
|
|
363
|
+
tools: m.snapshot ? m.snapshot.tools.map((t) => ({ name: t.name, annotations: resolveAnnotations(t.annotations) })) : null
|
|
364
|
+
}))
|
|
365
|
+
);
|
|
366
|
+
const findings = stack.collisions.map((c) => ({
|
|
367
|
+
kind: "tool_collision",
|
|
368
|
+
severity: c.writes ? "high" : "moderate",
|
|
369
|
+
tool: c.tool,
|
|
370
|
+
where: "tool namespace",
|
|
371
|
+
detail: `exposed by ${c.servers.join(" and ")}; the agent cannot say which one it means${c.writes ? ", and one of them can modify something" : ""}`,
|
|
372
|
+
evidence: null
|
|
373
|
+
}));
|
|
374
|
+
const read = members.filter((m) => !!m.snapshot);
|
|
375
|
+
for (const owner of read) {
|
|
376
|
+
const foreign = read.filter((m) => m !== owner).flatMap((m) => m.snapshot.tools.filter((t) => distinctive(t.name)).map((t) => ({ server: m.alias, name: t.name }))).filter((f) => !owner.snapshot.tools.some((t) => t.name === f.name));
|
|
377
|
+
if (!foreign.length) continue;
|
|
378
|
+
const pattern = new RegExp(`\\b(${foreign.map((f) => escapeRe(f.name)).join("|")})\\b`);
|
|
379
|
+
for (const tool of owner.snapshot.tools) {
|
|
380
|
+
for (const site of toolTexts(tool)) {
|
|
381
|
+
const m = pattern.exec(site.text);
|
|
382
|
+
if (!m) continue;
|
|
383
|
+
const target = foreign.find((f) => f.name === m[1]);
|
|
384
|
+
const steering = scanText(site).some((f) => f.severity === "high" || f.severity === "critical");
|
|
385
|
+
findings.push({
|
|
386
|
+
kind: "cross_server_reference",
|
|
387
|
+
severity: steering ? "high" : "moderate",
|
|
388
|
+
server: owner.alias,
|
|
389
|
+
tool: tool.name,
|
|
390
|
+
where: site.where,
|
|
391
|
+
detail: `describes ${target.server}'s tool "${target.name}"${steering ? " while instructing the model" : ""}; a server steering another server's tools is the shadowing pattern`,
|
|
392
|
+
evidence: snippet(site.text, m.index, m[0].length)
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return { stack, findings: sortFindings(findings) };
|
|
398
|
+
}
|
|
399
|
+
var findingKey = (f) => `${f.kind}|${f.tool ?? ""}|${f.where}|${f.evidence ?? ""}`;
|
|
400
|
+
var MAX_TEXT_CHANGES = 50;
|
|
401
|
+
function diffSnapshots(prev, next, label = "server") {
|
|
402
|
+
const contract = diffMcpSurfaces(mcpSurface(label, null, prev.tools), mcpSurface(label, null, next.tools));
|
|
403
|
+
const before = new Map(prev.tools.map((t) => [t.name, t]));
|
|
404
|
+
const descriptionChanges = [];
|
|
405
|
+
const capabilitiesGained = [];
|
|
406
|
+
const changedText = /* @__PURE__ */ new Set();
|
|
407
|
+
for (const t of next.tools) {
|
|
408
|
+
const old = before.get(t.name);
|
|
409
|
+
if (!old) continue;
|
|
410
|
+
for (const field of ["description", "title"]) {
|
|
411
|
+
if ((old[field] ?? null) !== (t[field] ?? null)) {
|
|
412
|
+
changedText.add(t.name);
|
|
413
|
+
if (descriptionChanges.length < MAX_TEXT_CHANGES) {
|
|
414
|
+
descriptionChanges.push({ tool: t.name, field, before: old[field] ?? null, after: t[field] ?? null });
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
const had = new Set(toolCapabilities(old).map((h) => h.capability));
|
|
419
|
+
const gained = toolCapabilities(t).map((h) => h.capability).filter((c) => !had.has(c));
|
|
420
|
+
if (gained.length) capabilitiesGained.push({ tool: t.name, capabilities: gained });
|
|
421
|
+
}
|
|
422
|
+
const empty = { issues: [] };
|
|
423
|
+
const prevKeys = new Set(analyzeServer({ ...empty, ...prev }).findings.map(findingKey));
|
|
424
|
+
const newFindings = analyzeServer({ ...empty, ...next }).findings.filter((f) => !prevKeys.has(findingKey(f)));
|
|
425
|
+
const rugPull = [
|
|
426
|
+
...new Set(
|
|
427
|
+
newFindings.filter((f) => f.tool && changedText.has(f.tool) && (f.severity === "high" || f.severity === "critical")).map((f) => f.tool)
|
|
428
|
+
)
|
|
429
|
+
].sort();
|
|
430
|
+
const prevPrompts = new Set(prev.prompts.map((p) => p.name));
|
|
431
|
+
const nextPrompts = new Set(next.prompts.map((p) => p.name));
|
|
432
|
+
const promptsAdded = [...nextPrompts].filter((p) => !prevPrompts.has(p)).sort();
|
|
433
|
+
const promptsRemoved = [...prevPrompts].filter((p) => !nextPrompts.has(p)).sort();
|
|
434
|
+
const instructionsChanged = (prev.instructions ?? null) !== (next.instructions ?? null);
|
|
435
|
+
const writingGained = capabilitiesGained.some((g) => g.capabilities.some((c) => WRITE_CAPABILITIES.has(c)));
|
|
436
|
+
const widened = contract.annotationFlips.some((f) => f.widensPrivilege);
|
|
437
|
+
const findingWorst = worst(newFindings);
|
|
438
|
+
let severity = "info";
|
|
439
|
+
const raise = (s) => {
|
|
440
|
+
if (SEVERITY_RANK[s] < SEVERITY_RANK[severity]) severity = s;
|
|
441
|
+
};
|
|
442
|
+
if (rugPull.length) raise("critical");
|
|
443
|
+
if (findingWorst) raise(findingWorst);
|
|
444
|
+
if (widened || contract.silentDrift.length) raise("high");
|
|
445
|
+
if (contract.breaking || writingGained || instructionsChanged) raise("moderate");
|
|
446
|
+
if (contract.addedTools.length || descriptionChanges.length || promptsAdded.length || promptsRemoved.length || capabilitiesGained.length) {
|
|
447
|
+
raise("low");
|
|
448
|
+
}
|
|
449
|
+
const parts = [];
|
|
450
|
+
if (rugPull.length) parts.push(`${rugPull.length} tool(s) rewrote their description and now instruct the model: ${rugPull.join(", ")}`);
|
|
451
|
+
const drift = contract.inconclusive ? `contract not comparable (${contract.inconclusive})` : summarizeDrift(contract);
|
|
452
|
+
if (drift !== "no contract change") parts.push(drift);
|
|
453
|
+
if (descriptionChanges.length && !rugPull.length) parts.push(`${changedText.size} tool description(s) changed`);
|
|
454
|
+
if (instructionsChanged) parts.push("server instructions changed");
|
|
455
|
+
if (promptsAdded.length) parts.push(`${promptsAdded.length} prompt(s) added`);
|
|
456
|
+
if (promptsRemoved.length) parts.push(`${promptsRemoved.length} prompt(s) removed`);
|
|
457
|
+
if (writingGained) parts.push("a tool gained the ability to modify something");
|
|
458
|
+
const serious = newFindings.filter((f) => f.severity === "critical" || f.severity === "high");
|
|
459
|
+
if (serious.length && !rugPull.length) parts.push(`${serious.length} new high-severity finding(s)`);
|
|
460
|
+
const unchanged = !contract.addedTools.length && !contract.removedTools.length && !contract.silentDrift.length && !contract.annotationFlips.length && !contract.typeChanged.length && !contract.paramsAdded.length && !contract.paramsRemoved.length && !contract.requiredAdded.length && !contract.requiredRelaxed.length && !contract.outputChanged.length && !descriptionChanges.length && !instructionsChanged && !promptsAdded.length && !promptsRemoved.length;
|
|
461
|
+
return {
|
|
462
|
+
contract,
|
|
463
|
+
descriptionChanges,
|
|
464
|
+
instructionsChanged,
|
|
465
|
+
promptsAdded,
|
|
466
|
+
promptsRemoved,
|
|
467
|
+
capabilitiesGained,
|
|
468
|
+
newFindings,
|
|
469
|
+
rugPull,
|
|
470
|
+
severity,
|
|
471
|
+
summary: parts.length ? parts.join("; ") : unchanged ? "no change" : "minor changes",
|
|
472
|
+
unchanged
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// src/mcpScan/redact.ts
|
|
477
|
+
init_esm_shims();
|
|
478
|
+
var SHAPES = [
|
|
479
|
+
/\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{16,}/g,
|
|
480
|
+
/\bgh[pousr]_[A-Za-z0-9]{20,}/g,
|
|
481
|
+
/\bgithub_pat_[A-Za-z0-9_]{20,}/g,
|
|
482
|
+
/\bxox[abpors]-[A-Za-z0-9-]{10,}/g,
|
|
483
|
+
/\bAKIA[0-9A-Z]{16}\b/g,
|
|
484
|
+
/\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}/g,
|
|
485
|
+
/\blurq_(?:live|test)_[A-Za-z0-9_-]{16,}/g,
|
|
486
|
+
/\b(?:sk|rk|pk)_(?:live|test)_[A-Za-z0-9]{16,}/g
|
|
487
|
+
];
|
|
488
|
+
var BEARER = /\b(Bearer|Basic|token)\s+[A-Za-z0-9._~+/=-]{12,}/gi;
|
|
489
|
+
var REDACTED = "[redacted]";
|
|
490
|
+
function looksLikeSecret(value) {
|
|
491
|
+
return SHAPES.some((re) => {
|
|
492
|
+
re.lastIndex = 0;
|
|
493
|
+
const m = re.exec(value);
|
|
494
|
+
return m !== null && m.index === 0 && m[0].length === value.length;
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
function scrub(text2, secrets = []) {
|
|
498
|
+
let out = text2;
|
|
499
|
+
for (const s of secrets) if (s && out.includes(s)) out = out.split(s).join(REDACTED);
|
|
500
|
+
for (const re of SHAPES) out = out.replace(re, REDACTED);
|
|
501
|
+
return out.replace(BEARER, `$1 ${REDACTED}`);
|
|
502
|
+
}
|
|
503
|
+
function scrubDeep(value, secrets = []) {
|
|
504
|
+
if (typeof value === "string") return scrub(value, secrets);
|
|
505
|
+
if (Array.isArray(value)) return value.map((v) => scrubDeep(v, secrets));
|
|
506
|
+
if (value && typeof value === "object") {
|
|
507
|
+
const out = {};
|
|
508
|
+
for (const [k, v] of Object.entries(value)) {
|
|
509
|
+
out[scrub(k, secrets)] = scrubDeep(v, secrets);
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
return value;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// src/mcpScan/snapshot.ts
|
|
517
|
+
init_esm_shims();
|
|
518
|
+
import { createHash } from "crypto";
|
|
519
|
+
var LIMITS = {
|
|
520
|
+
tools: 2e3,
|
|
521
|
+
prompts: 1e3,
|
|
522
|
+
resourceTemplates: 1e3,
|
|
523
|
+
/** `resources/list` is paged only to count; URIs are the user's data, never kept. */
|
|
524
|
+
resourcePages: 50,
|
|
525
|
+
pages: 100,
|
|
526
|
+
name: 256,
|
|
527
|
+
text: 32e3,
|
|
528
|
+
instructions: 32e3,
|
|
529
|
+
schemaBytes: 2e5,
|
|
530
|
+
schemaDepth: 64
|
|
531
|
+
};
|
|
532
|
+
var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
533
|
+
function text(v, max, issues, list, where) {
|
|
534
|
+
if (typeof v !== "string") return void 0;
|
|
535
|
+
if (v.length <= max) return v;
|
|
536
|
+
issues.push({ list, kind: "oversized", detail: `${where}: ${v.length} chars, kept the first ${max}` });
|
|
537
|
+
return v.slice(0, max);
|
|
538
|
+
}
|
|
539
|
+
function depthOf(value, limit) {
|
|
540
|
+
let max = 0;
|
|
541
|
+
const stack = [[value, 1]];
|
|
542
|
+
while (stack.length) {
|
|
543
|
+
const [v, d] = stack.pop();
|
|
544
|
+
if (d > max) max = d;
|
|
545
|
+
if (max > limit) return max;
|
|
546
|
+
if (v && typeof v === "object") {
|
|
547
|
+
for (const child of Array.isArray(v) ? v : Object.values(v)) {
|
|
548
|
+
if (child && typeof child === "object") stack.push([child, d + 1]);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return max;
|
|
553
|
+
}
|
|
554
|
+
function schema(v, issues, list, where) {
|
|
555
|
+
if (v === void 0 || v === null) return void 0;
|
|
556
|
+
const depth = depthOf(v, LIMITS.schemaDepth);
|
|
557
|
+
if (depth > LIMITS.schemaDepth) {
|
|
558
|
+
issues.push({ list, kind: "oversized", detail: `${where}: nested deeper than ${LIMITS.schemaDepth} levels` });
|
|
559
|
+
return { "x-lurq-omitted": `schema deeper than ${LIMITS.schemaDepth} levels` };
|
|
560
|
+
}
|
|
561
|
+
const bytes = JSON.stringify(v).length;
|
|
562
|
+
if (bytes > LIMITS.schemaBytes) {
|
|
563
|
+
issues.push({ list, kind: "oversized", detail: `${where}: ${bytes} bytes` });
|
|
564
|
+
return { "x-lurq-omitted": `schema larger than ${LIMITS.schemaBytes} bytes` };
|
|
565
|
+
}
|
|
566
|
+
return v;
|
|
567
|
+
}
|
|
568
|
+
var HINTS = ["readOnlyHint", "destructiveHint", "idempotentHint", "openWorldHint"];
|
|
569
|
+
function annotations(v) {
|
|
570
|
+
if (!isObj(v)) return void 0;
|
|
571
|
+
const out = {};
|
|
572
|
+
for (const h of HINTS) if (typeof v[h] === "boolean") out[h] = v[h];
|
|
573
|
+
if (typeof v.title === "string") out.title = v.title.slice(0, LIMITS.name);
|
|
574
|
+
return Object.keys(out).length ? out : void 0;
|
|
575
|
+
}
|
|
576
|
+
function each(raw, list, seen, issues, cap, build) {
|
|
577
|
+
for (let i = 0; i < raw.length; i++) {
|
|
578
|
+
const entry = raw[i];
|
|
579
|
+
if (!isObj(entry) || typeof entry.name !== "string" || !entry.name.trim()) {
|
|
580
|
+
issues.push({ list, kind: "malformed", detail: `entry ${i} has no string name` });
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
const name = entry.name.trim();
|
|
584
|
+
if (name.length > LIMITS.name) {
|
|
585
|
+
issues.push({ list, kind: "malformed", detail: `a name is ${name.length} chars (limit ${LIMITS.name})` });
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
if (seen.has(name)) {
|
|
589
|
+
issues.push({ list, kind: "duplicate", detail: `"${name}" is listed more than once` });
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (seen.size >= cap) {
|
|
593
|
+
issues.push({ list, kind: "truncated", detail: `more than ${cap} entries; the rest were not recorded` });
|
|
594
|
+
return false;
|
|
595
|
+
}
|
|
596
|
+
const built = build(entry, name);
|
|
597
|
+
if (built) seen.set(name, built);
|
|
598
|
+
}
|
|
599
|
+
return true;
|
|
600
|
+
}
|
|
601
|
+
function addTools(raw, seen, issues) {
|
|
602
|
+
return each(raw, "tools", seen, issues, LIMITS.tools, (e, name) => {
|
|
603
|
+
const tool = { name };
|
|
604
|
+
const title = text(e.title, LIMITS.name, issues, "tools", `${name}.title`);
|
|
605
|
+
const description = text(e.description, LIMITS.text, issues, "tools", `${name}.description`);
|
|
606
|
+
const input = schema(e.inputSchema, issues, "tools", `${name}.inputSchema`);
|
|
607
|
+
const output = schema(e.outputSchema, issues, "tools", `${name}.outputSchema`);
|
|
608
|
+
const ann = annotations(e.annotations);
|
|
609
|
+
if (title !== void 0) tool.title = title;
|
|
610
|
+
if (description !== void 0) tool.description = description;
|
|
611
|
+
if (input !== void 0) tool.inputSchema = input;
|
|
612
|
+
if (output !== void 0) tool.outputSchema = output;
|
|
613
|
+
if (ann) tool.annotations = ann;
|
|
614
|
+
return tool;
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
function addPrompts(raw, seen, issues) {
|
|
618
|
+
return each(raw, "prompts", seen, issues, LIMITS.prompts, (e, name) => {
|
|
619
|
+
const args = Array.isArray(e.arguments) ? e.arguments : [];
|
|
620
|
+
const prompt = {
|
|
621
|
+
name,
|
|
622
|
+
arguments: args.filter(isObj).flatMap(
|
|
623
|
+
(a) => typeof a.name === "string" ? [
|
|
624
|
+
{
|
|
625
|
+
name: a.name.slice(0, LIMITS.name),
|
|
626
|
+
...typeof a.description === "string" ? { description: a.description.slice(0, LIMITS.text) } : {},
|
|
627
|
+
required: a.required === true
|
|
628
|
+
}
|
|
629
|
+
] : []
|
|
630
|
+
)
|
|
631
|
+
};
|
|
632
|
+
const title = text(e.title, LIMITS.name, issues, "prompts", `${name}.title`);
|
|
633
|
+
const description = text(e.description, LIMITS.text, issues, "prompts", `${name}.description`);
|
|
634
|
+
if (title !== void 0) prompt.title = title;
|
|
635
|
+
if (description !== void 0) prompt.description = description;
|
|
636
|
+
return prompt;
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
function addTemplates(raw, seen, issues) {
|
|
640
|
+
return each(raw, "resourceTemplates", seen, issues, LIMITS.resourceTemplates, (e, name) => {
|
|
641
|
+
if (typeof e.uriTemplate !== "string") {
|
|
642
|
+
issues.push({ list: "resourceTemplates", kind: "malformed", detail: `"${name}" has no uriTemplate` });
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
const t = { name, uriTemplate: e.uriTemplate.slice(0, 2048) };
|
|
646
|
+
const title = text(e.title, LIMITS.name, issues, "resourceTemplates", `${name}.title`);
|
|
647
|
+
const description = text(e.description, LIMITS.text, issues, "resourceTemplates", `${name}.description`);
|
|
648
|
+
if (title !== void 0) t.title = title;
|
|
649
|
+
if (description !== void 0) t.description = description;
|
|
650
|
+
if (typeof e.mimeType === "string") t.mimeType = e.mimeType.slice(0, 200);
|
|
651
|
+
return t;
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
var sha = (s) => createHash("sha256").update(s).digest("hex");
|
|
655
|
+
var byName = (xs) => [...xs].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
|
|
656
|
+
function canonicalJson(value) {
|
|
657
|
+
return JSON.stringify(
|
|
658
|
+
value,
|
|
659
|
+
(_k, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.keys(v).sort().map((k) => [k, v[k]])) : v
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
function contractHash(s) {
|
|
663
|
+
return surfaceHash(s.tools);
|
|
664
|
+
}
|
|
665
|
+
function contentHash(s) {
|
|
666
|
+
return sha(
|
|
667
|
+
canonicalJson({
|
|
668
|
+
tools: byName(s.tools),
|
|
669
|
+
prompts: byName(s.prompts),
|
|
670
|
+
resourceTemplates: byName(s.resourceTemplates),
|
|
671
|
+
instructions: s.instructions ?? null
|
|
672
|
+
})
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
function emptySnapshot() {
|
|
676
|
+
return {
|
|
677
|
+
serverInfo: { name: null, version: null, title: null },
|
|
678
|
+
protocolVersion: null,
|
|
679
|
+
capabilities: {
|
|
680
|
+
tools: false,
|
|
681
|
+
prompts: false,
|
|
682
|
+
resources: false,
|
|
683
|
+
logging: false,
|
|
684
|
+
completions: false,
|
|
685
|
+
toolsListChanged: false
|
|
686
|
+
},
|
|
687
|
+
instructions: null,
|
|
688
|
+
tools: [],
|
|
689
|
+
prompts: [],
|
|
690
|
+
resourceTemplates: [],
|
|
691
|
+
resourceCount: null,
|
|
692
|
+
issues: []
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
|
|
697
|
+
init_esm_shims();
|
|
698
|
+
|
|
699
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/client.js
|
|
700
|
+
init_esm_shims();
|
|
701
|
+
var ExperimentalClientTasks = class {
|
|
702
|
+
constructor(_client) {
|
|
703
|
+
this._client = _client;
|
|
704
|
+
}
|
|
705
|
+
/**
|
|
706
|
+
* Calls a tool and returns an AsyncGenerator that yields response messages.
|
|
707
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
708
|
+
*
|
|
709
|
+
* This method provides streaming access to tool execution, allowing you to
|
|
710
|
+
* observe intermediate task status updates for long-running tool calls.
|
|
711
|
+
* Automatically validates structured output if the tool has an outputSchema.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* ```typescript
|
|
715
|
+
* const stream = client.experimental.tasks.callToolStream({ name: 'myTool', arguments: {} });
|
|
716
|
+
* for await (const message of stream) {
|
|
717
|
+
* switch (message.type) {
|
|
718
|
+
* case 'taskCreated':
|
|
719
|
+
* console.log('Tool execution started:', message.task.taskId);
|
|
720
|
+
* break;
|
|
721
|
+
* case 'taskStatus':
|
|
722
|
+
* console.log('Tool status:', message.task.status);
|
|
723
|
+
* break;
|
|
724
|
+
* case 'result':
|
|
725
|
+
* console.log('Tool result:', message.result);
|
|
726
|
+
* break;
|
|
727
|
+
* case 'error':
|
|
728
|
+
* console.error('Tool error:', message.error);
|
|
729
|
+
* break;
|
|
730
|
+
* }
|
|
731
|
+
* }
|
|
732
|
+
* ```
|
|
733
|
+
*
|
|
734
|
+
* @param params - Tool call parameters (name and arguments)
|
|
735
|
+
* @param resultSchema - Zod schema for validating the result (defaults to CallToolResultSchema)
|
|
736
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
737
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
738
|
+
*
|
|
739
|
+
* @experimental
|
|
740
|
+
*/
|
|
741
|
+
async *callToolStream(params, resultSchema = CallToolResultSchema, options) {
|
|
742
|
+
const clientInternal = this._client;
|
|
743
|
+
const optionsWithTask = {
|
|
744
|
+
...options,
|
|
745
|
+
// We check if the tool is known to be a task during auto-configuration, but assume
|
|
746
|
+
// the caller knows what they're doing if they pass this explicitly
|
|
747
|
+
task: options?.task ?? (clientInternal.isToolTask(params.name) ? {} : void 0)
|
|
748
|
+
};
|
|
749
|
+
const stream = clientInternal.requestStream({ method: "tools/call", params }, resultSchema, optionsWithTask);
|
|
750
|
+
const validator = clientInternal.getToolOutputValidator(params.name);
|
|
751
|
+
for await (const message of stream) {
|
|
752
|
+
if (message.type === "result" && validator) {
|
|
753
|
+
const result = message.result;
|
|
754
|
+
if (!result.structuredContent && !result.isError) {
|
|
755
|
+
yield {
|
|
756
|
+
type: "error",
|
|
757
|
+
error: new McpError(ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`)
|
|
758
|
+
};
|
|
759
|
+
return;
|
|
760
|
+
}
|
|
761
|
+
if (result.structuredContent) {
|
|
762
|
+
try {
|
|
763
|
+
const validationResult = validator(result.structuredContent);
|
|
764
|
+
if (!validationResult.valid) {
|
|
765
|
+
yield {
|
|
766
|
+
type: "error",
|
|
767
|
+
error: new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`)
|
|
768
|
+
};
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
771
|
+
} catch (error) {
|
|
772
|
+
if (error instanceof McpError) {
|
|
773
|
+
yield { type: "error", error };
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
yield {
|
|
777
|
+
type: "error",
|
|
778
|
+
error: new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`)
|
|
779
|
+
};
|
|
780
|
+
return;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
yield message;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Gets the current status of a task.
|
|
789
|
+
*
|
|
790
|
+
* @param taskId - The task identifier
|
|
791
|
+
* @param options - Optional request options
|
|
792
|
+
* @returns The task status
|
|
793
|
+
*
|
|
794
|
+
* @experimental
|
|
795
|
+
*/
|
|
796
|
+
async getTask(taskId, options) {
|
|
797
|
+
return this._client.getTask({ taskId }, options);
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Retrieves the result of a completed task.
|
|
801
|
+
*
|
|
802
|
+
* @param taskId - The task identifier
|
|
803
|
+
* @param resultSchema - Zod schema for validating the result
|
|
804
|
+
* @param options - Optional request options
|
|
805
|
+
* @returns The task result
|
|
806
|
+
*
|
|
807
|
+
* @experimental
|
|
808
|
+
*/
|
|
809
|
+
async getTaskResult(taskId, resultSchema, options) {
|
|
810
|
+
return this._client.getTaskResult({ taskId }, resultSchema, options);
|
|
811
|
+
}
|
|
812
|
+
/**
|
|
813
|
+
* Lists tasks with optional pagination.
|
|
814
|
+
*
|
|
815
|
+
* @param cursor - Optional pagination cursor
|
|
816
|
+
* @param options - Optional request options
|
|
817
|
+
* @returns List of tasks with optional next cursor
|
|
818
|
+
*
|
|
819
|
+
* @experimental
|
|
820
|
+
*/
|
|
821
|
+
async listTasks(cursor, options) {
|
|
822
|
+
return this._client.listTasks(cursor ? { cursor } : void 0, options);
|
|
823
|
+
}
|
|
824
|
+
/**
|
|
825
|
+
* Cancels a running task.
|
|
826
|
+
*
|
|
827
|
+
* @param taskId - The task identifier
|
|
828
|
+
* @param options - Optional request options
|
|
829
|
+
*
|
|
830
|
+
* @experimental
|
|
831
|
+
*/
|
|
832
|
+
async cancelTask(taskId, options) {
|
|
833
|
+
return this._client.cancelTask({ taskId }, options);
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Sends a request and returns an AsyncGenerator that yields response messages.
|
|
837
|
+
* The generator is guaranteed to end with either a 'result' or 'error' message.
|
|
838
|
+
*
|
|
839
|
+
* This method provides streaming access to request processing, allowing you to
|
|
840
|
+
* observe intermediate task status updates for task-augmented requests.
|
|
841
|
+
*
|
|
842
|
+
* @param request - The request to send
|
|
843
|
+
* @param resultSchema - Zod schema for validating the result
|
|
844
|
+
* @param options - Optional request options (timeout, signal, task creation params, etc.)
|
|
845
|
+
* @returns AsyncGenerator that yields ResponseMessage objects
|
|
846
|
+
*
|
|
847
|
+
* @experimental
|
|
848
|
+
*/
|
|
849
|
+
requestStream(request, resultSchema, options) {
|
|
850
|
+
return this._client.requestStream(request, resultSchema, options);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
// node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
|
|
855
|
+
function applyElicitationDefaults(schema2, data) {
|
|
856
|
+
if (!schema2 || data === null || typeof data !== "object")
|
|
857
|
+
return;
|
|
858
|
+
if (schema2.type === "object" && schema2.properties && typeof schema2.properties === "object") {
|
|
859
|
+
const obj = data;
|
|
860
|
+
const props = schema2.properties;
|
|
861
|
+
for (const key of Object.keys(props)) {
|
|
862
|
+
const propSchema = props[key];
|
|
863
|
+
if (obj[key] === void 0 && Object.prototype.hasOwnProperty.call(propSchema, "default")) {
|
|
864
|
+
obj[key] = propSchema.default;
|
|
865
|
+
}
|
|
866
|
+
if (obj[key] !== void 0) {
|
|
867
|
+
applyElicitationDefaults(propSchema, obj[key]);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
if (Array.isArray(schema2.anyOf)) {
|
|
872
|
+
for (const sub of schema2.anyOf) {
|
|
873
|
+
if (typeof sub !== "boolean") {
|
|
874
|
+
applyElicitationDefaults(sub, data);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
if (Array.isArray(schema2.oneOf)) {
|
|
879
|
+
for (const sub of schema2.oneOf) {
|
|
880
|
+
if (typeof sub !== "boolean") {
|
|
881
|
+
applyElicitationDefaults(sub, data);
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function getSupportedElicitationModes(capabilities) {
|
|
887
|
+
if (!capabilities) {
|
|
888
|
+
return { supportsFormMode: false, supportsUrlMode: false };
|
|
889
|
+
}
|
|
890
|
+
const hasFormCapability = capabilities.form !== void 0;
|
|
891
|
+
const hasUrlCapability = capabilities.url !== void 0;
|
|
892
|
+
const supportsFormMode = hasFormCapability || !hasFormCapability && !hasUrlCapability;
|
|
893
|
+
const supportsUrlMode = hasUrlCapability;
|
|
894
|
+
return { supportsFormMode, supportsUrlMode };
|
|
895
|
+
}
|
|
896
|
+
var Client = class extends Protocol {
|
|
897
|
+
/**
|
|
898
|
+
* Initializes this client with the given name and version information.
|
|
899
|
+
*/
|
|
900
|
+
constructor(_clientInfo, options) {
|
|
901
|
+
super(options);
|
|
902
|
+
this._clientInfo = _clientInfo;
|
|
903
|
+
this._cachedToolOutputValidators = /* @__PURE__ */ new Map();
|
|
904
|
+
this._cachedKnownTaskTools = /* @__PURE__ */ new Set();
|
|
905
|
+
this._cachedRequiredTaskTools = /* @__PURE__ */ new Set();
|
|
906
|
+
this._listChangedDebounceTimers = /* @__PURE__ */ new Map();
|
|
907
|
+
this._capabilities = options?.capabilities ?? {};
|
|
908
|
+
this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
|
|
909
|
+
if (options?.listChanged) {
|
|
910
|
+
this._pendingListChangedConfig = options.listChanged;
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Set up handlers for list changed notifications based on config and server capabilities.
|
|
915
|
+
* This should only be called after initialization when server capabilities are known.
|
|
916
|
+
* Handlers are silently skipped if the server doesn't advertise the corresponding listChanged capability.
|
|
917
|
+
* @internal
|
|
918
|
+
*/
|
|
919
|
+
_setupListChangedHandlers(config) {
|
|
920
|
+
if (config.tools && this._serverCapabilities?.tools?.listChanged) {
|
|
921
|
+
this._setupListChangedHandler("tools", ToolListChangedNotificationSchema, config.tools, async () => {
|
|
922
|
+
const result = await this.listTools();
|
|
923
|
+
return result.tools;
|
|
924
|
+
});
|
|
925
|
+
}
|
|
926
|
+
if (config.prompts && this._serverCapabilities?.prompts?.listChanged) {
|
|
927
|
+
this._setupListChangedHandler("prompts", PromptListChangedNotificationSchema, config.prompts, async () => {
|
|
928
|
+
const result = await this.listPrompts();
|
|
929
|
+
return result.prompts;
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
if (config.resources && this._serverCapabilities?.resources?.listChanged) {
|
|
933
|
+
this._setupListChangedHandler("resources", ResourceListChangedNotificationSchema, config.resources, async () => {
|
|
934
|
+
const result = await this.listResources();
|
|
935
|
+
return result.resources;
|
|
936
|
+
});
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Access experimental features.
|
|
941
|
+
*
|
|
942
|
+
* WARNING: These APIs are experimental and may change without notice.
|
|
943
|
+
*
|
|
944
|
+
* @experimental
|
|
945
|
+
*/
|
|
946
|
+
get experimental() {
|
|
947
|
+
if (!this._experimental) {
|
|
948
|
+
this._experimental = {
|
|
949
|
+
tasks: new ExperimentalClientTasks(this)
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
return this._experimental;
|
|
953
|
+
}
|
|
954
|
+
/**
|
|
955
|
+
* Registers new capabilities. This can only be called before connecting to a transport.
|
|
956
|
+
*
|
|
957
|
+
* The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
|
|
958
|
+
*/
|
|
959
|
+
registerCapabilities(capabilities) {
|
|
960
|
+
if (this.transport) {
|
|
961
|
+
throw new Error("Cannot register capabilities after connecting to transport");
|
|
962
|
+
}
|
|
963
|
+
this._capabilities = mergeCapabilities(this._capabilities, capabilities);
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Override request handler registration to enforce client-side validation for elicitation.
|
|
967
|
+
*/
|
|
968
|
+
setRequestHandler(requestSchema, handler) {
|
|
969
|
+
const shape = getObjectShape(requestSchema);
|
|
970
|
+
const methodSchema = shape?.method;
|
|
971
|
+
if (!methodSchema) {
|
|
972
|
+
throw new Error("Schema is missing a method literal");
|
|
973
|
+
}
|
|
974
|
+
let methodValue;
|
|
975
|
+
if (isZ4Schema(methodSchema)) {
|
|
976
|
+
const v4Schema = methodSchema;
|
|
977
|
+
const v4Def = v4Schema._zod?.def;
|
|
978
|
+
methodValue = v4Def?.value ?? v4Schema.value;
|
|
979
|
+
} else {
|
|
980
|
+
const v3Schema = methodSchema;
|
|
981
|
+
const legacyDef = v3Schema._def;
|
|
982
|
+
methodValue = legacyDef?.value ?? v3Schema.value;
|
|
983
|
+
}
|
|
984
|
+
if (typeof methodValue !== "string") {
|
|
985
|
+
throw new Error("Schema method literal must be a string");
|
|
986
|
+
}
|
|
987
|
+
const method = methodValue;
|
|
988
|
+
if (method === "elicitation/create") {
|
|
989
|
+
const wrappedHandler = async (request, extra) => {
|
|
990
|
+
const validatedRequest = safeParse(ElicitRequestSchema, request);
|
|
991
|
+
if (!validatedRequest.success) {
|
|
992
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
993
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation request: ${errorMessage}`);
|
|
994
|
+
}
|
|
995
|
+
const { params } = validatedRequest.data;
|
|
996
|
+
params.mode = params.mode ?? "form";
|
|
997
|
+
const { supportsFormMode, supportsUrlMode } = getSupportedElicitationModes(this._capabilities.elicitation);
|
|
998
|
+
if (params.mode === "form" && !supportsFormMode) {
|
|
999
|
+
throw new McpError(ErrorCode.InvalidParams, "Client does not support form-mode elicitation requests");
|
|
1000
|
+
}
|
|
1001
|
+
if (params.mode === "url" && !supportsUrlMode) {
|
|
1002
|
+
throw new McpError(ErrorCode.InvalidParams, "Client does not support URL-mode elicitation requests");
|
|
1003
|
+
}
|
|
1004
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
1005
|
+
if (params.task) {
|
|
1006
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
1007
|
+
if (!taskValidationResult.success) {
|
|
1008
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
1009
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
1010
|
+
}
|
|
1011
|
+
return taskValidationResult.data;
|
|
1012
|
+
}
|
|
1013
|
+
const validationResult = safeParse(ElicitResultSchema, result);
|
|
1014
|
+
if (!validationResult.success) {
|
|
1015
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
1016
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid elicitation result: ${errorMessage}`);
|
|
1017
|
+
}
|
|
1018
|
+
const validatedResult = validationResult.data;
|
|
1019
|
+
const requestedSchema = params.mode === "form" ? params.requestedSchema : void 0;
|
|
1020
|
+
if (params.mode === "form" && validatedResult.action === "accept" && validatedResult.content && requestedSchema) {
|
|
1021
|
+
if (this._capabilities.elicitation?.form?.applyDefaults) {
|
|
1022
|
+
try {
|
|
1023
|
+
applyElicitationDefaults(requestedSchema, validatedResult.content);
|
|
1024
|
+
} catch {
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
return validatedResult;
|
|
1029
|
+
};
|
|
1030
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
1031
|
+
}
|
|
1032
|
+
if (method === "sampling/createMessage") {
|
|
1033
|
+
const wrappedHandler = async (request, extra) => {
|
|
1034
|
+
const validatedRequest = safeParse(CreateMessageRequestSchema, request);
|
|
1035
|
+
if (!validatedRequest.success) {
|
|
1036
|
+
const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
|
|
1037
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling request: ${errorMessage}`);
|
|
1038
|
+
}
|
|
1039
|
+
const { params } = validatedRequest.data;
|
|
1040
|
+
const result = await Promise.resolve(handler(request, extra));
|
|
1041
|
+
if (params.task) {
|
|
1042
|
+
const taskValidationResult = safeParse(CreateTaskResultSchema, result);
|
|
1043
|
+
if (!taskValidationResult.success) {
|
|
1044
|
+
const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
|
|
1045
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
|
|
1046
|
+
}
|
|
1047
|
+
return taskValidationResult.data;
|
|
1048
|
+
}
|
|
1049
|
+
const hasTools = params.tools || params.toolChoice;
|
|
1050
|
+
const resultSchema = hasTools ? CreateMessageResultWithToolsSchema : CreateMessageResultSchema;
|
|
1051
|
+
const validationResult = safeParse(resultSchema, result);
|
|
1052
|
+
if (!validationResult.success) {
|
|
1053
|
+
const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
|
|
1054
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid sampling result: ${errorMessage}`);
|
|
1055
|
+
}
|
|
1056
|
+
return validationResult.data;
|
|
1057
|
+
};
|
|
1058
|
+
return super.setRequestHandler(requestSchema, wrappedHandler);
|
|
1059
|
+
}
|
|
1060
|
+
return super.setRequestHandler(requestSchema, handler);
|
|
1061
|
+
}
|
|
1062
|
+
assertCapability(capability, method) {
|
|
1063
|
+
if (!this._serverCapabilities?.[capability]) {
|
|
1064
|
+
throw new Error(`Server does not support ${capability} (required for ${method})`);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
async connect(transport, options) {
|
|
1068
|
+
await super.connect(transport);
|
|
1069
|
+
if (transport.sessionId !== void 0) {
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
try {
|
|
1073
|
+
const result = await this.request({
|
|
1074
|
+
method: "initialize",
|
|
1075
|
+
params: {
|
|
1076
|
+
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
1077
|
+
capabilities: this._capabilities,
|
|
1078
|
+
clientInfo: this._clientInfo
|
|
1079
|
+
}
|
|
1080
|
+
}, InitializeResultSchema, options);
|
|
1081
|
+
if (result === void 0) {
|
|
1082
|
+
throw new Error(`Server sent invalid initialize result: ${result}`);
|
|
1083
|
+
}
|
|
1084
|
+
if (!SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion)) {
|
|
1085
|
+
throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`);
|
|
1086
|
+
}
|
|
1087
|
+
this._serverCapabilities = result.capabilities;
|
|
1088
|
+
this._serverVersion = result.serverInfo;
|
|
1089
|
+
if (transport.setProtocolVersion) {
|
|
1090
|
+
transport.setProtocolVersion(result.protocolVersion);
|
|
1091
|
+
}
|
|
1092
|
+
this._instructions = result.instructions;
|
|
1093
|
+
await this.notification({
|
|
1094
|
+
method: "notifications/initialized"
|
|
1095
|
+
});
|
|
1096
|
+
if (this._pendingListChangedConfig) {
|
|
1097
|
+
this._setupListChangedHandlers(this._pendingListChangedConfig);
|
|
1098
|
+
this._pendingListChangedConfig = void 0;
|
|
1099
|
+
}
|
|
1100
|
+
} catch (error) {
|
|
1101
|
+
void this.close();
|
|
1102
|
+
throw error;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* After initialization has completed, this will be populated with the server's reported capabilities.
|
|
1107
|
+
*/
|
|
1108
|
+
getServerCapabilities() {
|
|
1109
|
+
return this._serverCapabilities;
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* After initialization has completed, this will be populated with information about the server's name and version.
|
|
1113
|
+
*/
|
|
1114
|
+
getServerVersion() {
|
|
1115
|
+
return this._serverVersion;
|
|
1116
|
+
}
|
|
1117
|
+
/**
|
|
1118
|
+
* After initialization has completed, this may be populated with information about the server's instructions.
|
|
1119
|
+
*/
|
|
1120
|
+
getInstructions() {
|
|
1121
|
+
return this._instructions;
|
|
1122
|
+
}
|
|
1123
|
+
assertCapabilityForMethod(method) {
|
|
1124
|
+
switch (method) {
|
|
1125
|
+
case "logging/setLevel":
|
|
1126
|
+
if (!this._serverCapabilities?.logging) {
|
|
1127
|
+
throw new Error(`Server does not support logging (required for ${method})`);
|
|
1128
|
+
}
|
|
1129
|
+
break;
|
|
1130
|
+
case "prompts/get":
|
|
1131
|
+
case "prompts/list":
|
|
1132
|
+
if (!this._serverCapabilities?.prompts) {
|
|
1133
|
+
throw new Error(`Server does not support prompts (required for ${method})`);
|
|
1134
|
+
}
|
|
1135
|
+
break;
|
|
1136
|
+
case "resources/list":
|
|
1137
|
+
case "resources/templates/list":
|
|
1138
|
+
case "resources/read":
|
|
1139
|
+
case "resources/subscribe":
|
|
1140
|
+
case "resources/unsubscribe":
|
|
1141
|
+
if (!this._serverCapabilities?.resources) {
|
|
1142
|
+
throw new Error(`Server does not support resources (required for ${method})`);
|
|
1143
|
+
}
|
|
1144
|
+
if (method === "resources/subscribe" && !this._serverCapabilities.resources.subscribe) {
|
|
1145
|
+
throw new Error(`Server does not support resource subscriptions (required for ${method})`);
|
|
1146
|
+
}
|
|
1147
|
+
break;
|
|
1148
|
+
case "tools/call":
|
|
1149
|
+
case "tools/list":
|
|
1150
|
+
if (!this._serverCapabilities?.tools) {
|
|
1151
|
+
throw new Error(`Server does not support tools (required for ${method})`);
|
|
1152
|
+
}
|
|
1153
|
+
break;
|
|
1154
|
+
case "completion/complete":
|
|
1155
|
+
if (!this._serverCapabilities?.completions) {
|
|
1156
|
+
throw new Error(`Server does not support completions (required for ${method})`);
|
|
1157
|
+
}
|
|
1158
|
+
break;
|
|
1159
|
+
case "initialize":
|
|
1160
|
+
break;
|
|
1161
|
+
case "ping":
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
assertNotificationCapability(method) {
|
|
1166
|
+
switch (method) {
|
|
1167
|
+
case "notifications/roots/list_changed":
|
|
1168
|
+
if (!this._capabilities.roots?.listChanged) {
|
|
1169
|
+
throw new Error(`Client does not support roots list changed notifications (required for ${method})`);
|
|
1170
|
+
}
|
|
1171
|
+
break;
|
|
1172
|
+
case "notifications/initialized":
|
|
1173
|
+
break;
|
|
1174
|
+
case "notifications/cancelled":
|
|
1175
|
+
break;
|
|
1176
|
+
case "notifications/progress":
|
|
1177
|
+
break;
|
|
1178
|
+
}
|
|
1179
|
+
}
|
|
1180
|
+
assertRequestHandlerCapability(method) {
|
|
1181
|
+
if (!this._capabilities) {
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
switch (method) {
|
|
1185
|
+
case "sampling/createMessage":
|
|
1186
|
+
if (!this._capabilities.sampling) {
|
|
1187
|
+
throw new Error(`Client does not support sampling capability (required for ${method})`);
|
|
1188
|
+
}
|
|
1189
|
+
break;
|
|
1190
|
+
case "elicitation/create":
|
|
1191
|
+
if (!this._capabilities.elicitation) {
|
|
1192
|
+
throw new Error(`Client does not support elicitation capability (required for ${method})`);
|
|
1193
|
+
}
|
|
1194
|
+
break;
|
|
1195
|
+
case "roots/list":
|
|
1196
|
+
if (!this._capabilities.roots) {
|
|
1197
|
+
throw new Error(`Client does not support roots capability (required for ${method})`);
|
|
1198
|
+
}
|
|
1199
|
+
break;
|
|
1200
|
+
case "tasks/get":
|
|
1201
|
+
case "tasks/list":
|
|
1202
|
+
case "tasks/result":
|
|
1203
|
+
case "tasks/cancel":
|
|
1204
|
+
if (!this._capabilities.tasks) {
|
|
1205
|
+
throw new Error(`Client does not support tasks capability (required for ${method})`);
|
|
1206
|
+
}
|
|
1207
|
+
break;
|
|
1208
|
+
case "ping":
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
assertTaskCapability(method) {
|
|
1213
|
+
assertToolsCallTaskCapability(this._serverCapabilities?.tasks?.requests, method, "Server");
|
|
1214
|
+
}
|
|
1215
|
+
assertTaskHandlerCapability(method) {
|
|
1216
|
+
if (!this._capabilities) {
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
assertClientRequestTaskCapability(this._capabilities.tasks?.requests, method, "Client");
|
|
1220
|
+
}
|
|
1221
|
+
async ping(options) {
|
|
1222
|
+
return this.request({ method: "ping" }, EmptyResultSchema, options);
|
|
1223
|
+
}
|
|
1224
|
+
async complete(params, options) {
|
|
1225
|
+
return this.request({ method: "completion/complete", params }, CompleteResultSchema, options);
|
|
1226
|
+
}
|
|
1227
|
+
async setLoggingLevel(level, options) {
|
|
1228
|
+
return this.request({ method: "logging/setLevel", params: { level } }, EmptyResultSchema, options);
|
|
1229
|
+
}
|
|
1230
|
+
async getPrompt(params, options) {
|
|
1231
|
+
return this.request({ method: "prompts/get", params }, GetPromptResultSchema, options);
|
|
1232
|
+
}
|
|
1233
|
+
async listPrompts(params, options) {
|
|
1234
|
+
return this.request({ method: "prompts/list", params }, ListPromptsResultSchema, options);
|
|
1235
|
+
}
|
|
1236
|
+
async listResources(params, options) {
|
|
1237
|
+
return this.request({ method: "resources/list", params }, ListResourcesResultSchema, options);
|
|
1238
|
+
}
|
|
1239
|
+
async listResourceTemplates(params, options) {
|
|
1240
|
+
return this.request({ method: "resources/templates/list", params }, ListResourceTemplatesResultSchema, options);
|
|
1241
|
+
}
|
|
1242
|
+
async readResource(params, options) {
|
|
1243
|
+
return this.request({ method: "resources/read", params }, ReadResourceResultSchema, options);
|
|
1244
|
+
}
|
|
1245
|
+
async subscribeResource(params, options) {
|
|
1246
|
+
return this.request({ method: "resources/subscribe", params }, EmptyResultSchema, options);
|
|
1247
|
+
}
|
|
1248
|
+
async unsubscribeResource(params, options) {
|
|
1249
|
+
return this.request({ method: "resources/unsubscribe", params }, EmptyResultSchema, options);
|
|
1250
|
+
}
|
|
1251
|
+
/**
|
|
1252
|
+
* Calls a tool and waits for the result. Automatically validates structured output if the tool has an outputSchema.
|
|
1253
|
+
*
|
|
1254
|
+
* For task-based execution with streaming behavior, use client.experimental.tasks.callToolStream() instead.
|
|
1255
|
+
*/
|
|
1256
|
+
async callTool(params, resultSchema = CallToolResultSchema, options) {
|
|
1257
|
+
if (this.isToolTaskRequired(params.name)) {
|
|
1258
|
+
throw new McpError(ErrorCode.InvalidRequest, `Tool "${params.name}" requires task-based execution. Use client.experimental.tasks.callToolStream() instead.`);
|
|
1259
|
+
}
|
|
1260
|
+
const result = await this.request({ method: "tools/call", params }, resultSchema, options);
|
|
1261
|
+
const validator = this.getToolOutputValidator(params.name);
|
|
1262
|
+
if (validator) {
|
|
1263
|
+
if (!result.structuredContent && !result.isError) {
|
|
1264
|
+
throw new McpError(ErrorCode.InvalidRequest, `Tool ${params.name} has an output schema but did not return structured content`);
|
|
1265
|
+
}
|
|
1266
|
+
if (result.structuredContent) {
|
|
1267
|
+
try {
|
|
1268
|
+
const validationResult = validator(result.structuredContent);
|
|
1269
|
+
if (!validationResult.valid) {
|
|
1270
|
+
throw new McpError(ErrorCode.InvalidParams, `Structured content does not match the tool's output schema: ${validationResult.errorMessage}`);
|
|
1271
|
+
}
|
|
1272
|
+
} catch (error) {
|
|
1273
|
+
if (error instanceof McpError) {
|
|
1274
|
+
throw error;
|
|
1275
|
+
}
|
|
1276
|
+
throw new McpError(ErrorCode.InvalidParams, `Failed to validate structured content: ${error instanceof Error ? error.message : String(error)}`);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
return result;
|
|
1281
|
+
}
|
|
1282
|
+
isToolTask(toolName) {
|
|
1283
|
+
if (!this._serverCapabilities?.tasks?.requests?.tools?.call) {
|
|
1284
|
+
return false;
|
|
1285
|
+
}
|
|
1286
|
+
return this._cachedKnownTaskTools.has(toolName);
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Check if a tool requires task-based execution.
|
|
1290
|
+
* Unlike isToolTask which includes 'optional' tools, this only checks for 'required'.
|
|
1291
|
+
*/
|
|
1292
|
+
isToolTaskRequired(toolName) {
|
|
1293
|
+
return this._cachedRequiredTaskTools.has(toolName);
|
|
1294
|
+
}
|
|
1295
|
+
/**
|
|
1296
|
+
* Cache validators for tool output schemas.
|
|
1297
|
+
* Called after listTools() to pre-compile validators for better performance.
|
|
1298
|
+
*/
|
|
1299
|
+
cacheToolMetadata(tools) {
|
|
1300
|
+
this._cachedToolOutputValidators.clear();
|
|
1301
|
+
this._cachedKnownTaskTools.clear();
|
|
1302
|
+
this._cachedRequiredTaskTools.clear();
|
|
1303
|
+
for (const tool of tools) {
|
|
1304
|
+
if (tool.outputSchema) {
|
|
1305
|
+
const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema);
|
|
1306
|
+
this._cachedToolOutputValidators.set(tool.name, toolValidator);
|
|
1307
|
+
}
|
|
1308
|
+
const taskSupport = tool.execution?.taskSupport;
|
|
1309
|
+
if (taskSupport === "required" || taskSupport === "optional") {
|
|
1310
|
+
this._cachedKnownTaskTools.add(tool.name);
|
|
1311
|
+
}
|
|
1312
|
+
if (taskSupport === "required") {
|
|
1313
|
+
this._cachedRequiredTaskTools.add(tool.name);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Get cached validator for a tool
|
|
1319
|
+
*/
|
|
1320
|
+
getToolOutputValidator(toolName) {
|
|
1321
|
+
return this._cachedToolOutputValidators.get(toolName);
|
|
1322
|
+
}
|
|
1323
|
+
async listTools(params, options) {
|
|
1324
|
+
const result = await this.request({ method: "tools/list", params }, ListToolsResultSchema, options);
|
|
1325
|
+
this.cacheToolMetadata(result.tools);
|
|
1326
|
+
return result;
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Set up a single list changed handler.
|
|
1330
|
+
* @internal
|
|
1331
|
+
*/
|
|
1332
|
+
_setupListChangedHandler(listType, notificationSchema, options, fetcher) {
|
|
1333
|
+
const parseResult = ListChangedOptionsBaseSchema.safeParse(options);
|
|
1334
|
+
if (!parseResult.success) {
|
|
1335
|
+
throw new Error(`Invalid ${listType} listChanged options: ${parseResult.error.message}`);
|
|
1336
|
+
}
|
|
1337
|
+
if (typeof options.onChanged !== "function") {
|
|
1338
|
+
throw new Error(`Invalid ${listType} listChanged options: onChanged must be a function`);
|
|
1339
|
+
}
|
|
1340
|
+
const { autoRefresh, debounceMs } = parseResult.data;
|
|
1341
|
+
const { onChanged } = options;
|
|
1342
|
+
const refresh = async () => {
|
|
1343
|
+
if (!autoRefresh) {
|
|
1344
|
+
onChanged(null, null);
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
try {
|
|
1348
|
+
const items = await fetcher();
|
|
1349
|
+
onChanged(null, items);
|
|
1350
|
+
} catch (e) {
|
|
1351
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
1352
|
+
onChanged(error, null);
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
const handler = () => {
|
|
1356
|
+
if (debounceMs) {
|
|
1357
|
+
const existingTimer = this._listChangedDebounceTimers.get(listType);
|
|
1358
|
+
if (existingTimer) {
|
|
1359
|
+
clearTimeout(existingTimer);
|
|
1360
|
+
}
|
|
1361
|
+
const timer = setTimeout(refresh, debounceMs);
|
|
1362
|
+
this._listChangedDebounceTimers.set(listType, timer);
|
|
1363
|
+
} else {
|
|
1364
|
+
refresh();
|
|
1365
|
+
}
|
|
1366
|
+
};
|
|
1367
|
+
this.setNotificationHandler(notificationSchema, handler);
|
|
1368
|
+
}
|
|
1369
|
+
async sendRootsListChanged() {
|
|
1370
|
+
return this.notification({ method: "notifications/roots/list_changed" });
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
|
|
1374
|
+
export {
|
|
1375
|
+
analyzeServer,
|
|
1376
|
+
sortFindings,
|
|
1377
|
+
worst,
|
|
1378
|
+
analyzeStackScan,
|
|
1379
|
+
diffSnapshots,
|
|
1380
|
+
looksLikeSecret,
|
|
1381
|
+
scrub,
|
|
1382
|
+
scrubDeep,
|
|
1383
|
+
Client,
|
|
1384
|
+
LIMITS,
|
|
1385
|
+
addTools,
|
|
1386
|
+
addPrompts,
|
|
1387
|
+
addTemplates,
|
|
1388
|
+
contractHash,
|
|
1389
|
+
contentHash,
|
|
1390
|
+
emptySnapshot
|
|
1391
|
+
};
|