@@ -16,7 +16,13 @@ import {
1616 type Schema ,
1717} from '@google/genai' ;
1818import { ToolRegistry } from '../tools/tool-registry.js' ;
19- import { DiscoveredMCPTool } from '../tools/mcp-tool.js' ;
19+ import { type AnyDeclarativeTool } from '../tools/tools.js' ;
20+ import {
21+ DiscoveredMCPTool ,
22+ isMcpToolName ,
23+ parseMcpToolName ,
24+ MCP_TOOL_PREFIX ,
25+ } from '../tools/mcp-tool.js' ;
2026import { CompressionStatus } from '../core/turn.js' ;
2127import { type ToolCallRequestInfo } from '../scheduler/types.js' ;
2228import { type Message } from '../confirmation-bus/types.js' ;
@@ -141,28 +147,55 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
141147 runtimeContext . getAgentRegistry ( ) . getAllAgentNames ( ) ,
142148 ) ;
143149
144- const registerToolByName = ( toolName : string ) => {
150+ const registerToolInstance = ( tool : AnyDeclarativeTool ) => {
145151 // Check if the tool is a subagent to prevent recursion.
146152 // We do not allow agents to call other agents.
147- if ( allAgentNames . has ( toolName ) ) {
153+ if ( allAgentNames . has ( tool . name ) ) {
148154 debugLogger . warn (
149- `[LocalAgentExecutor] Skipping subagent tool '${ toolName } ' for agent '${ definition . name } ' to prevent recursion.` ,
155+ `[LocalAgentExecutor] Skipping subagent tool '${ tool . name } ' for agent '${ definition . name } ' to prevent recursion.` ,
150156 ) ;
151157 return ;
152158 }
153159
160+ agentToolRegistry . registerTool ( tool ) ;
161+ } ;
162+
163+ const registerToolByName = ( toolName : string ) => {
164+ // Handle global wildcard
165+ if ( toolName === '*' ) {
166+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
167+ registerToolInstance ( tool ) ;
168+ }
169+ return ;
170+ }
171+
172+ // Handle MCP wildcards
173+ if ( isMcpToolName ( toolName ) ) {
174+ if ( toolName === `${ MCP_TOOL_PREFIX } *` ) {
175+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
176+ if ( tool instanceof DiscoveredMCPTool ) {
177+ registerToolInstance ( tool ) ;
178+ }
179+ }
180+ return ;
181+ }
182+
183+ const parsed = parseMcpToolName ( toolName ) ;
184+ if ( parsed . serverName && parsed . toolName === '*' ) {
185+ for ( const tool of parentToolRegistry . getToolsByServer (
186+ parsed . serverName ,
187+ ) ) {
188+ registerToolInstance ( tool ) ;
189+ }
190+ return ;
191+ }
192+ }
193+
154194 // If the tool is referenced by name, retrieve it from the parent
155195 // registry and register it with the agent's isolated registry.
156196 const tool = parentToolRegistry . getTool ( toolName ) ;
157197 if ( tool ) {
158- if ( tool instanceof DiscoveredMCPTool ) {
159- // Subagents MUST use fully qualified names for MCP tools to ensure
160- // unambiguous tool calls and to comply with policy requirements.
161- // We automatically "upgrade" any MCP tool to its qualified version.
162- agentToolRegistry . registerTool ( tool . asFullyQualifiedTool ( ) ) ;
163- } else {
164- agentToolRegistry . registerTool ( tool ) ;
165- }
198+ registerToolInstance ( tool ) ;
166199 }
167200 } ;
168201
@@ -1171,22 +1204,14 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
11711204 const { toolConfig, outputConfig } = this . definition ;
11721205
11731206 if ( toolConfig ) {
1174- const toolNamesToLoad : string [ ] = [ ] ;
11751207 for ( const toolRef of toolConfig . tools ) {
1176- if ( typeof toolRef === 'string' ) {
1177- toolNamesToLoad . push ( toolRef ) ;
1178- } else if ( typeof toolRef === 'object' && 'schema' in toolRef ) {
1179- // Tool instance with an explicit schema property.
1180- toolsList . push ( toolRef . schema ) ;
1181- } else {
1208+ if ( typeof toolRef === 'object' && ! ( 'schema' in toolRef ) ) {
11821209 // Raw `FunctionDeclaration` object.
11831210 toolsList . push ( toolRef ) ;
11841211 }
11851212 }
1186- // Add schemas from tools that were registered by name.
1187- toolsList . push (
1188- ...this . toolRegistry . getFunctionDeclarationsFiltered ( toolNamesToLoad ) ,
1189- ) ;
1213+ // Add schemas from tools that were explicitly registered by name, wildcard, or instance.
1214+ toolsList . push ( ...this . toolRegistry . getFunctionDeclarations ( ) ) ;
11901215 }
11911216
11921217 // Always inject complete_task.
0 commit comments