MCP Commands - Task Management

<< 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

RunCodeAsync - Execute Code Asynchronously

Previous TopNext


MiniRobot Language (MRL) - MCP Task Management Commands

 

MCP.RunCodeAsync

Execute Code in Background

 

Purpose

 

The MCP.RunCodeAsync command executes code asynchronously in a background job, allowing the robot to continue with other tasks without waiting for the code execution to complete. This is useful for long-running operations that should not block the main execution flow.

 

This command is particularly useful when:

• Executing long-running computations that would block the main thread

• Running multiple operations in parallel

• Performing background processing while the robot continues other tasks

• Implementing fire-and-forget operations

 

Syntax

 

MCP.RunCodeAsync|$$COD|$$LAN|$$JOB

 

Parameters

 

$$CODE - The code to execute. This can be any supported programming language code as a string.

 

$$LANGUAGE - The programming language of the code (e.g., python, javascript, powershell).

 

$$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: Execute Python code asynchronously

MCP.RunCodeAsync|print('Hello from async')|python|$$JobId

PRT.Started job: $$JobId

 

' Example 2: Long computation in background

' Start the background job

MCP.RunCodeAsync|import time; time.sleep(10); print('Done')|python|$$CalcJob

' Continue with other work while job runs

PRT.Doing other work...

' Later, check if job is complete

MCP.CheckJobResult|$$CalcJob|$$Status|$$Result

 

' Example 3: PowerShell script execution

MCP.RunCodeAsync|Get-Process | Select-Object -First 5|powershell|$$PsJob

PRT.PowerShell job started: $$PsJob

 

Remarks

 

The RunCodeAsync command starts a background thread to execute the provided code. The job ID returned can be used to track the job status and retrieve results later. Jobs remain in memory until explicitly cleaned up using MCP.CleanupJobs.

 

Supported languages depend on the MCP server configuration. Common options include python, javascript, and powershell. Check your MCP server documentation for the complete list of supported languages.

 

If the code execution fails, the error information will be stored with the job result and can be retrieved using MCP.GetJobResult.

 

Error Conditions

 

The command will fail with a parameter error if:

• The code parameter is missing or empty

• The language parameter is missing or unsupported

• The return variable parameter is missing

 

See also:

 

MCP.RunCodeSync - Execute Code Synchronously

MCP.CheckJobResult - Check Job Result

MCP.WaitForJobResult - Wait for Job Result

MCP.GetJobResult - Get Job Result

MCP.CleanupJobs - Clean Up Jobs