@@ -17,7 +17,13 @@ import {
1717 type Schema ,
1818} from '@google/genai' ;
1919import { ToolRegistry } from '../tools/tool-registry.js' ;
20- import { DiscoveredMCPTool } from '../tools/mcp-tool.js' ;
20+ import { type AnyDeclarativeTool } from '../tools/tools.js' ;
21+ import {
22+ DiscoveredMCPTool ,
23+ isMcpToolName ,
24+ parseMcpToolName ,
25+ MCP_TOOL_PREFIX ,
26+ } from '../tools/mcp-tool.js' ;
2127import { CompressionStatus } from '../core/turn.js' ;
2228import { type ToolCallRequestInfo } from '../scheduler/types.js' ;
2329import { type Message } from '../confirmation-bus/types.js' ;
@@ -146,28 +152,55 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
146152 context . config . getAgentRegistry ( ) . getAllAgentNames ( ) ,
147153 ) ;
148154
149- const registerToolByName = ( toolName : string ) => {
155+ const registerToolInstance = ( tool : AnyDeclarativeTool ) => {
150156 // Check if the tool is a subagent to prevent recursion.
151157 // We do not allow agents to call other agents.
152- if ( allAgentNames . has ( toolName ) ) {
158+ if ( allAgentNames . has ( tool . name ) ) {
153159 debugLogger . warn (
154- `[LocalAgentExecutor] Skipping subagent tool '${ toolName } ' for agent '${ definition . name } ' to prevent recursion.` ,
160+ `[LocalAgentExecutor] Skipping subagent tool '${ tool . name } ' for agent '${ definition . name } ' to prevent recursion.` ,
155161 ) ;
156162 return ;
157163 }
158164
165+ agentToolRegistry . registerTool ( tool ) ;
166+ } ;
167+
168+ const registerToolByName = ( toolName : string ) => {
169+ // Handle global wildcard
170+ if ( toolName === '*' ) {
171+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
172+ registerToolInstance ( tool ) ;
173+ }
174+ return ;
175+ }
176+
177+ // Handle MCP wildcards
178+ if ( isMcpToolName ( toolName ) ) {
179+ if ( toolName === `${ MCP_TOOL_PREFIX } *` ) {
180+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
181+ if ( tool instanceof DiscoveredMCPTool ) {
182+ registerToolInstance ( tool ) ;
183+ }
184+ }
185+ return ;
186+ }
187+
188+ const parsed = parseMcpToolName ( toolName ) ;
189+ if ( parsed . serverName && parsed . toolName === '*' ) {
190+ for ( const tool of parentToolRegistry . getToolsByServer (
191+ parsed . serverName ,
192+ ) ) {
193+ registerToolInstance ( tool ) ;
194+ }
195+ return ;
196+ }
197+ }
198+
159199 // If the tool is referenced by name, retrieve it from the parent
160200 // registry and register it with the agent's isolated registry.
161201 const tool = parentToolRegistry . getTool ( toolName ) ;
162202 if ( tool ) {
163- if ( tool instanceof DiscoveredMCPTool ) {
164- // Subagents MUST use fully qualified names for MCP tools to ensure
165- // unambiguous tool calls and to comply with policy requirements.
166- // We automatically "upgrade" any MCP tool to its qualified version.
167- agentToolRegistry . registerTool ( tool . asFullyQualifiedTool ( ) ) ;
168- } else {
169- agentToolRegistry . registerTool ( tool ) ;
170- }
203+ registerToolInstance ( tool ) ;
171204 }
172205 } ;
173206
@@ -1175,10 +1208,9 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
11751208 const { toolConfig, outputConfig } = this . definition ;
11761209
11771210 if ( toolConfig ) {
1178- const toolNamesToLoad : string [ ] = [ ] ;
11791211 for ( const toolRef of toolConfig . tools ) {
11801212 if ( typeof toolRef === 'string' ) {
1181- toolNamesToLoad . push ( toolRef ) ;
1213+ // The names were already expanded and loaded into the registry during creation.
11821214 } else if ( typeof toolRef === 'object' && 'schema' in toolRef ) {
11831215 // Tool instance with an explicit schema property.
11841216 toolsList . push ( toolRef . schema ) ;
@@ -1187,10 +1219,8 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
11871219 toolsList . push ( toolRef ) ;
11881220 }
11891221 }
1190- // Add schemas from tools that were registered by name.
1191- toolsList . push (
1192- ...this . toolRegistry . getFunctionDeclarationsFiltered ( toolNamesToLoad ) ,
1193- ) ;
1222+ // Add schemas from tools that were explicitly registered by name or wildcard.
1223+ toolsList . push ( ...this . toolRegistry . getFunctionDeclarations ( ) ) ;
11941224 }
11951225
11961226 // Always inject complete_task.
0 commit comments