@mcp-ts/sdk 1.6.2 → 2.1.0
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 +12 -6
- package/dist/adapters/agui-adapter.d.mts +3 -3
- package/dist/adapters/agui-adapter.d.ts +3 -3
- package/dist/adapters/agui-adapter.js +5 -5
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs +5 -5
- package/dist/adapters/agui-adapter.mjs.map +1 -1
- package/dist/adapters/agui-middleware.d.mts +3 -3
- package/dist/adapters/agui-middleware.d.ts +3 -3
- package/dist/adapters/ai-adapter.d.mts +9 -3
- package/dist/adapters/ai-adapter.d.ts +9 -3
- package/dist/adapters/ai-adapter.js +21 -6
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs +21 -6
- package/dist/adapters/ai-adapter.mjs.map +1 -1
- package/dist/adapters/langchain-adapter.d.mts +3 -3
- package/dist/adapters/langchain-adapter.d.ts +3 -3
- package/dist/adapters/langchain-adapter.js +10 -6
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +10 -6
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/adapters/mastra-adapter.d.mts +1 -1
- package/dist/adapters/mastra-adapter.d.ts +1 -1
- package/dist/adapters/mastra-adapter.js +5 -1
- package/dist/adapters/mastra-adapter.js.map +1 -1
- package/dist/adapters/mastra-adapter.mjs +5 -1
- package/dist/adapters/mastra-adapter.mjs.map +1 -1
- package/dist/bin/mcp-ts.js +7 -1
- package/dist/bin/mcp-ts.js.map +1 -1
- package/dist/bin/mcp-ts.mjs +7 -1
- package/dist/bin/mcp-ts.mjs.map +1 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +9 -13
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +9 -13
- package/dist/client/index.mjs.map +1 -1
- package/dist/client/react.d.mts +7 -7
- package/dist/client/react.d.ts +7 -7
- package/dist/client/react.js +15 -19
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs +15 -19
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +7 -7
- package/dist/client/vue.d.ts +7 -7
- package/dist/client/vue.js +14 -18
- package/dist/client/vue.js.map +1 -1
- package/dist/client/vue.mjs +14 -18
- package/dist/client/vue.mjs.map +1 -1
- package/dist/{index-bFL4ZF2N.d.mts → index-Cfjsme-a.d.mts} +5 -5
- package/dist/{index-DhA-OEAe.d.ts → index-CmjMd2ac.d.ts} +5 -5
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +643 -374
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +642 -374
- package/dist/index.mjs.map +1 -1
- package/dist/{multi-session-client-CHE8QpVE.d.ts → multi-session-client-BYtguGJm.d.ts} +22 -22
- package/dist/{multi-session-client-CQsRbxYI.d.mts → multi-session-client-DYNe6az3.d.mts} +22 -22
- package/dist/server/index.d.mts +31 -34
- package/dist/server/index.d.ts +31 -34
- package/dist/server/index.js +531 -256
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +530 -256
- package/dist/server/index.mjs.map +1 -1
- package/dist/shared/index.d.mts +7 -7
- package/dist/shared/index.d.ts +7 -7
- package/dist/shared/index.js +103 -105
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +103 -105
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-BVaV1udm.d.mts → tool-router-BP8TT9mI.d.ts} +87 -73
- package/dist/{tool-router-Dh2804tM.d.ts → tool-router-BkQnso27.d.mts} +87 -73
- package/dist/{types-rIuN1CQi.d.mts → types-CxFaaZrM.d.mts} +6 -5
- package/dist/{types-rIuN1CQi.d.ts → types-CxFaaZrM.d.ts} +6 -5
- package/dist/{utils-0qmYrqoa.d.mts → utils-DELRKQPU.d.mts} +1 -1
- package/dist/{utils-0qmYrqoa.d.ts → utils-DELRKQPU.d.ts} +1 -1
- package/migrations/neon/20260513010000_install_mcp_sessions.sql +69 -0
- package/migrations/neon/20260513020000_add_session_cleanup_cron.sql +35 -0
- package/{supabase/migrations → migrations/supabase}/20260330195700_install_mcp_sessions.sql +7 -9
- package/package.json +14 -5
- package/src/adapters/ai-adapter.ts +30 -1
- package/src/adapters/langchain-adapter.ts +6 -2
- package/src/adapters/mastra-adapter.ts +6 -2
- package/src/bin/mcp-ts.ts +8 -1
- package/src/client/core/app-host.ts +1 -1
- package/src/client/core/sse-client.ts +12 -14
- package/src/client/core/types.ts +1 -1
- package/src/client/react/use-mcp-apps.tsx +1 -1
- package/src/client/react/use-mcp.ts +11 -11
- package/src/client/vue/use-mcp.ts +10 -10
- package/src/server/handlers/nextjs-handler.ts +18 -15
- package/src/server/handlers/sse-handler.ts +29 -29
- package/src/server/index.ts +1 -1
- package/src/server/mcp/multi-session-client.ts +17 -17
- package/src/server/mcp/oauth-client.ts +37 -37
- package/src/server/mcp/storage-oauth-provider.ts +17 -17
- package/src/server/storage/file-backend.ts +25 -25
- package/src/server/storage/index.ts +67 -10
- package/src/server/storage/memory-backend.ts +34 -34
- package/src/server/storage/neon-backend.ts +281 -0
- package/src/server/storage/redis-backend.ts +64 -64
- package/src/server/storage/sqlite-backend.ts +33 -33
- package/src/server/storage/supabase-backend.ts +23 -24
- package/src/server/storage/types.ts +18 -21
- package/src/shared/errors.ts +1 -1
- package/src/shared/index.ts +1 -2
- package/src/shared/meta-tools.ts +9 -10
- package/src/shared/schema-compressor.ts +2 -42
- package/src/shared/tool-index.ts +90 -84
- package/src/shared/tool-router.ts +38 -27
- package/src/shared/types.ts +6 -5
- /package/{supabase/migrations → migrations/supabase}/20260421010000_add_session_cleanup_cron.sql +0 -0
package/dist/shared/index.mjs
CHANGED
|
@@ -154,7 +154,7 @@ var ToolExecutionError = class extends McpError {
|
|
|
154
154
|
};
|
|
155
155
|
var RpcErrorCodes = {
|
|
156
156
|
EXECUTION_ERROR: "EXECUTION_ERROR",
|
|
157
|
-
|
|
157
|
+
MISSING_USER_ID: "MISSING_USER_ID",
|
|
158
158
|
UNAUTHORIZED: "UNAUTHORIZED",
|
|
159
159
|
NO_CONNECTION: "NO_CONNECTION",
|
|
160
160
|
UNKNOWN_METHOD: "UNKNOWN_METHOD",
|
|
@@ -211,17 +211,7 @@ function findToolByName(connections, toolName) {
|
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
// src/shared/tool-index.ts
|
|
214
|
-
var
|
|
215
|
-
function classifyChar(ch) {
|
|
216
|
-
const code = ch.charCodeAt(0);
|
|
217
|
-
if (code <= 32 || ch === "{" || ch === "}" || ch === "[" || ch === "]" || ch === ":" || ch === ",") return 1;
|
|
218
|
-
if (code >= 33 && code <= 47) return 1.5;
|
|
219
|
-
if (code >= 48 && code <= 57) return 2;
|
|
220
|
-
if (code >= 65 && code <= 90) return 3.5;
|
|
221
|
-
if (code >= 97 && code <= 122) return 4;
|
|
222
|
-
return 2.5;
|
|
223
|
-
}
|
|
224
|
-
var ToolIndex = class _ToolIndex {
|
|
214
|
+
var ToolIndex = class {
|
|
225
215
|
constructor(options = {}) {
|
|
226
216
|
/** All indexed tools keyed by name (supports duplicates). */
|
|
227
217
|
__publicField(this, "tools", /* @__PURE__ */ new Map());
|
|
@@ -239,8 +229,6 @@ var ToolIndex = class _ToolIndex {
|
|
|
239
229
|
__publicField(this, "docLengths", /* @__PURE__ */ new Map());
|
|
240
230
|
/** BM25: average document length across the entire index. */
|
|
241
231
|
__publicField(this, "avgDocLength", 0);
|
|
242
|
-
/** Cached total estimated token cost across all indexed tools. */
|
|
243
|
-
__publicField(this, "totalTokenCost", 0);
|
|
244
232
|
__publicField(this, "options");
|
|
245
233
|
this.options = {
|
|
246
234
|
embedFn: options.embedFn ?? void 0,
|
|
@@ -263,7 +251,6 @@ var ToolIndex = class _ToolIndex {
|
|
|
263
251
|
this.embeddings.clear();
|
|
264
252
|
this.docLengths.clear();
|
|
265
253
|
this.avgDocLength = 0;
|
|
266
|
-
this.totalTokenCost = 0;
|
|
267
254
|
const allTokenSets = /* @__PURE__ */ new Map();
|
|
268
255
|
let totalLength = 0;
|
|
269
256
|
for (const tool of tools) {
|
|
@@ -272,19 +259,17 @@ var ToolIndex = class _ToolIndex {
|
|
|
272
259
|
this.tools.set(tool.name, []);
|
|
273
260
|
}
|
|
274
261
|
this.tools.get(tool.name).push(tool);
|
|
275
|
-
const estimatedTokens = _ToolIndex.estimateTokens(tool);
|
|
276
262
|
this.toolSummaries.set(docKey, {
|
|
277
263
|
name: tool.name,
|
|
278
264
|
description: tool.description ?? "",
|
|
279
265
|
serverName: tool.serverName,
|
|
280
266
|
serverId: tool.serverId,
|
|
281
|
-
sessionId: tool.sessionId
|
|
282
|
-
estimatedTokens
|
|
267
|
+
sessionId: tool.sessionId
|
|
283
268
|
});
|
|
284
|
-
this.
|
|
285
|
-
const text =
|
|
269
|
+
const rawText = this.buildSearchableText(tool);
|
|
270
|
+
const text = rawText.toLowerCase();
|
|
286
271
|
this.searchTexts.set(docKey, text);
|
|
287
|
-
const tokens = this.tokenize(
|
|
272
|
+
const tokens = this.tokenize(rawText);
|
|
288
273
|
const tf = /* @__PURE__ */ new Map();
|
|
289
274
|
const uniqueTokens = /* @__PURE__ */ new Set();
|
|
290
275
|
for (const tok of tokens) {
|
|
@@ -548,30 +533,6 @@ var ToolIndex = class _ToolIndex {
|
|
|
548
533
|
}
|
|
549
534
|
return count;
|
|
550
535
|
}
|
|
551
|
-
/** Total estimated token cost of all indexed tool schemas. */
|
|
552
|
-
getTotalTokenCost() {
|
|
553
|
-
return this.totalTokenCost;
|
|
554
|
-
}
|
|
555
|
-
// -----------------------------------------------------------------------
|
|
556
|
-
// Static Helpers
|
|
557
|
-
// -----------------------------------------------------------------------
|
|
558
|
-
/**
|
|
559
|
-
* Estimate token count of a tool's full schema (name + description + inputSchema).
|
|
560
|
-
*
|
|
561
|
-
* Uses character-class weighted counting calibrated against cl100k_base.
|
|
562
|
-
* Accuracy is typically within ±10% for JSON Schema payloads.
|
|
563
|
-
*/
|
|
564
|
-
static estimateTokens(tool) {
|
|
565
|
-
const parts = [tool.name];
|
|
566
|
-
if (tool.description) parts.push(tool.description);
|
|
567
|
-
if (tool.inputSchema) parts.push(JSON.stringify(tool.inputSchema));
|
|
568
|
-
const text = parts.join(" ");
|
|
569
|
-
let weightedLen = 0;
|
|
570
|
-
for (let i = 0; i < text.length; i++) {
|
|
571
|
-
weightedLen += 1 / classifyChar(text[i]);
|
|
572
|
-
}
|
|
573
|
-
return Math.ceil(weightedLen / (1 / CALIBRATION_DIVISOR));
|
|
574
|
-
}
|
|
575
536
|
// -----------------------------------------------------------------------
|
|
576
537
|
// Internals
|
|
577
538
|
// -----------------------------------------------------------------------
|
|
@@ -580,18 +541,74 @@ var ToolIndex = class _ToolIndex {
|
|
|
580
541
|
const parts = [tool.name];
|
|
581
542
|
if (tool.description) parts.push(tool.description);
|
|
582
543
|
if (tool.inputSchema && typeof tool.inputSchema === "object") {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
544
|
+
this.collectSchemaSearchText(tool.inputSchema, parts);
|
|
545
|
+
}
|
|
546
|
+
return parts.join(" ");
|
|
547
|
+
}
|
|
548
|
+
/** Recursively collect JSON Schema argument names and descriptions. */
|
|
549
|
+
collectSchemaSearchText(schema, parts, seen = /* @__PURE__ */ new WeakSet()) {
|
|
550
|
+
if (!schema || typeof schema !== "object") return;
|
|
551
|
+
if (seen.has(schema)) return;
|
|
552
|
+
seen.add(schema);
|
|
553
|
+
if (Array.isArray(schema)) {
|
|
554
|
+
for (const item of schema) {
|
|
555
|
+
this.collectSchemaSearchText(item, parts, seen);
|
|
556
|
+
}
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
const schemaObject = schema;
|
|
560
|
+
this.pushStringValue(schemaObject.description, parts);
|
|
561
|
+
this.pushStringValue(schemaObject.title, parts);
|
|
562
|
+
const properties = schemaObject.properties;
|
|
563
|
+
if (properties && typeof properties === "object" && !Array.isArray(properties)) {
|
|
564
|
+
for (const [propertyName, propertySchema] of Object.entries(properties)) {
|
|
565
|
+
parts.push(propertyName);
|
|
566
|
+
this.collectSchemaSearchText(propertySchema, parts, seen);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
const patternProperties = schemaObject.patternProperties;
|
|
570
|
+
if (patternProperties && typeof patternProperties === "object" && !Array.isArray(patternProperties)) {
|
|
571
|
+
for (const [propertyPattern, propertySchema] of Object.entries(patternProperties)) {
|
|
572
|
+
parts.push(propertyPattern);
|
|
573
|
+
this.collectSchemaSearchText(propertySchema, parts, seen);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
const dependentSchemas = schemaObject.dependentSchemas;
|
|
577
|
+
if (dependentSchemas && typeof dependentSchemas === "object" && !Array.isArray(dependentSchemas)) {
|
|
578
|
+
for (const [propertyName, dependentSchema] of Object.entries(dependentSchemas)) {
|
|
579
|
+
parts.push(propertyName);
|
|
580
|
+
this.collectSchemaSearchText(dependentSchema, parts, seen);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
for (const key of [
|
|
584
|
+
"items",
|
|
585
|
+
"additionalProperties",
|
|
586
|
+
"contains",
|
|
587
|
+
"propertyNames",
|
|
588
|
+
"if",
|
|
589
|
+
"then",
|
|
590
|
+
"else",
|
|
591
|
+
"not"
|
|
592
|
+
]) {
|
|
593
|
+
this.collectSchemaSearchText(schemaObject[key], parts, seen);
|
|
594
|
+
}
|
|
595
|
+
for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
|
|
596
|
+
this.collectSchemaSearchText(schemaObject[key], parts, seen);
|
|
597
|
+
}
|
|
598
|
+
for (const key of ["$defs", "definitions"]) {
|
|
599
|
+
const definitions = schemaObject[key];
|
|
600
|
+
if (definitions && typeof definitions === "object" && !Array.isArray(definitions)) {
|
|
601
|
+
for (const [definitionName, definitionSchema] of Object.entries(definitions)) {
|
|
602
|
+
parts.push(definitionName);
|
|
603
|
+
this.collectSchemaSearchText(definitionSchema, parts, seen);
|
|
591
604
|
}
|
|
592
605
|
}
|
|
593
606
|
}
|
|
594
|
-
|
|
607
|
+
}
|
|
608
|
+
pushStringValue(value, parts) {
|
|
609
|
+
if (typeof value === "string" && value.trim()) {
|
|
610
|
+
parts.push(value);
|
|
611
|
+
}
|
|
595
612
|
}
|
|
596
613
|
getDocumentKey(tool) {
|
|
597
614
|
return `${tool.sessionId}::${tool.serverId}::${tool.name}`;
|
|
@@ -612,7 +629,7 @@ var ToolIndex = class _ToolIndex {
|
|
|
612
629
|
}
|
|
613
630
|
/** Simple whitespace + camelCase + snake_case tokenizer. */
|
|
614
631
|
tokenize(text) {
|
|
615
|
-
return text.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ").replace(/[^a-z0-9\s]/g, "").split(/\s+/).filter((t) => t.length > 1);
|
|
632
|
+
return text.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[_-]/g, " ").toLowerCase().replace(/[^a-z0-9\s]/g, "").split(/\s+/).filter((t) => t.length > 1);
|
|
616
633
|
}
|
|
617
634
|
/** Cosine similarity between two vectors. */
|
|
618
635
|
cosineSimilarity(a, b) {
|
|
@@ -667,27 +684,6 @@ var SchemaCompressor = class _SchemaCompressor {
|
|
|
667
684
|
const limited = options?.maxTools ? tools.slice(0, options.maxTools) : tools;
|
|
668
685
|
return limited.map((t) => _SchemaCompressor.toCompact(t));
|
|
669
686
|
}
|
|
670
|
-
/**
|
|
671
|
-
* Estimate token savings from using compact vs full tool schemas.
|
|
672
|
-
*/
|
|
673
|
-
static estimateSavings(tools) {
|
|
674
|
-
let fullTokens = 0;
|
|
675
|
-
let compactTokens = 0;
|
|
676
|
-
for (const tool of tools) {
|
|
677
|
-
fullTokens += ToolIndex.estimateTokens(tool);
|
|
678
|
-
const compact = _SchemaCompressor.toCompact(tool);
|
|
679
|
-
const text = [compact.name, compact.description ?? "", compact.parameterHint ?? ""].join(" ");
|
|
680
|
-
compactTokens += Math.ceil(text.length / 4);
|
|
681
|
-
}
|
|
682
|
-
const saved = fullTokens - compactTokens;
|
|
683
|
-
const pct = fullTokens > 0 ? (saved / fullTokens * 100).toFixed(1) : "0.0";
|
|
684
|
-
return {
|
|
685
|
-
fullTokens,
|
|
686
|
-
compactTokens,
|
|
687
|
-
savedTokens: saved,
|
|
688
|
-
savingsPercent: `${pct}%`
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
687
|
};
|
|
692
688
|
|
|
693
689
|
// src/shared/meta-tools.ts
|
|
@@ -766,7 +762,7 @@ function createRegexSearchToolDefinition() {
|
|
|
766
762
|
function createGetSchemaToolDefinition() {
|
|
767
763
|
return {
|
|
768
764
|
name: "mcp_get_tool_schema",
|
|
769
|
-
description: "Get the full input schema (parameters) for a specific tool. Call this after mcp_search_tools to get the parameter details needed to call a tool correctly. Do NOT call the discovered tool directly; after reading the schema, call mcp_execute_tool.",
|
|
765
|
+
description: "Get the full input schema (parameters) and output schema (result shape) for a specific tool. Call this after mcp_search_tools to get the parameter details needed to call a tool correctly and understand what it returns. Do NOT call the discovered tool directly; after reading the schema, call mcp_execute_tool.",
|
|
770
766
|
inputSchema: {
|
|
771
767
|
type: "object",
|
|
772
768
|
properties: {
|
|
@@ -883,7 +879,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
|
883
879
|
const lines = [];
|
|
884
880
|
if (found.length > 0) {
|
|
885
881
|
lines.push(...found.map(
|
|
886
|
-
(t, i) => `${i + 1}. **${t.name}** (
|
|
882
|
+
(t, i) => `${i + 1}. **${t.name}** (serverName: ${t.serverName}, serverId: ${t.serverId})
|
|
887
883
|
${t.description}`
|
|
888
884
|
));
|
|
889
885
|
}
|
|
@@ -911,7 +907,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
|
911
907
|
serverName: query || void 0
|
|
912
908
|
});
|
|
913
909
|
const text = servers.length === 0 ? "No connected servers found." : servers.map(
|
|
914
|
-
(server, i) => `${i + 1}. **${server.serverName}** (serverId: ${server.serverId}
|
|
910
|
+
(server, i) => `${i + 1}. **${server.serverName}** (serverId: ${server.serverId})
|
|
915
911
|
Tool count: ${server.toolCount}`
|
|
916
912
|
).join("\n");
|
|
917
913
|
return {
|
|
@@ -951,6 +947,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
|
951
947
|
name: tool.name,
|
|
952
948
|
description: tool.description,
|
|
953
949
|
inputSchema: tool.inputSchema,
|
|
950
|
+
outputSchema: tool.outputSchema,
|
|
954
951
|
executionInstructions: {
|
|
955
952
|
nextTool: "mcp_execute_tool",
|
|
956
953
|
toolName: tool.name,
|
|
@@ -1018,9 +1015,8 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
|
1018
1015
|
}
|
|
1019
1016
|
function formatToolSummaries(tools) {
|
|
1020
1017
|
return tools.map(
|
|
1021
|
-
(t, i) => `${i + 1}. **${t.name}** (
|
|
1022
|
-
${t.description}
|
|
1023
|
-
Estimated tokens: ${t.estimatedTokens}`
|
|
1018
|
+
(t, i) => `${i + 1}. **${t.name}** (serverName: ${t.serverName}, serverId: ${t.serverId})
|
|
1019
|
+
${t.description}`
|
|
1024
1020
|
);
|
|
1025
1021
|
}
|
|
1026
1022
|
function isMetaTool(toolName) {
|
|
@@ -1047,18 +1043,26 @@ var ToolRouter = class {
|
|
|
1047
1043
|
this.options = options;
|
|
1048
1044
|
__publicField(this, "index");
|
|
1049
1045
|
__publicField(this, "allTools", []);
|
|
1046
|
+
__publicField(this, "pinnedTools", []);
|
|
1047
|
+
__publicField(this, "discoverableTools", []);
|
|
1050
1048
|
__publicField(this, "groupsMap", /* @__PURE__ */ new Map());
|
|
1051
1049
|
__publicField(this, "strategy");
|
|
1052
1050
|
__publicField(this, "maxTools");
|
|
1053
1051
|
__publicField(this, "compactSchemas");
|
|
1054
1052
|
__publicField(this, "activeGroups");
|
|
1055
1053
|
__publicField(this, "customGroups");
|
|
1054
|
+
__publicField(this, "pinnedToolNames");
|
|
1055
|
+
__publicField(this, "excludeToolMatchers");
|
|
1056
1056
|
__publicField(this, "initialized", false);
|
|
1057
1057
|
this.strategy = options.strategy ?? "all";
|
|
1058
1058
|
this.maxTools = options.maxTools ?? 40;
|
|
1059
1059
|
this.compactSchemas = options.compactSchemas ?? false;
|
|
1060
1060
|
this.activeGroups = new Set(options.activeGroups ?? []);
|
|
1061
1061
|
this.customGroups = options.groups;
|
|
1062
|
+
this.pinnedToolNames = new Set(options.pinnedTools ?? []);
|
|
1063
|
+
this.excludeToolMatchers = (options.excludeTools ?? []).map(
|
|
1064
|
+
(pattern) => globToRegExp(pattern)
|
|
1065
|
+
);
|
|
1062
1066
|
this.index = new ToolIndex({
|
|
1063
1067
|
embedFn: options.embedFn,
|
|
1064
1068
|
keywordWeight: options.keywordWeight
|
|
@@ -1079,7 +1083,7 @@ var ToolRouter = class {
|
|
|
1079
1083
|
await this.ensureInitialized();
|
|
1080
1084
|
switch (this.strategy) {
|
|
1081
1085
|
case "search":
|
|
1082
|
-
return this.getMetaToolDefinitions();
|
|
1086
|
+
return [...this.getMetaToolDefinitions(), ...this.pinnedTools];
|
|
1083
1087
|
case "groups":
|
|
1084
1088
|
return this.getGroupFilteredTools();
|
|
1085
1089
|
case "all":
|
|
@@ -1163,26 +1167,6 @@ var ToolRouter = class {
|
|
|
1163
1167
|
getActiveGroups() {
|
|
1164
1168
|
return [...this.activeGroups];
|
|
1165
1169
|
}
|
|
1166
|
-
// -----------------------------------------------------------------------
|
|
1167
|
-
// Stats & Introspection
|
|
1168
|
-
// -----------------------------------------------------------------------
|
|
1169
|
-
/** Total token cost of all tools if loaded without filtering. */
|
|
1170
|
-
getTotalTokenCost() {
|
|
1171
|
-
return this.index.getTotalTokenCost();
|
|
1172
|
-
}
|
|
1173
|
-
/** Estimate token cost of the currently filtered tool set. */
|
|
1174
|
-
async getFilteredTokenCost() {
|
|
1175
|
-
const tools = await this.getFilteredTools();
|
|
1176
|
-
let total = 0;
|
|
1177
|
-
for (const tool of tools) {
|
|
1178
|
-
total += ToolIndex.estimateTokens(tool);
|
|
1179
|
-
}
|
|
1180
|
-
return total;
|
|
1181
|
-
}
|
|
1182
|
-
/** Get compression stats showing savings from current strategy. */
|
|
1183
|
-
getCompressionStats() {
|
|
1184
|
-
return SchemaCompressor.estimateSavings(this.allTools);
|
|
1185
|
-
}
|
|
1186
1170
|
/** Number of total indexed tools. */
|
|
1187
1171
|
get totalToolCount() {
|
|
1188
1172
|
return this.allTools.length;
|
|
@@ -1226,8 +1210,11 @@ var ToolRouter = class {
|
|
|
1226
1210
|
/** Lazy initialization — fetches tools from all connected clients. */
|
|
1227
1211
|
async ensureInitialized() {
|
|
1228
1212
|
if (this.initialized) return;
|
|
1229
|
-
|
|
1230
|
-
|
|
1213
|
+
const fetchedTools = await this.fetchAllTools();
|
|
1214
|
+
this.allTools = fetchedTools.filter((tool) => !this.matchesExcludedTool(tool.name));
|
|
1215
|
+
this.pinnedTools = this.allTools.filter((tool) => this.matchesPinnedTool(tool.name));
|
|
1216
|
+
this.discoverableTools = this.allTools.filter((tool) => !this.matchesPinnedTool(tool.name));
|
|
1217
|
+
await this.index.buildIndex(this.discoverableTools);
|
|
1231
1218
|
this.buildGroups();
|
|
1232
1219
|
this.initialized = true;
|
|
1233
1220
|
}
|
|
@@ -1326,7 +1313,18 @@ var ToolRouter = class {
|
|
|
1326
1313
|
createExecuteToolDefinition()
|
|
1327
1314
|
];
|
|
1328
1315
|
}
|
|
1316
|
+
matchesPinnedTool(toolName) {
|
|
1317
|
+
return this.pinnedToolNames.has(toolName);
|
|
1318
|
+
}
|
|
1319
|
+
matchesExcludedTool(toolName) {
|
|
1320
|
+
return this.excludeToolMatchers.some((matcher) => matcher.test(toolName));
|
|
1321
|
+
}
|
|
1329
1322
|
};
|
|
1323
|
+
function globToRegExp(pattern) {
|
|
1324
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
1325
|
+
const regexPattern = `^${escaped.replace(/\*/g, ".*")}$`;
|
|
1326
|
+
return new RegExp(regexPattern);
|
|
1327
|
+
}
|
|
1330
1328
|
|
|
1331
1329
|
export { AuthenticationError, ConfigurationError, ConnectionError, DEFAULT_CLIENT_NAME, DEFAULT_CLIENT_URI, DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_LOGO_URI, DEFAULT_POLICY_URI, DisposableStore, Emitter, InvalidStateError, MCP_CLIENT_NAME, MCP_CLIENT_VERSION, McpError, NotConnectedError, REDIS_KEY_PREFIX, RpcErrorCodes, SESSION_TTL_SECONDS, SOFTWARE_ID, SOFTWARE_VERSION, STATE_EXPIRATION_MS, SchemaCompressor, SessionNotFoundError, SessionValidationError, TOKEN_EXPIRY_BUFFER_MS, ToolExecutionError, ToolIndex, ToolRouter, UnauthorizedError, createExecuteToolDefinition, createGetSchemaToolDefinition, createListServersToolDefinition, createRegexSearchToolDefinition, createSearchToolDefinition, executeMetaTool, findToolByName, getToolUiResourceUri, isCallToolSuccess, isConnectAuthRequired, isConnectError, isConnectSuccess, isListToolsSuccess, isMetaTool, resolveMetaToolProxy, sanitizeServerLabel };
|
|
1332
1330
|
//# sourceMappingURL=index.mjs.map
|