@mcp-ts/sdk 1.6.2 → 2.0.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 +4 -5
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs +4 -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 +20 -6
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs +20 -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 +9 -6
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +9 -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-DhA-OEAe.d.ts → index-C9gvpxy5.d.ts} +5 -5
- package/dist/{index-bFL4ZF2N.d.mts → index-eaH14_5u.d.mts} +5 -5
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +616 -370
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +615 -370
- 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 +5 -5
- package/dist/shared/index.d.ts +5 -5
- package/dist/shared/index.js +76 -101
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +76 -101
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-Dh2804tM.d.ts → tool-router-Ddtybmr0.d.ts} +71 -73
- package/dist/{tool-router-BVaV1udm.d.mts → tool-router-Dnd6IOKC.d.mts} +71 -73
- package/dist/{types-rIuN1CQi.d.mts → types-BCAG20P6.d.mts} +4 -4
- package/dist/{types-rIuN1CQi.d.ts → types-BCAG20P6.d.ts} +4 -4
- 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 +4 -6
- package/src/shared/schema-compressor.ts +2 -42
- package/src/shared/tool-index.ts +89 -84
- package/src/shared/tool-router.ts +0 -24
- package/src/shared/types.ts +4 -4
- /package/{supabase/migrations → migrations/supabase}/20260421010000_add_session_cleanup_cron.sql +0 -0
package/dist/shared/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, M as McpConnectionEvent, c as McpConnectionState, d as McpObservabilityEvent } from '../events-CK3N--3g.mjs';
|
|
2
|
-
export { A as AuthenticationError, C as ConfigurationError, a as ConnectionError, I as InvalidStateError, M as McpError, N as NotConnectedError, R as RpcErrorCode, b as RpcErrorCodes, S as SessionNotFoundError, c as SessionValidationError, T as ToolExecutionError, U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-
|
|
3
|
-
import { v as ToolInfo } from '../types-
|
|
4
|
-
export { C as CallToolParams, a as CallToolRequest, b as CallToolResponse, c as ConnectAuthRequiredResponse, d as ConnectErrorResponse, e as ConnectParams, f as ConnectRequest, g as ConnectResponse, h as ConnectResult, i as ConnectSuccessResponse, D as DisconnectParams, j as DisconnectResult, F as FinishAuthParams, k as FinishAuthResult, G as GetPromptParams, L as ListPromptsResult,
|
|
5
|
-
import {
|
|
6
|
-
export { C as CompactTool,
|
|
2
|
+
export { A as AuthenticationError, C as ConfigurationError, a as ConnectionError, I as InvalidStateError, M as McpError, N as NotConnectedError, R as RpcErrorCode, b as RpcErrorCodes, S as SessionNotFoundError, c as SessionValidationError, T as ToolExecutionError, U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-DELRKQPU.mjs';
|
|
3
|
+
import { v as ToolInfo } from '../types-BCAG20P6.mjs';
|
|
4
|
+
export { C as CallToolParams, a as CallToolRequest, b as CallToolResponse, c as ConnectAuthRequiredResponse, d as ConnectErrorResponse, e as ConnectParams, f as ConnectRequest, g as ConnectResponse, h as ConnectResult, i as ConnectSuccessResponse, D as DisconnectParams, j as DisconnectResult, F as FinishAuthParams, k as FinishAuthResult, G as GetPromptParams, l as GetSessionResult, L as ListPromptsResult, m as ListResourcesResult, n as ListToolsResponse, o as ListToolsRpcResult, M as McpRpcMethod, p as McpRpcParams, q as McpRpcRequest, r as McpRpcResponse, R as ReadResourceParams, S as SessionInfo, s as SessionListResult, t as SessionParams, T as ToolClient, u as ToolClientProvider, w as TransportType, x as isCallToolSuccess, y as isConnectAuthRequired, z as isConnectError, A as isConnectSuccess, B as isListToolsSuccess } from '../types-BCAG20P6.mjs';
|
|
5
|
+
import { d as ToolRouter } from '../tool-router-Dnd6IOKC.mjs';
|
|
6
|
+
export { C as CompactTool, E as EmbedFn, I as IndexedTool, S as SchemaCompressor, T as ToolGroupInfo, a as ToolIndex, b as ToolIndexOptions, c as ToolListResult, e as ToolRouterClientInput, f as ToolRouterOptions, g as ToolRouterStrategy, h as ToolSearchOptions, i as ToolServerSummary, j as ToolSummary } from '../tool-router-Dnd6IOKC.mjs';
|
|
7
7
|
import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
8
8
|
|
|
9
9
|
/**
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export { D as Disposable, a as DisposableStore, E as Emitter, b as Event, M as McpConnectionEvent, c as McpConnectionState, d as McpObservabilityEvent } from '../events-CK3N--3g.js';
|
|
2
|
-
export { A as AuthenticationError, C as ConfigurationError, a as ConnectionError, I as InvalidStateError, M as McpError, N as NotConnectedError, R as RpcErrorCode, b as RpcErrorCodes, S as SessionNotFoundError, c as SessionValidationError, T as ToolExecutionError, U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-
|
|
3
|
-
import { v as ToolInfo } from '../types-
|
|
4
|
-
export { C as CallToolParams, a as CallToolRequest, b as CallToolResponse, c as ConnectAuthRequiredResponse, d as ConnectErrorResponse, e as ConnectParams, f as ConnectRequest, g as ConnectResponse, h as ConnectResult, i as ConnectSuccessResponse, D as DisconnectParams, j as DisconnectResult, F as FinishAuthParams, k as FinishAuthResult, G as GetPromptParams, L as ListPromptsResult,
|
|
5
|
-
import {
|
|
6
|
-
export { C as CompactTool,
|
|
2
|
+
export { A as AuthenticationError, C as ConfigurationError, a as ConnectionError, I as InvalidStateError, M as McpError, N as NotConnectedError, R as RpcErrorCode, b as RpcErrorCodes, S as SessionNotFoundError, c as SessionValidationError, T as ToolExecutionError, U as UnauthorizedError, s as sanitizeServerLabel } from '../utils-DELRKQPU.js';
|
|
3
|
+
import { v as ToolInfo } from '../types-BCAG20P6.js';
|
|
4
|
+
export { C as CallToolParams, a as CallToolRequest, b as CallToolResponse, c as ConnectAuthRequiredResponse, d as ConnectErrorResponse, e as ConnectParams, f as ConnectRequest, g as ConnectResponse, h as ConnectResult, i as ConnectSuccessResponse, D as DisconnectParams, j as DisconnectResult, F as FinishAuthParams, k as FinishAuthResult, G as GetPromptParams, l as GetSessionResult, L as ListPromptsResult, m as ListResourcesResult, n as ListToolsResponse, o as ListToolsRpcResult, M as McpRpcMethod, p as McpRpcParams, q as McpRpcRequest, r as McpRpcResponse, R as ReadResourceParams, S as SessionInfo, s as SessionListResult, t as SessionParams, T as ToolClient, u as ToolClientProvider, w as TransportType, x as isCallToolSuccess, y as isConnectAuthRequired, z as isConnectError, A as isConnectSuccess, B as isListToolsSuccess } from '../types-BCAG20P6.js';
|
|
5
|
+
import { d as ToolRouter } from '../tool-router-Ddtybmr0.js';
|
|
6
|
+
export { C as CompactTool, E as EmbedFn, I as IndexedTool, S as SchemaCompressor, T as ToolGroupInfo, a as ToolIndex, b as ToolIndexOptions, c as ToolListResult, e as ToolRouterClientInput, f as ToolRouterOptions, g as ToolRouterStrategy, h as ToolSearchOptions, i as ToolServerSummary, j as ToolSummary } from '../tool-router-Ddtybmr0.js';
|
|
7
7
|
import { Tool, CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
8
8
|
|
|
9
9
|
/**
|
package/dist/shared/index.js
CHANGED
|
@@ -156,7 +156,7 @@ var ToolExecutionError = class extends McpError {
|
|
|
156
156
|
};
|
|
157
157
|
var RpcErrorCodes = {
|
|
158
158
|
EXECUTION_ERROR: "EXECUTION_ERROR",
|
|
159
|
-
|
|
159
|
+
MISSING_USER_ID: "MISSING_USER_ID",
|
|
160
160
|
UNAUTHORIZED: "UNAUTHORIZED",
|
|
161
161
|
NO_CONNECTION: "NO_CONNECTION",
|
|
162
162
|
UNKNOWN_METHOD: "UNKNOWN_METHOD",
|
|
@@ -213,17 +213,7 @@ function findToolByName(connections, toolName) {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
// src/shared/tool-index.ts
|
|
216
|
-
var
|
|
217
|
-
function classifyChar(ch) {
|
|
218
|
-
const code = ch.charCodeAt(0);
|
|
219
|
-
if (code <= 32 || ch === "{" || ch === "}" || ch === "[" || ch === "]" || ch === ":" || ch === ",") return 1;
|
|
220
|
-
if (code >= 33 && code <= 47) return 1.5;
|
|
221
|
-
if (code >= 48 && code <= 57) return 2;
|
|
222
|
-
if (code >= 65 && code <= 90) return 3.5;
|
|
223
|
-
if (code >= 97 && code <= 122) return 4;
|
|
224
|
-
return 2.5;
|
|
225
|
-
}
|
|
226
|
-
var ToolIndex = class _ToolIndex {
|
|
216
|
+
var ToolIndex = class {
|
|
227
217
|
constructor(options = {}) {
|
|
228
218
|
/** All indexed tools keyed by name (supports duplicates). */
|
|
229
219
|
__publicField(this, "tools", /* @__PURE__ */ new Map());
|
|
@@ -241,8 +231,6 @@ var ToolIndex = class _ToolIndex {
|
|
|
241
231
|
__publicField(this, "docLengths", /* @__PURE__ */ new Map());
|
|
242
232
|
/** BM25: average document length across the entire index. */
|
|
243
233
|
__publicField(this, "avgDocLength", 0);
|
|
244
|
-
/** Cached total estimated token cost across all indexed tools. */
|
|
245
|
-
__publicField(this, "totalTokenCost", 0);
|
|
246
234
|
__publicField(this, "options");
|
|
247
235
|
this.options = {
|
|
248
236
|
embedFn: options.embedFn ?? void 0,
|
|
@@ -265,7 +253,6 @@ var ToolIndex = class _ToolIndex {
|
|
|
265
253
|
this.embeddings.clear();
|
|
266
254
|
this.docLengths.clear();
|
|
267
255
|
this.avgDocLength = 0;
|
|
268
|
-
this.totalTokenCost = 0;
|
|
269
256
|
const allTokenSets = /* @__PURE__ */ new Map();
|
|
270
257
|
let totalLength = 0;
|
|
271
258
|
for (const tool of tools) {
|
|
@@ -274,19 +261,17 @@ var ToolIndex = class _ToolIndex {
|
|
|
274
261
|
this.tools.set(tool.name, []);
|
|
275
262
|
}
|
|
276
263
|
this.tools.get(tool.name).push(tool);
|
|
277
|
-
const estimatedTokens = _ToolIndex.estimateTokens(tool);
|
|
278
264
|
this.toolSummaries.set(docKey, {
|
|
279
265
|
name: tool.name,
|
|
280
266
|
description: tool.description ?? "",
|
|
281
267
|
serverName: tool.serverName,
|
|
282
268
|
serverId: tool.serverId,
|
|
283
|
-
sessionId: tool.sessionId
|
|
284
|
-
estimatedTokens
|
|
269
|
+
sessionId: tool.sessionId
|
|
285
270
|
});
|
|
286
|
-
this.
|
|
287
|
-
const text =
|
|
271
|
+
const rawText = this.buildSearchableText(tool);
|
|
272
|
+
const text = rawText.toLowerCase();
|
|
288
273
|
this.searchTexts.set(docKey, text);
|
|
289
|
-
const tokens = this.tokenize(
|
|
274
|
+
const tokens = this.tokenize(rawText);
|
|
290
275
|
const tf = /* @__PURE__ */ new Map();
|
|
291
276
|
const uniqueTokens = /* @__PURE__ */ new Set();
|
|
292
277
|
for (const tok of tokens) {
|
|
@@ -550,30 +535,6 @@ var ToolIndex = class _ToolIndex {
|
|
|
550
535
|
}
|
|
551
536
|
return count;
|
|
552
537
|
}
|
|
553
|
-
/** Total estimated token cost of all indexed tool schemas. */
|
|
554
|
-
getTotalTokenCost() {
|
|
555
|
-
return this.totalTokenCost;
|
|
556
|
-
}
|
|
557
|
-
// -----------------------------------------------------------------------
|
|
558
|
-
// Static Helpers
|
|
559
|
-
// -----------------------------------------------------------------------
|
|
560
|
-
/**
|
|
561
|
-
* Estimate token count of a tool's full schema (name + description + inputSchema).
|
|
562
|
-
*
|
|
563
|
-
* Uses character-class weighted counting calibrated against cl100k_base.
|
|
564
|
-
* Accuracy is typically within ±10% for JSON Schema payloads.
|
|
565
|
-
*/
|
|
566
|
-
static estimateTokens(tool) {
|
|
567
|
-
const parts = [tool.name];
|
|
568
|
-
if (tool.description) parts.push(tool.description);
|
|
569
|
-
if (tool.inputSchema) parts.push(JSON.stringify(tool.inputSchema));
|
|
570
|
-
const text = parts.join(" ");
|
|
571
|
-
let weightedLen = 0;
|
|
572
|
-
for (let i = 0; i < text.length; i++) {
|
|
573
|
-
weightedLen += 1 / classifyChar(text[i]);
|
|
574
|
-
}
|
|
575
|
-
return Math.ceil(weightedLen / (1 / CALIBRATION_DIVISOR));
|
|
576
|
-
}
|
|
577
538
|
// -----------------------------------------------------------------------
|
|
578
539
|
// Internals
|
|
579
540
|
// -----------------------------------------------------------------------
|
|
@@ -582,18 +543,74 @@ var ToolIndex = class _ToolIndex {
|
|
|
582
543
|
const parts = [tool.name];
|
|
583
544
|
if (tool.description) parts.push(tool.description);
|
|
584
545
|
if (tool.inputSchema && typeof tool.inputSchema === "object") {
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
546
|
+
this.collectSchemaSearchText(tool.inputSchema, parts);
|
|
547
|
+
}
|
|
548
|
+
return parts.join(" ");
|
|
549
|
+
}
|
|
550
|
+
/** Recursively collect JSON Schema argument names and descriptions. */
|
|
551
|
+
collectSchemaSearchText(schema, parts, seen = /* @__PURE__ */ new WeakSet()) {
|
|
552
|
+
if (!schema || typeof schema !== "object") return;
|
|
553
|
+
if (seen.has(schema)) return;
|
|
554
|
+
seen.add(schema);
|
|
555
|
+
if (Array.isArray(schema)) {
|
|
556
|
+
for (const item of schema) {
|
|
557
|
+
this.collectSchemaSearchText(item, parts, seen);
|
|
558
|
+
}
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const schemaObject = schema;
|
|
562
|
+
this.pushStringValue(schemaObject.description, parts);
|
|
563
|
+
this.pushStringValue(schemaObject.title, parts);
|
|
564
|
+
const properties = schemaObject.properties;
|
|
565
|
+
if (properties && typeof properties === "object" && !Array.isArray(properties)) {
|
|
566
|
+
for (const [propertyName, propertySchema] of Object.entries(properties)) {
|
|
567
|
+
parts.push(propertyName);
|
|
568
|
+
this.collectSchemaSearchText(propertySchema, parts, seen);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const patternProperties = schemaObject.patternProperties;
|
|
572
|
+
if (patternProperties && typeof patternProperties === "object" && !Array.isArray(patternProperties)) {
|
|
573
|
+
for (const [propertyPattern, propertySchema] of Object.entries(patternProperties)) {
|
|
574
|
+
parts.push(propertyPattern);
|
|
575
|
+
this.collectSchemaSearchText(propertySchema, parts, seen);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const dependentSchemas = schemaObject.dependentSchemas;
|
|
579
|
+
if (dependentSchemas && typeof dependentSchemas === "object" && !Array.isArray(dependentSchemas)) {
|
|
580
|
+
for (const [propertyName, dependentSchema] of Object.entries(dependentSchemas)) {
|
|
581
|
+
parts.push(propertyName);
|
|
582
|
+
this.collectSchemaSearchText(dependentSchema, parts, seen);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
for (const key of [
|
|
586
|
+
"items",
|
|
587
|
+
"additionalProperties",
|
|
588
|
+
"contains",
|
|
589
|
+
"propertyNames",
|
|
590
|
+
"if",
|
|
591
|
+
"then",
|
|
592
|
+
"else",
|
|
593
|
+
"not"
|
|
594
|
+
]) {
|
|
595
|
+
this.collectSchemaSearchText(schemaObject[key], parts, seen);
|
|
596
|
+
}
|
|
597
|
+
for (const key of ["allOf", "anyOf", "oneOf", "prefixItems"]) {
|
|
598
|
+
this.collectSchemaSearchText(schemaObject[key], parts, seen);
|
|
599
|
+
}
|
|
600
|
+
for (const key of ["$defs", "definitions"]) {
|
|
601
|
+
const definitions = schemaObject[key];
|
|
602
|
+
if (definitions && typeof definitions === "object" && !Array.isArray(definitions)) {
|
|
603
|
+
for (const [definitionName, definitionSchema] of Object.entries(definitions)) {
|
|
604
|
+
parts.push(definitionName);
|
|
605
|
+
this.collectSchemaSearchText(definitionSchema, parts, seen);
|
|
593
606
|
}
|
|
594
607
|
}
|
|
595
608
|
}
|
|
596
|
-
|
|
609
|
+
}
|
|
610
|
+
pushStringValue(value, parts) {
|
|
611
|
+
if (typeof value === "string" && value.trim()) {
|
|
612
|
+
parts.push(value);
|
|
613
|
+
}
|
|
597
614
|
}
|
|
598
615
|
getDocumentKey(tool) {
|
|
599
616
|
return `${tool.sessionId}::${tool.serverId}::${tool.name}`;
|
|
@@ -614,7 +631,7 @@ var ToolIndex = class _ToolIndex {
|
|
|
614
631
|
}
|
|
615
632
|
/** Simple whitespace + camelCase + snake_case tokenizer. */
|
|
616
633
|
tokenize(text) {
|
|
617
|
-
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);
|
|
634
|
+
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);
|
|
618
635
|
}
|
|
619
636
|
/** Cosine similarity between two vectors. */
|
|
620
637
|
cosineSimilarity(a, b) {
|
|
@@ -669,27 +686,6 @@ var SchemaCompressor = class _SchemaCompressor {
|
|
|
669
686
|
const limited = options?.maxTools ? tools.slice(0, options.maxTools) : tools;
|
|
670
687
|
return limited.map((t) => _SchemaCompressor.toCompact(t));
|
|
671
688
|
}
|
|
672
|
-
/**
|
|
673
|
-
* Estimate token savings from using compact vs full tool schemas.
|
|
674
|
-
*/
|
|
675
|
-
static estimateSavings(tools) {
|
|
676
|
-
let fullTokens = 0;
|
|
677
|
-
let compactTokens = 0;
|
|
678
|
-
for (const tool of tools) {
|
|
679
|
-
fullTokens += ToolIndex.estimateTokens(tool);
|
|
680
|
-
const compact = _SchemaCompressor.toCompact(tool);
|
|
681
|
-
const text = [compact.name, compact.description ?? "", compact.parameterHint ?? ""].join(" ");
|
|
682
|
-
compactTokens += Math.ceil(text.length / 4);
|
|
683
|
-
}
|
|
684
|
-
const saved = fullTokens - compactTokens;
|
|
685
|
-
const pct = fullTokens > 0 ? (saved / fullTokens * 100).toFixed(1) : "0.0";
|
|
686
|
-
return {
|
|
687
|
-
fullTokens,
|
|
688
|
-
compactTokens,
|
|
689
|
-
savedTokens: saved,
|
|
690
|
-
savingsPercent: `${pct}%`
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
689
|
};
|
|
694
690
|
|
|
695
691
|
// src/shared/meta-tools.ts
|
|
@@ -885,7 +881,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
|
885
881
|
const lines = [];
|
|
886
882
|
if (found.length > 0) {
|
|
887
883
|
lines.push(...found.map(
|
|
888
|
-
(t, i) => `${i + 1}. **${t.name}** (
|
|
884
|
+
(t, i) => `${i + 1}. **${t.name}** (serverName: ${t.serverName}, serverId: ${t.serverId})
|
|
889
885
|
${t.description}`
|
|
890
886
|
));
|
|
891
887
|
}
|
|
@@ -913,7 +909,7 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
|
913
909
|
serverName: query || void 0
|
|
914
910
|
});
|
|
915
911
|
const text = servers.length === 0 ? "No connected servers found." : servers.map(
|
|
916
|
-
(server, i) => `${i + 1}. **${server.serverName}** (serverId: ${server.serverId}
|
|
912
|
+
(server, i) => `${i + 1}. **${server.serverName}** (serverId: ${server.serverId})
|
|
917
913
|
Tool count: ${server.toolCount}`
|
|
918
914
|
).join("\n");
|
|
919
915
|
return {
|
|
@@ -1020,9 +1016,8 @@ async function executeMetaTool(toolName, args, router, callToolFn) {
|
|
|
1020
1016
|
}
|
|
1021
1017
|
function formatToolSummaries(tools) {
|
|
1022
1018
|
return tools.map(
|
|
1023
|
-
(t, i) => `${i + 1}. **${t.name}** (
|
|
1024
|
-
${t.description}
|
|
1025
|
-
Estimated tokens: ${t.estimatedTokens}`
|
|
1019
|
+
(t, i) => `${i + 1}. **${t.name}** (serverName: ${t.serverName}, serverId: ${t.serverId})
|
|
1020
|
+
${t.description}`
|
|
1026
1021
|
);
|
|
1027
1022
|
}
|
|
1028
1023
|
function isMetaTool(toolName) {
|
|
@@ -1165,26 +1160,6 @@ var ToolRouter = class {
|
|
|
1165
1160
|
getActiveGroups() {
|
|
1166
1161
|
return [...this.activeGroups];
|
|
1167
1162
|
}
|
|
1168
|
-
// -----------------------------------------------------------------------
|
|
1169
|
-
// Stats & Introspection
|
|
1170
|
-
// -----------------------------------------------------------------------
|
|
1171
|
-
/** Total token cost of all tools if loaded without filtering. */
|
|
1172
|
-
getTotalTokenCost() {
|
|
1173
|
-
return this.index.getTotalTokenCost();
|
|
1174
|
-
}
|
|
1175
|
-
/** Estimate token cost of the currently filtered tool set. */
|
|
1176
|
-
async getFilteredTokenCost() {
|
|
1177
|
-
const tools = await this.getFilteredTools();
|
|
1178
|
-
let total = 0;
|
|
1179
|
-
for (const tool of tools) {
|
|
1180
|
-
total += ToolIndex.estimateTokens(tool);
|
|
1181
|
-
}
|
|
1182
|
-
return total;
|
|
1183
|
-
}
|
|
1184
|
-
/** Get compression stats showing savings from current strategy. */
|
|
1185
|
-
getCompressionStats() {
|
|
1186
|
-
return SchemaCompressor.estimateSavings(this.allTools);
|
|
1187
|
-
}
|
|
1188
1163
|
/** Number of total indexed tools. */
|
|
1189
1164
|
get totalToolCount() {
|
|
1190
1165
|
return this.allTools.length;
|