|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > !Server-Operations - Commands for interacting with a running MCP server (signals, actions) > MCP. - MCP Server Operations |
SPR Script Language
HTP.ReturnResult
Returns a value from a parallel script to its parent and terminates.
Intention
This command is designed to be used exclusively inside a child script that was launched by HTP.RunScript. Its purpose is twofold: first, it sends a single string value back to the parent script that is waiting with HTP.WaitForResult. Second, it immediately terminates the child script, similar to the ENR. command.
This command is the final step in a parallel task, allowing the child process to deliver its result and cleanly exit.
Illustration
📦 Mission Complete: The worker (child script) uses HTP.ReturnResult to hand the finished report (the result value) back to the manager (parent script) and then goes home (terminates).
Syntax
HTP.ReturnResult|$$VAL
Parameter Explanation
P1 - $$VAL - (Variable, Required)
The variable containing the string value that will be sent back to the parent script's result variable (the $$RES parameter in HTP.WaitForResult).
Examples
'***********************************
' HTP.ReturnResult - Sample 1: Complete Parent/Child Interaction
'***********************************
' -- This code would be in the PARENT script --
' Define the child script. It gets the current time and returns it.
VAR.$$cod=VAR.$$tim=$time$$crlf$HTP.ReturnResult|$$tim
' Launch the child script
HTP.RunScript|$$cod|$$pid
' Prepare a variable to receive the result
VAR.$$res=
' Wait for the child to finish and return its value
HTP.WaitForResult|$$res|$$pid
' Display the result received from the child
MBX.The child script returned the time: $$res
ENR.
'
'
'SPR Script-file: MCP_Server tsted with Roo-Code
'Purpose:
'Author: MINIPC\theog
'Creation date: 07-24-2025 at 10:24:18
'===========================================================
'#EXE:?path\
'#SPI:ForceWrite
HTP.SetLogLevel|3
VAR.$$CFG=?path\mcp_config.json
VAR.$$POR=5555
VAR.$$ADD=127.0.0.1
PRT.Generating 100-line test script...
VAR.$$AIS=
FOR.$$IXX|1|4
VAR.$$AIS+PRT.This is line $$IXX->Line $$IXX$crlf$
NEX.
VAR.$$AIS+DMP.Speed$crlf$
VAR.$$AIS+MBX.!$crlf$
VAR.$$AIS+ENR.$crlf$
' --- Step 1: Initialize the Server ---
' This loads the config file (or creates it) and sets the port, etc.
MCP.Init|$$CFG
' --- Step 2: Start the Server in LISTENER mode ---
VAR.$$MSG=Server Start (Listener Mode)
' Start in Listener Mode (1)
MCP.Start|$$RES
DBP.Server started as TID: $$RES
JIZ.$$RES|Fail
MCP.IsRunning|$$RES
JIZ.$$RES|Fail
HTP.MCPShowWindow|1
' --- Step 3: Poll the Listener Queue ---
:Loop
PAU.500|ms
MCP.IsRunning|$$RES
JIZ.$$RES|Fail
HTP.MCP Simulate|RUNSCR|$$AIS
' Check the queue count
HTP.MCPGetQueueCount|$$RES
JIZ.$$RES|Loop
' Get the next command and its type from the queue
HTP.MCPGetNextCommand|$$RET|$$CMD
VAV.$$CMD=$$CMD
VAV.$$RET=$$RET
JNS.$$CMD|Loop
PRT.---------------------------------------
PRT.Dequeued Command: $$CMD
PRT.Ret=$$RET
PRT.CMD=$$CMD
PRT.---------------------------------------
' --- Use SCS to check the command type and prepare the script code ---
SCS.$$CMD
CAS.RUNSCR
' The payload in $$RET is the script code. Copy it to the execution variable.
VAR.$$SRC=$$RET
GTO.Execute
CAS.RUNPTH
' The payload in $$RET is a file path. Read the file's content into the execution variable.
CFF.$$RET|$$SRC
GTO.Execute
CAE.
' This is the default case for any unknown command types.
PRT.Unknown command in queue: $$CMD
GTO.Loop
ESC.
' This part should not be reached, but it acts as a safeguard.
GTO.Loop
:Execute
' --- Launch the script from the common variable and get its PID ---
HTP.RunScript|$$SRC|$$PID|0
JIZ.$$PID|ExecError
PRT.Launched script with PID: $$PID
' --- Wait for the script to finish, with a 5-minute timeout ---
HTP.WaitScript|$$PID|300000|$$STA
IVV.$$STA=1
PRT.Error: Script with PID $$PID timed out and was terminated.
ELS.
PRT.Script with PID $$PID finished successfully.
' (Future logic to retrieve the script's result file would go here)
EIF.
GTO.Loop
:ExecError
PRT.Error: Failed to launch script.
GTO.Loop
'===========================================================
:Fail
DBP.Server is not running.
ENR.
Remarks
- This command must be the last command you want to execute in a child script, as it will immediately terminate the script.
- Internally, it is a combination of the PRV. (Parallel Return Value) and ENR. (End Robot) commands.
See also: