@mcp-ts/sdk 2.0.0 → 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/dist/adapters/agui-adapter.d.mts +2 -2
- package/dist/adapters/agui-adapter.d.ts +2 -2
- package/dist/adapters/agui-adapter.js +1 -0
- package/dist/adapters/agui-adapter.js.map +1 -1
- package/dist/adapters/agui-adapter.mjs +1 -0
- package/dist/adapters/agui-adapter.mjs.map +1 -1
- package/dist/adapters/agui-middleware.d.mts +2 -2
- package/dist/adapters/agui-middleware.d.ts +2 -2
- package/dist/adapters/ai-adapter.d.mts +2 -2
- package/dist/adapters/ai-adapter.d.ts +2 -2
- package/dist/adapters/ai-adapter.js +1 -0
- package/dist/adapters/ai-adapter.js.map +1 -1
- package/dist/adapters/ai-adapter.mjs +1 -0
- package/dist/adapters/ai-adapter.mjs.map +1 -1
- package/dist/adapters/langchain-adapter.d.mts +2 -2
- package/dist/adapters/langchain-adapter.d.ts +2 -2
- package/dist/adapters/langchain-adapter.js +1 -0
- package/dist/adapters/langchain-adapter.js.map +1 -1
- package/dist/adapters/langchain-adapter.mjs +1 -0
- package/dist/adapters/langchain-adapter.mjs.map +1 -1
- package/dist/client/index.d.mts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/react.d.mts +4 -4
- package/dist/client/react.d.ts +4 -4
- package/dist/client/react.js.map +1 -1
- package/dist/client/react.mjs.map +1 -1
- package/dist/client/vue.d.mts +4 -4
- package/dist/client/vue.d.ts +4 -4
- package/dist/{index-eaH14_5u.d.mts → index-Cfjsme-a.d.mts} +1 -1
- package/dist/{index-C9gvpxy5.d.ts → index-CmjMd2ac.d.ts} +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +27 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -4
- package/dist/index.mjs.map +1 -1
- package/dist/server/index.d.mts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/shared/index.d.mts +6 -6
- package/dist/shared/index.d.ts +6 -6
- package/dist/shared/index.js +27 -4
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +27 -4
- package/dist/shared/index.mjs.map +1 -1
- package/dist/{tool-router-Ddtybmr0.d.ts → tool-router-BP8TT9mI.d.ts} +17 -1
- package/dist/{tool-router-Dnd6IOKC.d.mts → tool-router-BkQnso27.d.mts} +17 -1
- package/dist/{types-BCAG20P6.d.mts → types-CxFaaZrM.d.mts} +2 -1
- package/dist/{types-BCAG20P6.d.ts → types-CxFaaZrM.d.ts} +2 -1
- package/package.json +1 -1
- package/src/shared/meta-tools.ts +5 -4
- package/src/shared/tool-index.ts +1 -0
- package/src/shared/tool-router.ts +38 -3
- package/src/shared/types.ts +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import { u as ToolClientProvider, T as ToolClient } from './types-
|
|
2
|
+
import { u as ToolClientProvider, T as ToolClient } from './types-CxFaaZrM.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolIndex — Lightweight in-memory search index for MCP tool discovery.
|
|
@@ -64,6 +64,7 @@ interface IndexedTool extends Tool {
|
|
|
64
64
|
sessionId: string;
|
|
65
65
|
serverId: string;
|
|
66
66
|
serverName: string;
|
|
67
|
+
outputSchema?: Tool['outputSchema'];
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* An optional embedding function supplied by the consumer.
|
|
@@ -268,6 +269,15 @@ interface ToolRouterOptions {
|
|
|
268
269
|
* @default false
|
|
269
270
|
*/
|
|
270
271
|
compactSchemas?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Tool names to expose directly when using `search` strategy.
|
|
274
|
+
* Pinned tools are removed from discovery results and should be called directly.
|
|
275
|
+
*/
|
|
276
|
+
pinnedTools?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* Tool names or glob-style patterns to omit entirely from the router catalog.
|
|
279
|
+
*/
|
|
280
|
+
excludeTools?: string[];
|
|
271
281
|
/**
|
|
272
282
|
* Optional embedding function for semantic search.
|
|
273
283
|
* When not provided, keyword TF-IDF matching is used.
|
|
@@ -295,12 +305,16 @@ declare class ToolRouter {
|
|
|
295
305
|
private options;
|
|
296
306
|
private index;
|
|
297
307
|
private allTools;
|
|
308
|
+
private pinnedTools;
|
|
309
|
+
private discoverableTools;
|
|
298
310
|
private groupsMap;
|
|
299
311
|
private strategy;
|
|
300
312
|
private maxTools;
|
|
301
313
|
private compactSchemas;
|
|
302
314
|
private activeGroups;
|
|
303
315
|
private customGroups?;
|
|
316
|
+
private pinnedToolNames;
|
|
317
|
+
private excludeToolMatchers;
|
|
304
318
|
private initialized;
|
|
305
319
|
constructor(client: ToolRouterClientInput, options?: ToolRouterOptions);
|
|
306
320
|
/**
|
|
@@ -370,6 +384,8 @@ declare class ToolRouter {
|
|
|
370
384
|
private getGroupFilteredTools;
|
|
371
385
|
/** The 4 meta-tool definitions exposed in `search` strategy. */
|
|
372
386
|
private getMetaToolDefinitions;
|
|
387
|
+
private matchesPinnedTool;
|
|
388
|
+
private matchesExcludedTool;
|
|
373
389
|
}
|
|
374
390
|
|
|
375
391
|
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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
import { u as ToolClientProvider, T as ToolClient } from './types-
|
|
2
|
+
import { u as ToolClientProvider, T as ToolClient } from './types-CxFaaZrM.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ToolIndex — Lightweight in-memory search index for MCP tool discovery.
|
|
@@ -64,6 +64,7 @@ interface IndexedTool extends Tool {
|
|
|
64
64
|
sessionId: string;
|
|
65
65
|
serverId: string;
|
|
66
66
|
serverName: string;
|
|
67
|
+
outputSchema?: Tool['outputSchema'];
|
|
67
68
|
}
|
|
68
69
|
/**
|
|
69
70
|
* An optional embedding function supplied by the consumer.
|
|
@@ -268,6 +269,15 @@ interface ToolRouterOptions {
|
|
|
268
269
|
* @default false
|
|
269
270
|
*/
|
|
270
271
|
compactSchemas?: boolean;
|
|
272
|
+
/**
|
|
273
|
+
* Tool names to expose directly when using `search` strategy.
|
|
274
|
+
* Pinned tools are removed from discovery results and should be called directly.
|
|
275
|
+
*/
|
|
276
|
+
pinnedTools?: string[];
|
|
277
|
+
/**
|
|
278
|
+
* Tool names or glob-style patterns to omit entirely from the router catalog.
|
|
279
|
+
*/
|
|
280
|
+
excludeTools?: string[];
|
|
271
281
|
/**
|
|
272
282
|
* Optional embedding function for semantic search.
|
|
273
283
|
* When not provided, keyword TF-IDF matching is used.
|
|
@@ -295,12 +305,16 @@ declare class ToolRouter {
|
|
|
295
305
|
private options;
|
|
296
306
|
private index;
|
|
297
307
|
private allTools;
|
|
308
|
+
private pinnedTools;
|
|
309
|
+
private discoverableTools;
|
|
298
310
|
private groupsMap;
|
|
299
311
|
private strategy;
|
|
300
312
|
private maxTools;
|
|
301
313
|
private compactSchemas;
|
|
302
314
|
private activeGroups;
|
|
303
315
|
private customGroups?;
|
|
316
|
+
private pinnedToolNames;
|
|
317
|
+
private excludeToolMatchers;
|
|
304
318
|
private initialized;
|
|
305
319
|
constructor(client: ToolRouterClientInput, options?: ToolRouterOptions);
|
|
306
320
|
/**
|
|
@@ -370,6 +384,8 @@ declare class ToolRouter {
|
|
|
370
384
|
private getGroupFilteredTools;
|
|
371
385
|
/** The 4 meta-tool definitions exposed in `search` strategy. */
|
|
372
386
|
private getMetaToolDefinitions;
|
|
387
|
+
private matchesPinnedTool;
|
|
388
|
+
private matchesExcludedTool;
|
|
373
389
|
}
|
|
374
390
|
|
|
375
391
|
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 };
|
|
@@ -79,7 +79,8 @@ declare function isCallToolSuccess(response: CallToolResponse): response is Call
|
|
|
79
79
|
type ToolInfo = {
|
|
80
80
|
name: string;
|
|
81
81
|
description?: string;
|
|
82
|
-
inputSchema?:
|
|
82
|
+
inputSchema?: Tool['inputSchema'];
|
|
83
|
+
outputSchema?: Tool['outputSchema'];
|
|
83
84
|
};
|
|
84
85
|
type TransportType = 'sse' | 'streamable-http';
|
|
85
86
|
type McpRpcMethod = 'connect' | 'disconnect' | 'listTools' | 'callTool' | 'listSessions' | 'getSession' | 'finishAuth' | 'listPrompts' | 'getPrompt' | 'listResources' | 'readResource';
|
|
@@ -79,7 +79,8 @@ declare function isCallToolSuccess(response: CallToolResponse): response is Call
|
|
|
79
79
|
type ToolInfo = {
|
|
80
80
|
name: string;
|
|
81
81
|
description?: string;
|
|
82
|
-
inputSchema?:
|
|
82
|
+
inputSchema?: Tool['inputSchema'];
|
|
83
|
+
outputSchema?: Tool['outputSchema'];
|
|
83
84
|
};
|
|
84
85
|
type TransportType = 'sse' | 'streamable-http';
|
|
85
86
|
type McpRpcMethod = 'connect' | 'disconnect' | 'listTools' | 'callTool' | 'listSessions' | 'getSession' | 'finishAuth' | 'listPrompts' | 'getPrompt' | 'listResources' | 'readResource';
|
package/package.json
CHANGED
package/src/shared/meta-tools.ts
CHANGED
|
@@ -135,16 +135,16 @@ export function createRegexSearchToolDefinition(): Tool {
|
|
|
135
135
|
*
|
|
136
136
|
* After discovering tools via `mcp_search_tools` or
|
|
137
137
|
* `mcp_search_tool_regex`, the LLM calls this to load the full
|
|
138
|
-
*
|
|
139
|
-
* arguments.
|
|
138
|
+
* input and output schemas for a specific tool so it can construct the
|
|
139
|
+
* correct arguments and plan around the result shape.
|
|
140
140
|
*/
|
|
141
141
|
export function createGetSchemaToolDefinition(): Tool {
|
|
142
142
|
return {
|
|
143
143
|
name: 'mcp_get_tool_schema',
|
|
144
144
|
description:
|
|
145
|
-
'Get the full input schema (parameters) for a specific tool. ' +
|
|
145
|
+
'Get the full input schema (parameters) and output schema (result shape) for a specific tool. ' +
|
|
146
146
|
'Call this after mcp_search_tools to get the parameter details ' +
|
|
147
|
-
'needed to call a tool correctly. ' +
|
|
147
|
+
'needed to call a tool correctly and understand what it returns. ' +
|
|
148
148
|
'Do NOT call the discovered tool directly; after reading the schema, call mcp_execute_tool.',
|
|
149
149
|
inputSchema: {
|
|
150
150
|
type: 'object' as const,
|
|
@@ -432,6 +432,7 @@ export async function executeMetaTool(
|
|
|
432
432
|
name: tool.name,
|
|
433
433
|
description: tool.description,
|
|
434
434
|
inputSchema: tool.inputSchema,
|
|
435
|
+
outputSchema: tool.outputSchema,
|
|
435
436
|
executionInstructions: {
|
|
436
437
|
nextTool: 'mcp_execute_tool',
|
|
437
438
|
toolName: tool.name,
|
package/src/shared/tool-index.ts
CHANGED
|
@@ -99,6 +99,17 @@ export interface ToolRouterOptions {
|
|
|
99
99
|
*/
|
|
100
100
|
compactSchemas?: boolean;
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Tool names to expose directly when using `search` strategy.
|
|
104
|
+
* Pinned tools are removed from discovery results and should be called directly.
|
|
105
|
+
*/
|
|
106
|
+
pinnedTools?: string[];
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Tool names or glob-style patterns to omit entirely from the router catalog.
|
|
110
|
+
*/
|
|
111
|
+
excludeTools?: string[];
|
|
112
|
+
|
|
102
113
|
/**
|
|
103
114
|
* Optional embedding function for semantic search.
|
|
104
115
|
* When not provided, keyword TF-IDF matching is used.
|
|
@@ -136,12 +147,16 @@ export type ToolRouterClientInput = ToolClientProvider | ToolClient[];
|
|
|
136
147
|
export class ToolRouter {
|
|
137
148
|
private index: ToolIndex;
|
|
138
149
|
private allTools: IndexedTool[] = [];
|
|
150
|
+
private pinnedTools: IndexedTool[] = [];
|
|
151
|
+
private discoverableTools: IndexedTool[] = [];
|
|
139
152
|
private groupsMap = new Map<string, ToolGroupInfo>();
|
|
140
153
|
private strategy: ToolRouterStrategy;
|
|
141
154
|
private maxTools: number;
|
|
142
155
|
private compactSchemas: boolean;
|
|
143
156
|
private activeGroups: Set<string>;
|
|
144
157
|
private customGroups?: Record<string, string[]>;
|
|
158
|
+
private pinnedToolNames: Set<string>;
|
|
159
|
+
private excludeToolMatchers: RegExp[];
|
|
145
160
|
private initialized = false;
|
|
146
161
|
|
|
147
162
|
constructor(
|
|
@@ -153,6 +168,10 @@ export class ToolRouter {
|
|
|
153
168
|
this.compactSchemas = options.compactSchemas ?? false;
|
|
154
169
|
this.activeGroups = new Set(options.activeGroups ?? []);
|
|
155
170
|
this.customGroups = options.groups;
|
|
171
|
+
this.pinnedToolNames = new Set(options.pinnedTools ?? []);
|
|
172
|
+
this.excludeToolMatchers = (options.excludeTools ?? []).map((pattern) =>
|
|
173
|
+
globToRegExp(pattern)
|
|
174
|
+
);
|
|
156
175
|
|
|
157
176
|
this.index = new ToolIndex({
|
|
158
177
|
embedFn: options.embedFn,
|
|
@@ -177,7 +196,7 @@ export class ToolRouter {
|
|
|
177
196
|
|
|
178
197
|
switch (this.strategy) {
|
|
179
198
|
case 'search':
|
|
180
|
-
return this.getMetaToolDefinitions();
|
|
199
|
+
return [...this.getMetaToolDefinitions(), ...this.pinnedTools];
|
|
181
200
|
|
|
182
201
|
case 'groups':
|
|
183
202
|
return this.getGroupFilteredTools();
|
|
@@ -352,8 +371,11 @@ export class ToolRouter {
|
|
|
352
371
|
private async ensureInitialized(): Promise<void> {
|
|
353
372
|
if (this.initialized) return;
|
|
354
373
|
|
|
355
|
-
|
|
356
|
-
|
|
374
|
+
const fetchedTools = await this.fetchAllTools();
|
|
375
|
+
this.allTools = fetchedTools.filter((tool) => !this.matchesExcludedTool(tool.name));
|
|
376
|
+
this.pinnedTools = this.allTools.filter((tool) => this.matchesPinnedTool(tool.name));
|
|
377
|
+
this.discoverableTools = this.allTools.filter((tool) => !this.matchesPinnedTool(tool.name));
|
|
378
|
+
await this.index.buildIndex(this.discoverableTools);
|
|
357
379
|
this.buildGroups();
|
|
358
380
|
this.initialized = true;
|
|
359
381
|
}
|
|
@@ -476,4 +498,17 @@ export class ToolRouter {
|
|
|
476
498
|
];
|
|
477
499
|
}
|
|
478
500
|
|
|
501
|
+
private matchesPinnedTool(toolName: string): boolean {
|
|
502
|
+
return this.pinnedToolNames.has(toolName);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
private matchesExcludedTool(toolName: string): boolean {
|
|
506
|
+
return this.excludeToolMatchers.some((matcher) => matcher.test(toolName));
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
function globToRegExp(pattern: string): RegExp {
|
|
511
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&');
|
|
512
|
+
const regexPattern = `^${escaped.replace(/\*/g, '.*')}$`;
|
|
513
|
+
return new RegExp(regexPattern);
|
|
479
514
|
}
|
package/src/shared/types.ts
CHANGED