@mcp-ts/sdk 2.3.0 → 2.3.2
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-adapter.js +9 -5
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs +9 -5
- package/dist/adapters/agui-adapter.mjs.map +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/ai-adapter.js +9 -5
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs +9 -5
- package/dist/adapters/ai-adapter.mjs.map +1 -1
- package/dist/adapters/langchain-adapter.d.mts +1 -1
- package/dist/adapters/langchain-adapter.d.ts +1 -1
- package/dist/adapters/langchain-adapter.js +9 -5
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +9 -5
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +35 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -6
- 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 +35 -6
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +35 -6
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-CdX8e9bk.d.ts → tool-router-BMzhoNYt.d.ts} +7 -0
- package/dist/{tool-router-C8hIA-tg.d.mts → tool-router-BhHsvBfP.d.mts} +7 -0
- package/package.json +1 -1
- package/src/shared/meta-tools.ts +16 -7
- package/src/shared/tool-router.ts +45 -1
|
@@ -355,6 +355,11 @@ declare class ToolRouter {
|
|
|
355
355
|
* If tool name is ambiguous, use namespace to specify the server.
|
|
356
356
|
*/
|
|
357
357
|
getToolSchema(toolName: string, namespace?: string, options?: ToolLookupOptions): IndexedTool | undefined;
|
|
358
|
+
/**
|
|
359
|
+
* Resolve the full tool definition by name, ensuring the router index has
|
|
360
|
+
* been initialized first.
|
|
361
|
+
*/
|
|
362
|
+
resolveToolSchema(toolName: string, namespace?: string, options?: ToolLookupOptions): Promise<IndexedTool | undefined>;
|
|
358
363
|
/**
|
|
359
364
|
* Get compact (schema-less) summaries for all tools.
|
|
360
365
|
*/
|
|
@@ -395,6 +400,8 @@ declare class ToolRouter {
|
|
|
395
400
|
private matchesDeferredTool;
|
|
396
401
|
private matchesExcludedTool;
|
|
397
402
|
private getDirectlyVisibleTools;
|
|
403
|
+
private getIndexedToolMatches;
|
|
404
|
+
private matchTools;
|
|
398
405
|
}
|
|
399
406
|
|
|
400
407
|
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 };
|
|
@@ -355,6 +355,11 @@ declare class ToolRouter {
|
|
|
355
355
|
* If tool name is ambiguous, use namespace to specify the server.
|
|
356
356
|
*/
|
|
357
357
|
getToolSchema(toolName: string, namespace?: string, options?: ToolLookupOptions): IndexedTool | undefined;
|
|
358
|
+
/**
|
|
359
|
+
* Resolve the full tool definition by name, ensuring the router index has
|
|
360
|
+
* been initialized first.
|
|
361
|
+
*/
|
|
362
|
+
resolveToolSchema(toolName: string, namespace?: string, options?: ToolLookupOptions): Promise<IndexedTool | undefined>;
|
|
358
363
|
/**
|
|
359
364
|
* Get compact (schema-less) summaries for all tools.
|
|
360
365
|
*/
|
|
@@ -395,6 +400,8 @@ declare class ToolRouter {
|
|
|
395
400
|
private matchesDeferredTool;
|
|
396
401
|
private matchesExcludedTool;
|
|
397
402
|
private getDirectlyVisibleTools;
|
|
403
|
+
private getIndexedToolMatches;
|
|
404
|
+
private matchTools;
|
|
398
405
|
}
|
|
399
406
|
|
|
400
407
|
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
package/src/shared/meta-tools.ts
CHANGED
|
@@ -235,12 +235,23 @@ export async function executeMetaTool(
|
|
|
235
235
|
router: ToolRouter,
|
|
236
236
|
callToolFn?: CallToolFn
|
|
237
237
|
): Promise<CallToolResult | null> {
|
|
238
|
-
const resolveToolSchema = (
|
|
238
|
+
const resolveToolSchema = async (
|
|
239
239
|
name: string,
|
|
240
240
|
namespace?: string,
|
|
241
241
|
options?: ToolLookupOptions
|
|
242
|
-
): { tool?: IndexedTool; error?: CallToolResult } => {
|
|
242
|
+
): Promise<{ tool?: IndexedTool; error?: CallToolResult }> => {
|
|
243
243
|
try {
|
|
244
|
+
if (typeof (router as ToolRouter & { resolveToolSchema?: unknown }).resolveToolSchema === 'function') {
|
|
245
|
+
return {
|
|
246
|
+
tool: await (router as ToolRouter & {
|
|
247
|
+
resolveToolSchema: (
|
|
248
|
+
toolName: string,
|
|
249
|
+
namespace?: string,
|
|
250
|
+
options?: ToolLookupOptions
|
|
251
|
+
) => Promise<IndexedTool | undefined>;
|
|
252
|
+
}).resolveToolSchema(name, namespace, options),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
244
255
|
return { tool: router.getToolSchema(name, namespace, options) };
|
|
245
256
|
} catch (err) {
|
|
246
257
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
@@ -307,8 +318,6 @@ export async function executeMetaTool(
|
|
|
307
318
|
// Fast path: Check for select: prefix
|
|
308
319
|
const selectMatch = query.match(/^select:(.+)$/i);
|
|
309
320
|
if (selectMatch) {
|
|
310
|
-
await router.listTools({ serverId, serverName, limit: 1 });
|
|
311
|
-
|
|
312
321
|
const requested = selectMatch[1]!
|
|
313
322
|
.split(',')
|
|
314
323
|
.map((s) => s.trim())
|
|
@@ -320,7 +329,7 @@ export async function executeMetaTool(
|
|
|
320
329
|
const namespace = serverId ?? serverName;
|
|
321
330
|
|
|
322
331
|
for (const requestedToolName of requested) {
|
|
323
|
-
const { tool, error } = resolveToolSchema(requestedToolName, namespace, {
|
|
332
|
+
const { tool, error } = await resolveToolSchema(requestedToolName, namespace, {
|
|
324
333
|
allowServerNameFragment: Boolean(serverName && !serverId),
|
|
325
334
|
});
|
|
326
335
|
if (error) {
|
|
@@ -410,7 +419,7 @@ export async function executeMetaTool(
|
|
|
410
419
|
case 'mcp_get_tool_schema': {
|
|
411
420
|
const name = String(args.toolName ?? '');
|
|
412
421
|
const namespace = String(args.serverId ?? '') || undefined;
|
|
413
|
-
const { tool, error } = resolveToolSchema(name, namespace);
|
|
422
|
+
const { tool, error } = await resolveToolSchema(name, namespace);
|
|
414
423
|
|
|
415
424
|
if (error) {
|
|
416
425
|
return error;
|
|
@@ -461,7 +470,7 @@ export async function executeMetaTool(
|
|
|
461
470
|
}
|
|
462
471
|
|
|
463
472
|
// Verify the tool exists in our index
|
|
464
|
-
const { tool, error } = resolveToolSchema(targetToolName, namespace);
|
|
473
|
+
const { tool, error } = await resolveToolSchema(targetToolName, namespace);
|
|
465
474
|
if (error) {
|
|
466
475
|
return error;
|
|
467
476
|
}
|
|
@@ -274,7 +274,7 @@ export class ToolRouter {
|
|
|
274
274
|
namespace?: string,
|
|
275
275
|
options: ToolLookupOptions = {}
|
|
276
276
|
): IndexedTool | undefined {
|
|
277
|
-
const matches = this.
|
|
277
|
+
const matches = this.getIndexedToolMatches(toolName, namespace, options);
|
|
278
278
|
|
|
279
279
|
if (matches.length === 0) return undefined;
|
|
280
280
|
|
|
@@ -289,6 +289,19 @@ export class ToolRouter {
|
|
|
289
289
|
return matches[0];
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Resolve the full tool definition by name, ensuring the router index has
|
|
294
|
+
* been initialized first.
|
|
295
|
+
*/
|
|
296
|
+
async resolveToolSchema(
|
|
297
|
+
toolName: string,
|
|
298
|
+
namespace?: string,
|
|
299
|
+
options: ToolLookupOptions = {}
|
|
300
|
+
): Promise<IndexedTool | undefined> {
|
|
301
|
+
await this.ensureInitialized();
|
|
302
|
+
return this.getToolSchema(toolName, namespace, options);
|
|
303
|
+
}
|
|
304
|
+
|
|
292
305
|
/**
|
|
293
306
|
* Get compact (schema-less) summaries for all tools.
|
|
294
307
|
*/
|
|
@@ -533,6 +546,37 @@ export class ToolRouter {
|
|
|
533
546
|
private getDirectlyVisibleTools(): IndexedTool[] {
|
|
534
547
|
return this.allTools.filter((tool) => !this.matchesDeferredTool(tool) || this.matchesPinnedTool(tool.name));
|
|
535
548
|
}
|
|
549
|
+
|
|
550
|
+
private getIndexedToolMatches(
|
|
551
|
+
toolName: string,
|
|
552
|
+
namespace?: string,
|
|
553
|
+
options: ToolLookupOptions = {}
|
|
554
|
+
): IndexedTool[] {
|
|
555
|
+
const indexedMatches = this.index.getTool(toolName, namespace, options);
|
|
556
|
+
if (indexedMatches.length > 0 || !this.matchesPinnedTool(toolName)) {
|
|
557
|
+
return indexedMatches;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
return this.matchTools(this.pinnedTools.filter((tool) => tool.name === toolName), namespace, options);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
private matchTools(
|
|
564
|
+
tools: IndexedTool[],
|
|
565
|
+
namespace?: string,
|
|
566
|
+
options: ToolLookupOptions = {}
|
|
567
|
+
): IndexedTool[] {
|
|
568
|
+
if (!namespace) return tools;
|
|
569
|
+
|
|
570
|
+
const exactMatches = tools.filter(
|
|
571
|
+
(tool) => tool.sessionId === namespace || tool.serverId === namespace
|
|
572
|
+
);
|
|
573
|
+
if (exactMatches.length > 0) return exactMatches;
|
|
574
|
+
|
|
575
|
+
if (!options.allowServerNameFragment) return [];
|
|
576
|
+
|
|
577
|
+
const namespaceLower = namespace.toLowerCase();
|
|
578
|
+
return tools.filter((tool) => tool.serverName.toLowerCase().includes(namespaceLower));
|
|
579
|
+
}
|
|
536
580
|
}
|
|
537
581
|
|
|
538
582
|
function globToRegExp(pattern: string): RegExp {
|