@mcp-ts/sdk 2.1.0 → 2.2.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/dist/adapters/agui-adapter.d.mts +1 -1
- package/dist/adapters/agui-adapter.d.ts +1 -1
- package/dist/adapters/agui-middleware.d.mts +1 -1
- package/dist/adapters/agui-middleware.d.ts +1 -1
- package/dist/adapters/ai-adapter.d.mts +1 -1
- package/dist/adapters/ai-adapter.d.ts +1 -1
- package/dist/adapters/langchain-adapter.d.mts +1 -1
- package/dist/adapters/langchain-adapter.d.ts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -3
- package/dist/index.mjs.map +1 -1
- package/dist/shared/index.d.mts +2 -2
- package/dist/shared/index.d.ts +2 -2
- package/dist/shared/index.js +20 -3
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +20 -3
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-BkQnso27.d.mts → tool-router-C8hIA-tg.d.mts} +9 -0
- package/dist/{tool-router-BP8TT9mI.d.ts → tool-router-CdX8e9bk.d.ts} +9 -0
- package/package.json +1 -1
- package/src/shared/tool-router.ts +31 -3
|
@@ -274,6 +274,11 @@ interface ToolRouterOptions {
|
|
|
274
274
|
* Pinned tools are removed from discovery results and should be called directly.
|
|
275
275
|
*/
|
|
276
276
|
pinnedTools?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* Tool names to omit from direct exposure while keeping them indexed for
|
|
279
|
+
* search/schema lookup/calls through meta-tools.
|
|
280
|
+
*/
|
|
281
|
+
deferredTools?: string[];
|
|
277
282
|
/**
|
|
278
283
|
* Tool names or glob-style patterns to omit entirely from the router catalog.
|
|
279
284
|
*/
|
|
@@ -306,6 +311,7 @@ declare class ToolRouter {
|
|
|
306
311
|
private index;
|
|
307
312
|
private allTools;
|
|
308
313
|
private pinnedTools;
|
|
314
|
+
private deferredTools;
|
|
309
315
|
private discoverableTools;
|
|
310
316
|
private groupsMap;
|
|
311
317
|
private strategy;
|
|
@@ -314,6 +320,7 @@ declare class ToolRouter {
|
|
|
314
320
|
private activeGroups;
|
|
315
321
|
private customGroups?;
|
|
316
322
|
private pinnedToolNames;
|
|
323
|
+
private deferredToolNames;
|
|
317
324
|
private excludeToolMatchers;
|
|
318
325
|
private initialized;
|
|
319
326
|
constructor(client: ToolRouterClientInput, options?: ToolRouterOptions);
|
|
@@ -385,7 +392,9 @@ declare class ToolRouter {
|
|
|
385
392
|
/** The 4 meta-tool definitions exposed in `search` strategy. */
|
|
386
393
|
private getMetaToolDefinitions;
|
|
387
394
|
private matchesPinnedTool;
|
|
395
|
+
private matchesDeferredTool;
|
|
388
396
|
private matchesExcludedTool;
|
|
397
|
+
private getDirectlyVisibleTools;
|
|
389
398
|
}
|
|
390
399
|
|
|
391
400
|
export { type CompactTool as C, type EmbedFn as E, type IndexedTool as I, SchemaCompressor as S, type ToolGroupInfo as T, ToolIndex as a, type ToolIndexOptions as b, type ToolListResult as c, ToolRouter as d, type ToolRouterClientInput as e, type ToolRouterOptions as f, type ToolRouterStrategy as g, type ToolSearchOptions as h, type ToolServerSummary as i, type ToolSummary as j };
|
|
@@ -274,6 +274,11 @@ interface ToolRouterOptions {
|
|
|
274
274
|
* Pinned tools are removed from discovery results and should be called directly.
|
|
275
275
|
*/
|
|
276
276
|
pinnedTools?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* Tool names to omit from direct exposure while keeping them indexed for
|
|
279
|
+
* search/schema lookup/calls through meta-tools.
|
|
280
|
+
*/
|
|
281
|
+
deferredTools?: string[];
|
|
277
282
|
/**
|
|
278
283
|
* Tool names or glob-style patterns to omit entirely from the router catalog.
|
|
279
284
|
*/
|
|
@@ -306,6 +311,7 @@ declare class ToolRouter {
|
|
|
306
311
|
private index;
|
|
307
312
|
private allTools;
|
|
308
313
|
private pinnedTools;
|
|
314
|
+
private deferredTools;
|
|
309
315
|
private discoverableTools;
|
|
310
316
|
private groupsMap;
|
|
311
317
|
private strategy;
|
|
@@ -314,6 +320,7 @@ declare class ToolRouter {
|
|
|
314
320
|
private activeGroups;
|
|
315
321
|
private customGroups?;
|
|
316
322
|
private pinnedToolNames;
|
|
323
|
+
private deferredToolNames;
|
|
317
324
|
private excludeToolMatchers;
|
|
318
325
|
private initialized;
|
|
319
326
|
constructor(client: ToolRouterClientInput, options?: ToolRouterOptions);
|
|
@@ -385,7 +392,9 @@ declare class ToolRouter {
|
|
|
385
392
|
/** The 4 meta-tool definitions exposed in `search` strategy. */
|
|
386
393
|
private getMetaToolDefinitions;
|
|
387
394
|
private matchesPinnedTool;
|
|
395
|
+
private matchesDeferredTool;
|
|
388
396
|
private matchesExcludedTool;
|
|
397
|
+
private getDirectlyVisibleTools;
|
|
389
398
|
}
|
|
390
399
|
|
|
391
400
|
export { type CompactTool as C, type EmbedFn as E, type IndexedTool as I, SchemaCompressor as S, type ToolGroupInfo as T, ToolIndex as a, type ToolIndexOptions as b, type ToolListResult as c, ToolRouter as d, type ToolRouterClientInput as e, type ToolRouterOptions as f, type ToolRouterStrategy as g, type ToolSearchOptions as h, type ToolServerSummary as i, type ToolSummary as j };
|
package/package.json
CHANGED
|
@@ -105,6 +105,12 @@ export interface ToolRouterOptions {
|
|
|
105
105
|
*/
|
|
106
106
|
pinnedTools?: string[];
|
|
107
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Tool names to omit from direct exposure while keeping them indexed for
|
|
110
|
+
* search/schema lookup/calls through meta-tools.
|
|
111
|
+
*/
|
|
112
|
+
deferredTools?: string[];
|
|
113
|
+
|
|
108
114
|
/**
|
|
109
115
|
* Tool names or glob-style patterns to omit entirely from the router catalog.
|
|
110
116
|
*/
|
|
@@ -148,6 +154,7 @@ export class ToolRouter {
|
|
|
148
154
|
private index: ToolIndex;
|
|
149
155
|
private allTools: IndexedTool[] = [];
|
|
150
156
|
private pinnedTools: IndexedTool[] = [];
|
|
157
|
+
private deferredTools: IndexedTool[] = [];
|
|
151
158
|
private discoverableTools: IndexedTool[] = [];
|
|
152
159
|
private groupsMap = new Map<string, ToolGroupInfo>();
|
|
153
160
|
private strategy: ToolRouterStrategy;
|
|
@@ -156,6 +163,7 @@ export class ToolRouter {
|
|
|
156
163
|
private activeGroups: Set<string>;
|
|
157
164
|
private customGroups?: Record<string, string[]>;
|
|
158
165
|
private pinnedToolNames: Set<string>;
|
|
166
|
+
private deferredToolNames: Set<string>;
|
|
159
167
|
private excludeToolMatchers: RegExp[];
|
|
160
168
|
private initialized = false;
|
|
161
169
|
|
|
@@ -169,6 +177,7 @@ export class ToolRouter {
|
|
|
169
177
|
this.activeGroups = new Set(options.activeGroups ?? []);
|
|
170
178
|
this.customGroups = options.groups;
|
|
171
179
|
this.pinnedToolNames = new Set(options.pinnedTools ?? []);
|
|
180
|
+
this.deferredToolNames = new Set(options.deferredTools ?? []);
|
|
172
181
|
this.excludeToolMatchers = (options.excludeTools ?? []).map((pattern) =>
|
|
173
182
|
globToRegExp(pattern)
|
|
174
183
|
);
|
|
@@ -203,9 +212,10 @@ export class ToolRouter {
|
|
|
203
212
|
|
|
204
213
|
case 'all':
|
|
205
214
|
default:
|
|
215
|
+
const directlyVisibleTools = this.getDirectlyVisibleTools();
|
|
206
216
|
if (this.compactSchemas) {
|
|
207
217
|
// Return tools with inputSchema stripped
|
|
208
|
-
return
|
|
218
|
+
return directlyVisibleTools.map((t) => {
|
|
209
219
|
const compact = SchemaCompressor.toCompact(t);
|
|
210
220
|
return {
|
|
211
221
|
name: compact.name,
|
|
@@ -216,7 +226,7 @@ export class ToolRouter {
|
|
|
216
226
|
};
|
|
217
227
|
});
|
|
218
228
|
}
|
|
219
|
-
return [...
|
|
229
|
+
return [...directlyVisibleTools];
|
|
220
230
|
}
|
|
221
231
|
}
|
|
222
232
|
|
|
@@ -374,6 +384,9 @@ export class ToolRouter {
|
|
|
374
384
|
const fetchedTools = await this.fetchAllTools();
|
|
375
385
|
this.allTools = fetchedTools.filter((tool) => !this.matchesExcludedTool(tool.name));
|
|
376
386
|
this.pinnedTools = this.allTools.filter((tool) => this.matchesPinnedTool(tool.name));
|
|
387
|
+
this.deferredTools = this.allTools.filter(
|
|
388
|
+
(tool) => !this.matchesPinnedTool(tool.name) && this.matchesDeferredTool(tool)
|
|
389
|
+
);
|
|
377
390
|
this.discoverableTools = this.allTools.filter((tool) => !this.matchesPinnedTool(tool.name));
|
|
378
391
|
await this.index.buildIndex(this.discoverableTools);
|
|
379
392
|
this.buildGroups();
|
|
@@ -469,7 +482,7 @@ export class ToolRouter {
|
|
|
469
482
|
}
|
|
470
483
|
}
|
|
471
484
|
|
|
472
|
-
const filtered = this.
|
|
485
|
+
const filtered = this.getDirectlyVisibleTools().filter((t) => activeToolNames.has(t.name));
|
|
473
486
|
|
|
474
487
|
if (this.compactSchemas) {
|
|
475
488
|
return filtered.slice(0, this.maxTools).map((t) => {
|
|
@@ -502,9 +515,24 @@ export class ToolRouter {
|
|
|
502
515
|
return this.pinnedToolNames.has(toolName);
|
|
503
516
|
}
|
|
504
517
|
|
|
518
|
+
private matchesDeferredTool(tool: Tool): boolean {
|
|
519
|
+
if (this.deferredToolNames.has(tool.name)) {
|
|
520
|
+
return true;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
const meta = (tool as Tool & {
|
|
524
|
+
_meta?: { toolRouter?: { deferred?: boolean } };
|
|
525
|
+
})._meta;
|
|
526
|
+
return meta?.toolRouter?.deferred === true;
|
|
527
|
+
}
|
|
528
|
+
|
|
505
529
|
private matchesExcludedTool(toolName: string): boolean {
|
|
506
530
|
return this.excludeToolMatchers.some((matcher) => matcher.test(toolName));
|
|
507
531
|
}
|
|
532
|
+
|
|
533
|
+
private getDirectlyVisibleTools(): IndexedTool[] {
|
|
534
|
+
return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
|
|
535
|
+
}
|
|
508
536
|
}
|
|
509
537
|
|
|
510
538
|
function globToRegExp(pattern: string): RegExp {
|