Skip to content

Commit a75e485

Browse files
author
Lasim
committed
feat(satellite): add wildcard search for MCP tools and limit results
1 parent c062e49 commit a75e485

File tree

2 files changed

+94
-9
lines changed

2 files changed

+94
-9
lines changed

services/satellite/src/core/mcp-server-wrapper.ts

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ export class McpServerWrapper {
9292
const metaTools = [
9393
{
9494
name: 'discover_mcp_tools',
95-
description: 'Search for MCP tools using 1-3 keywords only. Examples: "markdown", "github create", "database query". Avoid long descriptions. Use tool name or main function as keywords. Returns tool paths for execute_mcp_tool.',
95+
description: 'Search for MCP tools using 1-3 keywords only. Examples: "markdown", "github create", "database query". Use "*" to list all available tools (max 20). Avoid long descriptions. Use tool name or main function as keywords. Returns tool paths for execute_mcp_tool.',
9696
inputSchema: {
9797
type: 'object',
9898
properties: {
9999
query: {
100100
type: 'string',
101-
description: 'Short search query with 1-3 keywords (e.g., "markdown", "github", "database postgres"). Avoid full sentences.'
101+
description: 'Short search query with 1-3 keywords (e.g., "markdown", "github", "database postgres"). Use "*" to list all tools. Avoid full sentences.'
102102
},
103103
limit: {
104104
type: 'number',
105-
description: 'Maximum number of results to return (default: 10)',
105+
description: 'Maximum number of results to return (default: 10, max: 20 for wildcard)',
106106
default: 10
107107
}
108108
},
@@ -186,17 +186,39 @@ export class McpServerWrapper {
186186
throw new Error('Invalid query parameter - must be a non-empty string');
187187
}
188188

189+
// Handle wildcard query "*" - list all tools (max 20)
190+
const isWildcard = query.trim() === '*';
191+
const wildcardLimit = 20;
192+
189193
this.logger.info({
190194
operation: 'discover_mcp_tools',
191195
query: query,
192-
limit: limit
193-
}, `Discovering tools with query: "${query}"`);
196+
limit: isWildcard ? wildcardLimit : limit,
197+
is_wildcard: isWildcard
198+
}, `Discovering tools with query: "${query}"${isWildcard ? ' (wildcard mode)' : ''}`);
194199

195200
const startTime = Date.now();
196-
const results = this.toolSearchService.search(query, limit);
201+
202+
let results;
203+
let totalAvailable = 0;
204+
let truncationMessage: string | undefined;
205+
206+
if (isWildcard) {
207+
// Wildcard: return all tools up to max 20
208+
results = this.toolSearchService.listAll(wildcardLimit);
209+
totalAvailable = this.toolSearchService.getEnabledToolCount();
210+
211+
if (totalAvailable > wildcardLimit) {
212+
truncationMessage = `Showing ${wildcardLimit} of ${totalAvailable} available tools. Use specific keywords (e.g., "github", "database", "markdown") to find additional tools not shown here.`;
213+
}
214+
} else {
215+
// Normal search
216+
results = this.toolSearchService.search(query, limit);
217+
}
218+
197219
const searchTime = Date.now() - startTime;
198220

199-
const response = {
221+
const response: any = {
200222
tools: results.map(result => ({
201223
tool_path: result.tool_path,
202224
description: result.description,
@@ -209,12 +231,21 @@ export class McpServerWrapper {
209231
query: query
210232
};
211233

234+
// Add truncation notice for wildcard queries with more tools available
235+
if (truncationMessage) {
236+
response.notice = truncationMessage;
237+
response.total_available = totalAvailable;
238+
}
239+
212240
this.logger.info({
213241
operation: 'discover_mcp_tools_success',
214242
query: query,
215243
results_count: results.length,
216-
search_time_ms: searchTime
217-
}, `Discovery complete: found ${results.length} tools in ${searchTime}ms`);
244+
search_time_ms: searchTime,
245+
is_wildcard: isWildcard,
246+
total_available: totalAvailable,
247+
was_truncated: !!truncationMessage
248+
}, `Discovery complete: found ${results.length} tools in ${searchTime}ms${truncationMessage ? ` (truncated from ${totalAvailable})` : ''}`);
218249

219250
return {
220251
content: [

services/satellite/src/services/tool-search-service.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,60 @@ export class ToolSearchService {
178178
}));
179179
}
180180

181+
/**
182+
* List all available tools without search filtering
183+
* Used when query is "*" to return all tools
184+
* Filters out disabled tools
185+
*/
186+
listAll(limit: number = 20): ToolSearchResult[] {
187+
const startTime = Date.now();
188+
189+
// Get tools from single source of truth
190+
const allTools = this.toolDiscoveryManager.getAllTools();
191+
192+
if (allTools.length === 0) {
193+
this.logger.warn({
194+
operation: 'tool_list_all_no_tools'
195+
}, 'No tools available');
196+
return [];
197+
}
198+
199+
// Filter out disabled tools
200+
const enabledTools = this.filterDisabledTools(allTools);
201+
202+
// Convert to searchable format
203+
const searchableTools = this.flattenTools(enabledTools);
204+
205+
const listTime = Date.now() - startTime;
206+
207+
this.logger.info({
208+
operation: 'tool_list_all_executed',
209+
total_tools: allTools.length,
210+
enabled_tools: searchableTools.length,
211+
returned_tools: Math.min(searchableTools.length, limit),
212+
list_time_ms: listTime,
213+
limit: limit
214+
}, `List all completed: returning ${Math.min(searchableTools.length, limit)}/${searchableTools.length} tools in ${listTime}ms`);
215+
216+
// Return up to limit tools
217+
return searchableTools.slice(0, limit).map(tool => ({
218+
tool_path: `${tool.serverSlug}:${tool.toolName}`,
219+
description: tool.description,
220+
server_name: tool.serverSlug,
221+
transport: tool.transport,
222+
score: 0 // Perfect score for direct listing
223+
}));
224+
}
225+
226+
/**
227+
* Get total count of enabled tools (for wildcard truncation message)
228+
*/
229+
getEnabledToolCount(): number {
230+
const allTools = this.toolDiscoveryManager.getAllTools();
231+
const enabledTools = this.filterDisabledTools(allTools);
232+
return enabledTools.length;
233+
}
234+
181235
/**
182236
* Get statistics about search service
183237
*/

0 commit comments

Comments
 (0)