@@ -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,62 @@ 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+ if ( tool instanceof DiscoveredMCPTool ) {
166+ // Subagents MUST use fully qualified names for MCP tools to ensure
167+ // unambiguous tool calls and to comply with policy requirements.
168+ // We automatically "upgrade" any MCP tool to its qualified version.
169+ agentToolRegistry . registerTool ( tool . asFullyQualifiedTool ( ) ) ;
170+ } else {
171+ agentToolRegistry . registerTool ( tool ) ;
172+ }
173+ } ;
174+
175+ const registerToolByName = ( toolName : string ) => {
176+ // Handle global wildcard
177+ if ( toolName === '*' ) {
178+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
179+ registerToolInstance ( tool ) ;
180+ }
181+ return ;
182+ }
183+
184+ // Handle MCP wildcards
185+ if ( isMcpToolName ( toolName ) ) {
186+ if ( toolName === `${ MCP_TOOL_PREFIX } *` ) {
187+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
188+ if ( tool instanceof DiscoveredMCPTool ) {
189+ registerToolInstance ( tool ) ;
190+ }
191+ }
192+ return ;
193+ }
194+
195+ const parsed = parseMcpToolName ( toolName ) ;
196+ if ( parsed . serverName && parsed . toolName === '*' ) {
197+ for ( const tool of parentToolRegistry . getToolsByServer (
198+ parsed . serverName ,
199+ ) ) {
200+ registerToolInstance ( tool ) ;
201+ }
202+ return ;
203+ }
204+ }
205+
159206 // If the tool is referenced by name, retrieve it from the parent
160207 // registry and register it with the agent's isolated registry.
161208 const tool = parentToolRegistry . getTool ( toolName ) ;
162209 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- }
210+ registerToolInstance ( tool ) ;
171211 }
172212 } ;
173213
@@ -1174,10 +1214,9 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
11741214 const { toolConfig, outputConfig } = this . definition ;
11751215
11761216 if ( toolConfig ) {
1177- const toolNamesToLoad : string [ ] = [ ] ;
11781217 for ( const toolRef of toolConfig . tools ) {
11791218 if ( typeof toolRef === 'string' ) {
1180- toolNamesToLoad . push ( toolRef ) ;
1219+ // The names were already expanded and loaded into the registry during creation.
11811220 } else if ( typeof toolRef === 'object' && 'schema' in toolRef ) {
11821221 // Tool instance with an explicit schema property.
11831222 toolsList . push ( toolRef . schema ) ;
@@ -1186,10 +1225,8 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
11861225 toolsList . push ( toolRef ) ;
11871226 }
11881227 }
1189- // Add schemas from tools that were registered by name.
1190- toolsList . push (
1191- ...this . toolRegistry . getFunctionDeclarationsFiltered ( toolNamesToLoad ) ,
1192- ) ;
1228+ // Add schemas from tools that were explicitly registered by name or wildcard.
1229+ toolsList . push ( ...this . toolRegistry . getFunctionDeclarations ( ) ) ;
11931230 }
11941231
11951232 // Always inject complete_task.
0 commit comments