MCP Commands - Queue Management

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > Queue Management - Listener queue operations >

MCP Commands - Queue Management

MCP.GetNextCommand - Get Next Command from Queue

PreviousTopNext


MiniRobot Language (MRL) - MCP Queue Management Commands

 

MCP.GetNextCommand / MCP.GetCmd

Retrieve the Next Command from the Queue

 

Purpose

 

The MCP.GetNextCommand command retrieves and removes the next command from the MCP server's command queue. This is typically used when implementing custom command processors or when scripts need to manually manage command execution from the queue.

 

This command is used when:

• Implementing custom command processing logic

• Building command dispatchers or routers

• Inspecting commands before execution

• Implementing custom filtering or validation

 

Syntax

 

MCP.GetNextCommand|$$COMMAND_VAR|$$ID_VAR|$$RETURN_VAR

 

MCP.GetCmd|$$COMMAND_VAR|$$ID_VAR|$$RETURN_VAR

 

Parameters

 

$$COMMAND_VAR - The variable that will receive the command string from the queue. Empty if no commands are pending.

 

$$ID_VAR - The variable that will receive the unique command ID for result correlation. Empty if no commands are pending.

 

$$RETURN_VAR - The variable that will receive the result code (0 for success, 1 if queue empty, 2 if error).

 

Return Value

 

0 - Command retrieved successfully

1 - Queue is empty (no commands pending)

2 - MCP server not running or error

 

Examples

 

' Example 1: Basic command retrieval

MCP.GetNextCommand|$$Command|$$CmdID|$$Status

IVV.$$Status!1

PRT.Command [$$CmdID]: $$Command

' Process the command...

ELS.

PRT.No commands in queue

EIF.

 

' Example 2: Command processing loop

LBL.ProcessLoop

MCP.GetCmd|$$NextCmd|$$NextID|$$Result

IVV.$$Result!0

JMP.ProcessLoopEnd

EIF.

PRT.Processing: $$NextCmd

' Execute and return result...

JMP.ProcessLoop

LBL.ProcessLoopEnd

 

' Example 3: Command filtering based on prefix

MCP.GetNextCommand|$$Cmd|$$ID|$$Ret

IVV.$$Ret!1

STX.HasPrefix|$$Cmd|MEM.|$$IsMemory

IVV.$$IsMemory!1

' Handle memory command

EIF.

EIF.

 

Remarks

 

The MCP.GetNextCommand command removes the command from the queue when retrieved. If you need to inspect the queue without removing commands, use MCP.GetQueueCount to check the queue size.

 

The command ID returned in $$ID_VAR is used to correlate results when using MCP.ReturnResult. Always preserve this ID if you intend to return a result for the command.

 

In SYNC mode, commands are retrieved in FIFO (first-in, first-out) order. In ASYNC mode, the retrieval order may vary based on internal scheduling.

 

MCP.GetNextCommand and MCP.GetCmd are aliases for the same command.

 

Error Conditions

 

The command will fail with a parameter error if:

• Any of the required parameters are missing

• Too many parameters are provided

 

See also:

 

MCP.ReturnResult - Return Result to Caller

MCP.GetQueueCount - Get Queue Count

Queue Management Overview