@@ -174,18 +174,14 @@ async def register_manual(self, caller, manual_call_template: CallTemplate) -> R
174
174
)
175
175
176
176
try :
177
- # For discovery, use the first command only
178
- first_command = manual_call_template .commands [0 ]
179
-
177
+ # Execute commands using the same approach as call_tool but with no arguments
180
178
env = self ._prepare_environment (manual_call_template )
181
- # Parse command string into proper arguments
182
- # Use posix=False on Windows, posix=True on Unix-like systems
183
- command = shlex .split (first_command .command , posix = (os .name != 'nt' ))
184
-
185
- self ._log_info (f"Executing command for tool discovery: { ' ' .join (command )} " )
179
+ shell_script = self ._build_combined_shell_script (manual_call_template .commands , {})
180
+
181
+ self ._log_info (f"Executing shell script for tool discovery from provider '{ manual_call_template .name } '" )
186
182
187
- stdout , stderr , return_code = await self ._execute_command (
188
- command ,
183
+ stdout , stderr , return_code = await self ._execute_shell_script (
184
+ shell_script ,
189
185
env ,
190
186
timeout = 30.0 ,
191
187
working_dir = manual_call_template .working_dir ,
@@ -196,14 +192,14 @@ async def register_manual(self, caller, manual_call_template: CallTemplate) -> R
196
192
197
193
if not output .strip ():
198
194
self ._log_info (
199
- f"No output from command '{ manual_call_template .command_name } '"
195
+ f"No output from commands for CLI provider '{ manual_call_template .name } '"
200
196
)
201
197
return RegisterManualResult (
202
198
success = False ,
203
199
manual_call_template = manual_call_template ,
204
200
manual = UtcpManual (manual_version = "0.0.0" , tools = []),
205
201
errors = [
206
- f"No output from discovery command for CLI provider '{ manual_call_template .name } '"
202
+ f"No output from discovery commands for CLI provider '{ manual_call_template .name } '"
207
203
],
208
204
)
209
205
@@ -415,8 +411,14 @@ def _parse_combined_output(self, stdout: str, stderr: str, return_code: int, com
415
411
Returns:
416
412
Final output from script (already filtered by append_to_final_output)
417
413
"""
418
- # Use stdout if successful, stderr if failed
419
- output = stdout if return_code == 0 else stderr
414
+ # Platform-specific output handling
415
+ if os .name == 'nt' :
416
+ # Windows (PowerShell): Use stdout on success, stderr on failure
417
+ output = stdout if return_code == 0 else stderr
418
+ else :
419
+ # Unix (Bash): Our script captures everything and echoes to stdout
420
+ # So we always use stdout first, fallback to stderr if stdout is empty
421
+ output = stdout if stdout .strip () else stderr
420
422
421
423
if not output .strip ():
422
424
self ._log_info (f"CLI tool '{ tool_name } ' produced no output" )
0 commit comments