@@ -16,7 +16,13 @@ import type {
1616 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 { ChatCompressionService } from '../services/chatCompressionService.js' ;
@@ -125,28 +131,55 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
125131 runtimeContext . getAgentRegistry ( ) . getAllAgentNames ( ) ,
126132 ) ;
127133
128- const registerToolByName = ( toolName : string ) => {
134+ const registerToolInstance = ( tool : AnyDeclarativeTool ) => {
129135 // Check if the tool is a subagent to prevent recursion.
130136 // We do not allow agents to call other agents.
131- if ( allAgentNames . has ( toolName ) ) {
137+ if ( allAgentNames . has ( tool . name ) ) {
132138 debugLogger . warn (
133- `[LocalAgentExecutor] Skipping subagent tool '${ toolName } ' for agent '${ definition . name } ' to prevent recursion.` ,
139+ `[LocalAgentExecutor] Skipping subagent tool '${ tool . name } ' for agent '${ definition . name } ' to prevent recursion.` ,
134140 ) ;
135141 return ;
136142 }
137143
144+ agentToolRegistry . registerTool ( tool ) ;
145+ } ;
146+
147+ const registerToolByName = ( toolName : string ) => {
148+ // Handle global wildcard
149+ if ( toolName === '*' ) {
150+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
151+ registerToolInstance ( tool ) ;
152+ }
153+ return ;
154+ }
155+
156+ // Handle MCP wildcards
157+ if ( isMcpToolName ( toolName ) ) {
158+ if ( toolName === `${ MCP_TOOL_PREFIX } *` ) {
159+ for ( const tool of parentToolRegistry . getAllTools ( ) ) {
160+ if ( tool instanceof DiscoveredMCPTool ) {
161+ registerToolInstance ( tool ) ;
162+ }
163+ }
164+ return ;
165+ }
166+
167+ const parsed = parseMcpToolName ( toolName ) ;
168+ if ( parsed . serverName && parsed . toolName === '*' ) {
169+ for ( const tool of parentToolRegistry . getToolsByServer (
170+ parsed . serverName ,
171+ ) ) {
172+ registerToolInstance ( tool ) ;
173+ }
174+ return ;
175+ }
176+ }
177+
138178 // If the tool is referenced by name, retrieve it from the parent
139179 // registry and register it with the agent's isolated registry.
140180 const tool = parentToolRegistry . getTool ( toolName ) ;
141181 if ( tool ) {
142- if ( tool instanceof DiscoveredMCPTool ) {
143- // Subagents MUST use fully qualified names for MCP tools to ensure
144- // unambiguous tool calls and to comply with policy requirements.
145- // We automatically "upgrade" any MCP tool to its qualified version.
146- agentToolRegistry . registerTool ( tool . asFullyQualifiedTool ( ) ) ;
147- } else {
148- agentToolRegistry . registerTool ( tool ) ;
149- }
182+ registerToolInstance ( tool ) ;
150183 }
151184 } ;
152185
@@ -1147,10 +1180,9 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
11471180 const { toolConfig, outputConfig } = this . definition ;
11481181
11491182 if ( toolConfig ) {
1150- const toolNamesToLoad : string [ ] = [ ] ;
11511183 for ( const toolRef of toolConfig . tools ) {
11521184 if ( typeof toolRef === 'string' ) {
1153- toolNamesToLoad . push ( toolRef ) ;
1185+ // The names were already expanded and loaded into the registry during creation.
11541186 } else if ( typeof toolRef === 'object' && 'schema' in toolRef ) {
11551187 // Tool instance with an explicit schema property.
11561188 toolsList . push ( toolRef . schema ) ;
@@ -1159,10 +1191,8 @@ export class LocalAgentExecutor<TOutput extends z.ZodTypeAny> {
11591191 toolsList . push ( toolRef ) ;
11601192 }
11611193 }
1162- // Add schemas from tools that were registered by name.
1163- toolsList . push (
1164- ...this . toolRegistry . getFunctionDeclarationsFiltered ( toolNamesToLoad ) ,
1165- ) ;
1194+ // Add schemas from tools that were explicitly registered by name or wildcard.
1195+ toolsList . push ( ...this . toolRegistry . getFunctionDeclarations ( ) ) ;
11661196 }
11671197
11681198 // Always inject complete_task.
0 commit comments