@1mcp/agent 0.29.2 → 0.30.0-beta1
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/build/commands/serve/index.d.ts +58 -0
- package/build/commands/serve/index.d.ts.map +1 -1
- package/build/commands/serve/index.js +70 -0
- package/build/commands/serve/index.js.map +1 -1
- package/build/commands/serve/serve.d.ts +11 -0
- package/build/commands/serve/serve.d.ts.map +1 -1
- package/build/commands/serve/serve.js +73 -1
- package/build/commands/serve/serve.js.map +1 -1
- package/build/constants/mcp.d.ts +1 -1
- package/build/constants/mcp.d.ts.map +1 -1
- package/build/constants/mcp.js +1 -1
- package/build/constants/mcp.js.map +1 -1
- package/build/core/capabilities/capabilityAggregator.d.ts.map +1 -1
- package/build/core/capabilities/capabilityAggregator.js +42 -18
- package/build/core/capabilities/capabilityAggregator.js.map +1 -1
- package/build/core/capabilities/capabilityManager.d.ts +3 -2
- package/build/core/capabilities/capabilityManager.d.ts.map +1 -1
- package/build/core/capabilities/capabilityManager.js +3 -3
- package/build/core/capabilities/capabilityManager.js.map +1 -1
- package/build/core/capabilities/internal/installationTools.d.ts.map +1 -1
- package/build/core/capabilities/internal/installationTools.js +4 -0
- package/build/core/capabilities/internal/installationTools.js.map +1 -1
- package/build/core/capabilities/internal/lazyTools.d.ts +11 -0
- package/build/core/capabilities/internal/lazyTools.d.ts.map +1 -0
- package/build/core/capabilities/internal/lazyTools.js +48 -0
- package/build/core/capabilities/internal/lazyTools.js.map +1 -0
- package/build/core/capabilities/internal/managementTools.d.ts.map +1 -1
- package/build/core/capabilities/internal/managementTools.js +9 -0
- package/build/core/capabilities/internal/managementTools.js.map +1 -1
- package/build/core/capabilities/internalCapabilitiesProvider.d.ts +7 -1
- package/build/core/capabilities/internalCapabilitiesProvider.d.ts.map +1 -1
- package/build/core/capabilities/internalCapabilitiesProvider.js +31 -2
- package/build/core/capabilities/internalCapabilitiesProvider.js.map +1 -1
- package/build/core/capabilities/lazyLoadingOrchestrator.d.ts +175 -0
- package/build/core/capabilities/lazyLoadingOrchestrator.d.ts.map +1 -0
- package/build/core/capabilities/lazyLoadingOrchestrator.js +515 -0
- package/build/core/capabilities/lazyLoadingOrchestrator.js.map +1 -0
- package/build/core/capabilities/metaToolProvider.d.ts +118 -0
- package/build/core/capabilities/metaToolProvider.d.ts.map +1 -0
- package/build/core/capabilities/metaToolProvider.js +374 -0
- package/build/core/capabilities/metaToolProvider.js.map +1 -0
- package/build/core/capabilities/schemaCache.d.ts +124 -0
- package/build/core/capabilities/schemaCache.d.ts.map +1 -0
- package/build/core/capabilities/schemaCache.js +248 -0
- package/build/core/capabilities/schemaCache.js.map +1 -0
- package/build/core/capabilities/schemas/metaToolSchemas.d.ts +92 -0
- package/build/core/capabilities/schemas/metaToolSchemas.d.ts.map +1 -0
- package/build/core/capabilities/schemas/metaToolSchemas.js +68 -0
- package/build/core/capabilities/schemas/metaToolSchemas.js.map +1 -0
- package/build/core/capabilities/toolRegistry.d.ts +140 -0
- package/build/core/capabilities/toolRegistry.d.ts.map +1 -0
- package/build/core/capabilities/toolRegistry.js +284 -0
- package/build/core/capabilities/toolRegistry.js.map +1 -0
- package/build/core/client/clientManager.d.ts.map +1 -1
- package/build/core/client/clientManager.js +11 -5
- package/build/core/client/clientManager.js.map +1 -1
- package/build/core/flags/flagManager.d.ts.map +1 -1
- package/build/core/flags/flagManager.js +14 -1
- package/build/core/flags/flagManager.js.map +1 -1
- package/build/core/instructions/instructionAggregator.d.ts +21 -0
- package/build/core/instructions/instructionAggregator.d.ts.map +1 -1
- package/build/core/instructions/instructionAggregator.js +78 -3
- package/build/core/instructions/instructionAggregator.js.map +1 -1
- package/build/core/instructions/templateTypes.d.ts +40 -1
- package/build/core/instructions/templateTypes.d.ts.map +1 -1
- package/build/core/instructions/templateTypes.js +70 -0
- package/build/core/instructions/templateTypes.js.map +1 -1
- package/build/core/protocol/requestHandlers.d.ts +2 -1
- package/build/core/protocol/requestHandlers.d.ts.map +1 -1
- package/build/core/protocol/requestHandlers.js +112 -84
- package/build/core/protocol/requestHandlers.js.map +1 -1
- package/build/core/server/adapters/ExternalServerAdapter.d.ts +38 -0
- package/build/core/server/adapters/ExternalServerAdapter.d.ts.map +1 -0
- package/build/core/server/adapters/ExternalServerAdapter.js +50 -0
- package/build/core/server/adapters/ExternalServerAdapter.js.map +1 -0
- package/build/core/server/adapters/ServerRegistry.d.ts +63 -0
- package/build/core/server/adapters/ServerRegistry.d.ts.map +1 -0
- package/build/core/server/adapters/ServerRegistry.js +92 -0
- package/build/core/server/adapters/ServerRegistry.js.map +1 -0
- package/build/core/server/adapters/TemplateServerAdapter.d.ts +47 -0
- package/build/core/server/adapters/TemplateServerAdapter.d.ts.map +1 -0
- package/build/core/server/adapters/TemplateServerAdapter.js +99 -0
- package/build/core/server/adapters/TemplateServerAdapter.js.map +1 -0
- package/build/core/server/adapters/index.d.ts +5 -0
- package/build/core/server/adapters/index.d.ts.map +1 -0
- package/build/core/server/adapters/index.js +6 -0
- package/build/core/server/adapters/index.js.map +1 -0
- package/build/core/server/adapters/types.d.ts +122 -0
- package/build/core/server/adapters/types.d.ts.map +1 -0
- package/build/core/server/adapters/types.js +48 -0
- package/build/core/server/adapters/types.js.map +1 -0
- package/build/core/server/agentConfig.d.ts +19 -0
- package/build/core/server/agentConfig.d.ts.map +1 -1
- package/build/core/server/agentConfig.js +19 -0
- package/build/core/server/agentConfig.js.map +1 -1
- package/build/core/server/connectionManager.d.ts +17 -1
- package/build/core/server/connectionManager.d.ts.map +1 -1
- package/build/core/server/connectionManager.js +65 -5
- package/build/core/server/connectionManager.js.map +1 -1
- package/build/core/server/connectionResolver.d.ts +81 -0
- package/build/core/server/connectionResolver.d.ts.map +1 -0
- package/build/core/server/connectionResolver.js +140 -0
- package/build/core/server/connectionResolver.js.map +1 -0
- package/build/core/server/serverManager.d.ts +13 -0
- package/build/core/server/serverManager.d.ts.map +1 -1
- package/build/core/server/serverManager.js +49 -2
- package/build/core/server/serverManager.js.map +1 -1
- package/build/core/server/templateServerManager.d.ts +16 -0
- package/build/core/server/templateServerManager.d.ts.map +1 -1
- package/build/core/server/templateServerManager.js +45 -0
- package/build/core/server/templateServerManager.js.map +1 -1
- package/build/domains/preset/manager/presetManager.d.ts +5 -0
- package/build/domains/preset/manager/presetManager.d.ts.map +1 -1
- package/build/domains/preset/manager/presetManager.js +7 -0
- package/build/domains/preset/manager/presetManager.js.map +1 -1
- package/build/logger/logger.d.ts +13 -0
- package/build/logger/logger.d.ts.map +1 -1
- package/build/logger/logger.js +41 -0
- package/build/logger/logger.js.map +1 -1
- package/build/server.d.ts +3 -0
- package/build/server.d.ts.map +1 -1
- package/build/server.js +32 -0
- package/build/server.js.map +1 -1
- package/build/transport/http/middlewares/tagsExtractor.d.ts.map +1 -1
- package/build/transport/http/middlewares/tagsExtractor.js +71 -1
- package/build/transport/http/middlewares/tagsExtractor.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
import { ConnectionResolver } from '../../core/server/connectionResolver.js';
|
|
2
|
+
import logger, { debugIf, errorIf } from '../../logger/logger.js';
|
|
3
|
+
import { zodToInputSchema, zodToOutputSchema } from '../../utils/schemaUtils.js';
|
|
4
|
+
import { ToolInvokeInputSchema, ToolInvokeOutputSchema, ToolListInputSchema, ToolListOutputSchema, ToolSchemaInputSchema, ToolSchemaOutputSchema, } from './schemas/metaToolSchemas.js';
|
|
5
|
+
/**
|
|
6
|
+
* MetaToolProvider provides meta-tools for lazy loading:
|
|
7
|
+
* 1. tool_list - List all tools (names + descriptions only)
|
|
8
|
+
* 2. tool_schema - Get full tool schema on-demand
|
|
9
|
+
* 3. tool_invoke - Invoke any tool by server and name
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const provider = new MetaToolProvider(() => toolRegistry, schemaCache, outboundConnections, loadSchemaFn);
|
|
14
|
+
* const tools = provider.getMetaTools();
|
|
15
|
+
* const result = await provider.callMetaTool('tool_list', { server: 'filesystem' });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class MetaToolProvider {
|
|
19
|
+
getToolRegistry;
|
|
20
|
+
schemaCache;
|
|
21
|
+
outboundConnections;
|
|
22
|
+
loadSchema;
|
|
23
|
+
allowedServers;
|
|
24
|
+
connectionResolver;
|
|
25
|
+
constructor(getToolRegistry, schemaCache, outboundConnections, loadSchema, allowedServers, templateHashProvider) {
|
|
26
|
+
this.getToolRegistry = getToolRegistry;
|
|
27
|
+
this.schemaCache = schemaCache;
|
|
28
|
+
this.outboundConnections = outboundConnections;
|
|
29
|
+
this.loadSchema = loadSchema;
|
|
30
|
+
this.allowedServers = allowedServers;
|
|
31
|
+
this.connectionResolver = new ConnectionResolver(outboundConnections, templateHashProvider);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolve a clean server name to the actual connection key.
|
|
35
|
+
* Delegates to ConnectionResolver.findByServerName for unified resolution logic.
|
|
36
|
+
*
|
|
37
|
+
* @param cleanServerName - The clean server name (without hash suffix)
|
|
38
|
+
* @returns The actual connection key, or the original name if not found
|
|
39
|
+
*/
|
|
40
|
+
resolveConnectionKey(cleanServerName) {
|
|
41
|
+
const result = this.connectionResolver.findByServerName(cleanServerName);
|
|
42
|
+
return result?.key ?? cleanServerName;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Set the allowed servers filter
|
|
46
|
+
* @param serverNames - Set of server names to allow, or undefined to allow all
|
|
47
|
+
*/
|
|
48
|
+
setAllowedServers(serverNames) {
|
|
49
|
+
this.allowedServers = serverNames;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the current tool registry, optionally filtered by allowed servers
|
|
53
|
+
*/
|
|
54
|
+
toolRegistry() {
|
|
55
|
+
const registry = this.getToolRegistry();
|
|
56
|
+
if (this.allowedServers !== undefined) {
|
|
57
|
+
return registry.filterByServers(this.allowedServers);
|
|
58
|
+
}
|
|
59
|
+
return registry;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get all available meta-tools (3 discovery tools)
|
|
63
|
+
*/
|
|
64
|
+
getMetaTools() {
|
|
65
|
+
return [this.createListToolsMetaTool(), this.createDescribeToolMetaTool(), this.createCallToolMetaTool()];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Call a meta-tool by name
|
|
69
|
+
*/
|
|
70
|
+
async callMetaTool(name, args) {
|
|
71
|
+
switch (name) {
|
|
72
|
+
case 'tool_list': {
|
|
73
|
+
const parsed = ToolListInputSchema.safeParse(args);
|
|
74
|
+
if (!parsed.success) {
|
|
75
|
+
return {
|
|
76
|
+
tools: [],
|
|
77
|
+
totalCount: 0,
|
|
78
|
+
servers: [],
|
|
79
|
+
hasMore: false,
|
|
80
|
+
error: {
|
|
81
|
+
type: 'validation',
|
|
82
|
+
message: `Invalid arguments for tool_list: ${parsed.error.message}`,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return this.listAvailableTools(parsed.data);
|
|
87
|
+
}
|
|
88
|
+
case 'tool_schema': {
|
|
89
|
+
const parsed = ToolSchemaInputSchema.safeParse(args);
|
|
90
|
+
if (!parsed.success) {
|
|
91
|
+
return {
|
|
92
|
+
schema: {},
|
|
93
|
+
error: {
|
|
94
|
+
type: 'validation',
|
|
95
|
+
message: `Invalid arguments for tool_schema: ${parsed.error.message}`,
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return this.describeTool(parsed.data);
|
|
100
|
+
}
|
|
101
|
+
case 'tool_invoke': {
|
|
102
|
+
const parsed = ToolInvokeInputSchema.safeParse(args);
|
|
103
|
+
if (!parsed.success) {
|
|
104
|
+
return {
|
|
105
|
+
result: {},
|
|
106
|
+
server: '',
|
|
107
|
+
tool: '',
|
|
108
|
+
error: {
|
|
109
|
+
type: 'validation',
|
|
110
|
+
message: `Invalid arguments for tool_invoke: ${parsed.error.message}`,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return this.callTool(parsed.data);
|
|
115
|
+
}
|
|
116
|
+
default:
|
|
117
|
+
return {
|
|
118
|
+
tools: [],
|
|
119
|
+
totalCount: 0,
|
|
120
|
+
servers: [],
|
|
121
|
+
hasMore: false,
|
|
122
|
+
error: {
|
|
123
|
+
type: 'not_found',
|
|
124
|
+
message: `Unknown meta-tool: ${name}. Valid meta-tools are: tool_list, tool_schema, tool_invoke`,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Create the tool_list meta-tool
|
|
131
|
+
*/
|
|
132
|
+
createListToolsMetaTool() {
|
|
133
|
+
return {
|
|
134
|
+
name: 'tool_list',
|
|
135
|
+
description: 'List all available MCP tools with names and descriptions. Use for tool discovery.',
|
|
136
|
+
inputSchema: zodToInputSchema(ToolListInputSchema),
|
|
137
|
+
outputSchema: zodToOutputSchema(ToolListOutputSchema),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Implement tool_list
|
|
142
|
+
*/
|
|
143
|
+
async listAvailableTools(args) {
|
|
144
|
+
try {
|
|
145
|
+
const registry = this.toolRegistry();
|
|
146
|
+
const result = registry.listTools(args);
|
|
147
|
+
// Format tools for response
|
|
148
|
+
const tools = result.tools.map((tool) => ({
|
|
149
|
+
name: tool.name,
|
|
150
|
+
server: tool.server,
|
|
151
|
+
description: tool.description,
|
|
152
|
+
tags: tool.tags,
|
|
153
|
+
}));
|
|
154
|
+
// Get unique servers from filtered results to keep output consistent with applied filters
|
|
155
|
+
const servers = Array.from(new Set(result.tools.map((t) => t.server))).sort();
|
|
156
|
+
// Return structured result matching outputSchema
|
|
157
|
+
const response = {
|
|
158
|
+
tools,
|
|
159
|
+
totalCount: result.totalCount,
|
|
160
|
+
servers,
|
|
161
|
+
hasMore: result.hasMore,
|
|
162
|
+
...(result.nextCursor ? { nextCursor: result.nextCursor } : {}),
|
|
163
|
+
};
|
|
164
|
+
return response;
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
168
|
+
errorIf(() => ({
|
|
169
|
+
message: 'Error in tool_list meta-tool',
|
|
170
|
+
meta: { args, error: errorMessage },
|
|
171
|
+
}));
|
|
172
|
+
return {
|
|
173
|
+
tools: [],
|
|
174
|
+
totalCount: 0,
|
|
175
|
+
servers: [],
|
|
176
|
+
hasMore: false,
|
|
177
|
+
error: {
|
|
178
|
+
type: 'internal',
|
|
179
|
+
message: `Internal error listing tools: ${errorMessage}`,
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Create the tool_schema meta-tool
|
|
186
|
+
*/
|
|
187
|
+
createDescribeToolMetaTool() {
|
|
188
|
+
return {
|
|
189
|
+
name: 'tool_schema',
|
|
190
|
+
description: 'Get the full schema for a specific tool including input validation rules',
|
|
191
|
+
inputSchema: zodToInputSchema(ToolSchemaInputSchema),
|
|
192
|
+
outputSchema: zodToOutputSchema(ToolSchemaOutputSchema),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Implement tool_schema
|
|
197
|
+
*/
|
|
198
|
+
async describeTool(args) {
|
|
199
|
+
try {
|
|
200
|
+
// Validate arguments
|
|
201
|
+
if (!args.server || !args.toolName) {
|
|
202
|
+
return {
|
|
203
|
+
schema: {},
|
|
204
|
+
error: {
|
|
205
|
+
type: 'validation',
|
|
206
|
+
message: 'Validation Error: "server" and "toolName" are required parameters',
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
// Check if tool exists in registry
|
|
211
|
+
if (!this.toolRegistry().hasTool(args.server, args.toolName)) {
|
|
212
|
+
return {
|
|
213
|
+
schema: {},
|
|
214
|
+
error: {
|
|
215
|
+
type: 'not_found',
|
|
216
|
+
message: `Tool not found: ${args.server}:${args.toolName}. Call tool_list to see available tools.`,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
// Try to get from cache first
|
|
221
|
+
const cached = this.schemaCache.getIfCached(args.server, args.toolName);
|
|
222
|
+
if (cached) {
|
|
223
|
+
debugIf(() => ({ message: `Cache hit for tool schema: ${args.server}:${args.toolName}` }));
|
|
224
|
+
return {
|
|
225
|
+
schema: cached,
|
|
226
|
+
fromCache: true,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
// Not in cache - load from server if SchemaLoader is available
|
|
230
|
+
if (this.loadSchema) {
|
|
231
|
+
try {
|
|
232
|
+
debugIf(() => ({ message: `Loading schema from server: ${args.server}:${args.toolName}` }));
|
|
233
|
+
// Resolve the clean server name to the actual connection key
|
|
234
|
+
const connectionKey = this.resolveConnectionKey(args.server);
|
|
235
|
+
const tool = await this.loadSchema(connectionKey, args.toolName);
|
|
236
|
+
// Cache the loaded schema
|
|
237
|
+
await this.schemaCache.preload([{ server: args.server, toolName: args.toolName }], async (s, t) => {
|
|
238
|
+
if (s === args.server && t === args.toolName) {
|
|
239
|
+
return tool;
|
|
240
|
+
}
|
|
241
|
+
throw new Error('Unexpected preload request');
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
schema: tool,
|
|
245
|
+
fromCache: false,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
catch (loadError) {
|
|
249
|
+
return {
|
|
250
|
+
schema: {},
|
|
251
|
+
error: {
|
|
252
|
+
type: 'upstream',
|
|
253
|
+
message: `Failed to load schema from server: ${loadError}`,
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// No SchemaLoader available - return error
|
|
259
|
+
return {
|
|
260
|
+
schema: {},
|
|
261
|
+
error: {
|
|
262
|
+
type: 'internal',
|
|
263
|
+
message: 'Tool schema not loaded and no SchemaLoader available. Please use the tool invocation flow to load schema on first use.',
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
269
|
+
errorIf(() => ({
|
|
270
|
+
message: 'Error in tool_schema meta-tool',
|
|
271
|
+
meta: { server: args.server, toolName: args.toolName, error: errorMessage },
|
|
272
|
+
}));
|
|
273
|
+
return {
|
|
274
|
+
schema: {},
|
|
275
|
+
error: {
|
|
276
|
+
type: 'internal',
|
|
277
|
+
message: `Internal error describing tool: ${errorMessage}`,
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Create the tool_invoke meta-tool
|
|
284
|
+
*/
|
|
285
|
+
createCallToolMetaTool() {
|
|
286
|
+
return {
|
|
287
|
+
name: 'tool_invoke',
|
|
288
|
+
description: 'Execute any tool on any MCP server with proper argument validation',
|
|
289
|
+
inputSchema: zodToInputSchema(ToolInvokeInputSchema),
|
|
290
|
+
outputSchema: zodToOutputSchema(ToolInvokeOutputSchema),
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Implement tool_invoke
|
|
295
|
+
*/
|
|
296
|
+
async callTool(args) {
|
|
297
|
+
try {
|
|
298
|
+
// Validate arguments
|
|
299
|
+
if (!args.server || !args.toolName) {
|
|
300
|
+
return {
|
|
301
|
+
result: {},
|
|
302
|
+
server: args.server,
|
|
303
|
+
tool: args.toolName,
|
|
304
|
+
error: {
|
|
305
|
+
type: 'validation',
|
|
306
|
+
message: 'Validation Error: "server" and "toolName" are required parameters',
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
// Check if tool exists
|
|
311
|
+
if (!this.toolRegistry().hasTool(args.server, args.toolName)) {
|
|
312
|
+
return {
|
|
313
|
+
result: {},
|
|
314
|
+
server: args.server,
|
|
315
|
+
tool: args.toolName,
|
|
316
|
+
error: {
|
|
317
|
+
type: 'not_found',
|
|
318
|
+
message: `Tool not found: ${args.server}:${args.toolName}. Call tool_list to see available tools.`,
|
|
319
|
+
},
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
// Get connection - resolve clean server name to actual connection key
|
|
323
|
+
const connectionKey = this.resolveConnectionKey(args.server);
|
|
324
|
+
const connection = this.outboundConnections.get(connectionKey);
|
|
325
|
+
if (!connection || !connection.client) {
|
|
326
|
+
return {
|
|
327
|
+
result: {},
|
|
328
|
+
server: args.server,
|
|
329
|
+
tool: args.toolName,
|
|
330
|
+
error: {
|
|
331
|
+
type: 'upstream',
|
|
332
|
+
message: `Server not connected: ${args.server}`,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
// Call the tool
|
|
337
|
+
const upstreamResult = await connection.client.callTool({
|
|
338
|
+
name: args.toolName,
|
|
339
|
+
arguments: args.args,
|
|
340
|
+
});
|
|
341
|
+
// Return structured result matching outputSchema
|
|
342
|
+
return {
|
|
343
|
+
result: upstreamResult,
|
|
344
|
+
server: args.server,
|
|
345
|
+
tool: args.toolName,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
catch (error) {
|
|
349
|
+
logger.error(`Error in tool_invoke: ${error}`);
|
|
350
|
+
// Check if it's a tool not found error from upstream
|
|
351
|
+
if (error instanceof Error && error.message.includes('not found')) {
|
|
352
|
+
return {
|
|
353
|
+
result: {},
|
|
354
|
+
server: args.server,
|
|
355
|
+
tool: args.toolName,
|
|
356
|
+
error: {
|
|
357
|
+
type: 'not_found',
|
|
358
|
+
message: `Tool not found: ${args.server}:${args.toolName}`,
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
result: {},
|
|
364
|
+
server: args.server,
|
|
365
|
+
tool: args.toolName,
|
|
366
|
+
error: {
|
|
367
|
+
type: 'upstream',
|
|
368
|
+
message: `Server Error: ${error}. This is an upstream server issue - please report it.`,
|
|
369
|
+
},
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
//# sourceMappingURL=metaToolProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metaToolProvider.js","sourceRoot":"","sources":["../../../src/core/capabilities/metaToolProvider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAwB,MAAM,wCAAwC,CAAC;AAElG,OAAO,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAGhF,OAAO,EACL,qBAAqB,EAErB,sBAAsB,EACtB,mBAAmB,EAEnB,oBAAoB,EACpB,qBAAqB,EAErB,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AAiDtC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,gBAAgB;IACnB,eAAe,CAAuB;IACtC,WAAW,CAAc;IACzB,mBAAmB,CAAsB;IACzC,UAAU,CAAgB;IAC1B,cAAc,CAAe;IAC7B,kBAAkB,CAAqB;IAE/C,YACE,eAAqC,EACrC,WAAwB,EACxB,mBAAwC,EACxC,UAAyB,EACzB,cAA4B,EAC5B,oBAA2C;QAE3C,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,kBAAkB,GAAG,IAAI,kBAAkB,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAAC;IAC9F,CAAC;IAED;;;;;;OAMG;IACK,oBAAoB,CAAC,eAAuB;QAClD,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;QAC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,EAAE,IAAI,CAAC,IAA+B;aAChD,CAAC,CAAC;YAEH,iDAAiD;YACjD,OAAO;gBACL,MAAM,EAAE,cAAc;gBACtB,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;aACpB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,yBAAyB,KAAK,EAAE,CAAC,CAAC;YAE/C,qDAAqD;YACrD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gBAClE,OAAO;oBACL,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE,IAAI,CAAC,MAAM;oBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;oBACnB,KAAK,EAAE;wBACL,IAAI,EAAE,WAAW;wBACjB,OAAO,EAAE,mBAAmB,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,EAAE;qBAC3D;iBACF,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE,IAAI,CAAC,MAAM;gBACnB,IAAI,EAAE,IAAI,CAAC,QAAQ;gBACnB,KAAK,EAAE;oBACL,IAAI,EAAE,UAAU;oBAChB,OAAO,EAAE,iBAAiB,KAAK,wDAAwD;iBACxF;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Tool } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Statistics for schema cache operations
|
|
4
|
+
*/
|
|
5
|
+
export interface SchemaCacheStats {
|
|
6
|
+
hits: number;
|
|
7
|
+
misses: number;
|
|
8
|
+
coalesced: number;
|
|
9
|
+
evictions: number;
|
|
10
|
+
get hitRate(): number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Configuration for SchemaCache
|
|
14
|
+
*/
|
|
15
|
+
export interface SchemaCacheConfig {
|
|
16
|
+
maxEntries: number;
|
|
17
|
+
ttlMs?: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* SchemaCache provides LRU caching for tool schemas with optional TTL and request coalescing.
|
|
21
|
+
*
|
|
22
|
+
* This cache reduces redundant upstream server calls by storing loaded tool schemas
|
|
23
|
+
* and coalescing parallel requests for the same tool.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* const cache = new SchemaCache({ maxEntries: 1000, ttlMs: 3600000 });
|
|
28
|
+
*
|
|
29
|
+
* // Load tool schema (with coalescing for parallel calls)
|
|
30
|
+
* const tool = await cache.getOrLoad('filesystem', 'read_file', async () => {
|
|
31
|
+
* return await fetchSchemaFromServer('filesystem', 'read_file');
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class SchemaCache {
|
|
36
|
+
private cache;
|
|
37
|
+
private inflightRequests;
|
|
38
|
+
private config;
|
|
39
|
+
private stats;
|
|
40
|
+
constructor(config: SchemaCacheConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Generate cache key from server and tool name
|
|
43
|
+
*/
|
|
44
|
+
private getCacheKey;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a cache entry has expired (TTL)
|
|
47
|
+
*/
|
|
48
|
+
private isExpired;
|
|
49
|
+
/**
|
|
50
|
+
* Evict oldest entry when cache is full (FIFO eviction by insertion time)
|
|
51
|
+
* Note: This is not true LRU - for that we'd need to track access order
|
|
52
|
+
*/
|
|
53
|
+
private evictOldest;
|
|
54
|
+
/**
|
|
55
|
+
* Get tool schema from cache or load it using the provided loader function
|
|
56
|
+
* Implements request coalescing for parallel requests to the same tool
|
|
57
|
+
*
|
|
58
|
+
* @param server - Server name
|
|
59
|
+
* @param toolName - Tool name
|
|
60
|
+
* @param loader - Async function to load the tool schema from upstream server
|
|
61
|
+
* @returns Promise resolving to the Tool schema
|
|
62
|
+
*/
|
|
63
|
+
getOrLoad(server: string, toolName: string, loader: (server: string, toolName: string) => Promise<Tool>): Promise<Tool>;
|
|
64
|
+
/**
|
|
65
|
+
* Check if a tool schema is currently cached (and not expired)
|
|
66
|
+
*/
|
|
67
|
+
has(server: string, toolName: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Get cached tool schema without loading (returns null if not cached)
|
|
70
|
+
*/
|
|
71
|
+
getIfCached(server: string, toolName: string): Tool | null;
|
|
72
|
+
/**
|
|
73
|
+
* Manually add a tool schema to the cache
|
|
74
|
+
*/
|
|
75
|
+
set(server: string, toolName: string, tool: Tool): void;
|
|
76
|
+
/**
|
|
77
|
+
* Remove a tool schema from the cache
|
|
78
|
+
*/
|
|
79
|
+
delete(server: string, toolName: string): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Clear all cached schemas
|
|
82
|
+
*/
|
|
83
|
+
clear(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Get current cache statistics
|
|
86
|
+
*/
|
|
87
|
+
getStats(): Readonly<SchemaCacheStats>;
|
|
88
|
+
/**
|
|
89
|
+
* Get current cache size
|
|
90
|
+
*/
|
|
91
|
+
size(): number;
|
|
92
|
+
/**
|
|
93
|
+
* Get all cached tool identifiers
|
|
94
|
+
*/
|
|
95
|
+
getCachedTools(): Array<{
|
|
96
|
+
server: string;
|
|
97
|
+
toolName: string;
|
|
98
|
+
}>;
|
|
99
|
+
/**
|
|
100
|
+
* Reset statistics counters
|
|
101
|
+
*/
|
|
102
|
+
resetStats(): void;
|
|
103
|
+
/**
|
|
104
|
+
* Log current cache statistics (for monitoring and observability)
|
|
105
|
+
* @param forceLog - Force logging even if debug mode is off
|
|
106
|
+
*/
|
|
107
|
+
logStats(forceLog?: boolean): void;
|
|
108
|
+
/**
|
|
109
|
+
* Preload tool schemas in batch
|
|
110
|
+
* @returns Object with loaded count and array of failures
|
|
111
|
+
*/
|
|
112
|
+
preload(tools: Array<{
|
|
113
|
+
server: string;
|
|
114
|
+
toolName: string;
|
|
115
|
+
}>, loader: (server: string, toolName: string) => Promise<Tool>): Promise<{
|
|
116
|
+
loaded: number;
|
|
117
|
+
failed: Array<{
|
|
118
|
+
server: string;
|
|
119
|
+
toolName: string;
|
|
120
|
+
error: string;
|
|
121
|
+
}>;
|
|
122
|
+
}>;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=schemaCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaCache.d.ts","sourceRoot":"","sources":["../../../src/core/capabilities/schemaCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAI1D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,OAAO,IAAI,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAUD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAsC;IACnD,OAAO,CAAC,gBAAgB,CAAyC;IACjE,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,KAAK,CASX;gBAEU,MAAM,EAAE,iBAAiB;IAIrC;;OAEG;IACH,OAAO,CAAC,WAAW;IAInB;;OAEG;IACH,OAAO,CAAC,SAAS;IASjB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAkBnB;;;;;;;;OAQG;IACU,SAAS,CACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC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