|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > Task Management - Execute code and scripts > MCP Commands - Task Management |
MiniRobot Language (MRL) - MCP Task Management Commands
MCP.RunScriptAsync
Execute Script File in Background
Purpose
The MCP.RunScriptAsync command executes a script file asynchronously in a background job. Unlike RunCodeAsync which executes code strings, this command runs an actual script file from disk, making it ideal for complex, multi-line scripts stored as files.
This command is particularly useful when:
• Running existing script files without loading them into memory
• Executing complex scripts that are too large for inline code
• Running scripts in the background while continuing robot execution
• Executing scripts that need to persist between robot runs
Syntax
MCP.RunScriptAsync|$$FILEPATH|$$JOB_ID_VAR
Parameters
$$FILEPATH - The full path to the script file to execute. The file extension determines the interpreter (e.g., .py for Python, .ps1 for PowerShell, .js for JavaScript).
$$JOB_ID_VAR - The variable that will receive the unique job ID for tracking the asynchronous task.
Return Value
The command returns a unique job ID string that can be used to check the status and retrieve the result of the background job using MCP.CheckJobResult, MCP.WaitForJobResult, or MCP.GetJobResult.
Examples
' Example 1: Run a Python script file
MCP.RunScriptAsync|C:\Scripts\process_data.py|$$JobId
PRT.Started processing job: $$JobId
' Example 2: Run PowerShell script and wait for completion
MCP.RunScriptAsync|C:\Scripts\backup.ps1|$$BackupJob
PRT.Backup started...
' Continue with other tasks
PRT.Doing other work while backup runs...
' Wait for backup to complete
MCP.WaitForJobResult|$$BackupJob|$$Result
' Example 3: JavaScript file execution
MCP.RunScriptAsync|C:\Scripts\generate_report.js|$$ReportJob
PRT.Report generation started: $$ReportJob
Remarks
The script file must exist and be accessible at the specified path. The file extension is used to determine the appropriate interpreter. Common extensions and their interpreters:
• .py - Python
• .ps1 - PowerShell
• .js - JavaScript (Node.js)
• .bat - Windows Batch
• .cmd - Windows Command
The script runs with the same permissions as the MCP server process. Ensure scripts are from trusted sources and have appropriate execution permissions.
Error Conditions
The command will fail with an error if:
• The file path is missing or empty
• The file does not exist at the specified path
• The file extension is not supported
• The return variable parameter is missing
• The script file is not readable
See also:
• MCP.RunScriptSync - Execute Script Synchronously
• MCP.RunCodeAsync - Execute Code Asynchronously
• MCP.CheckJobResult - Check Job Result