|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > MCP. - MCP Server Operations |
SPR Script Language
!Server-Lifecycle
Commands for managing the MCP server lifecycle (init, start, stop).
Intention
The commands in this section are responsible for controlling the fundamental state of the MCP server. This includes the initial setup of the library, launching the server in its background thread, checking its running status, and performing a clean shutdown. These are typically the first and last MCP commands you will use in a script.
Commands
• MCP.End - Sends an "END" signal to gracefully request that the server thread terminates itself.
• MCP.Init - Initializes the MCP library and its resources, optionally with a config file.
• MCP.IsRunning - Checks if the server thread is currently active.
• MCP.Start - Starts the MCP server in a separate thread (either Executor or Listener mode).
• MCP.Stop - Shuts down the MCP server completely and cleans up all resources.
• MCP.StartSprServer - A specialized command to start the server in Listener mode for SSPR integration.
' Working Sample Sript
'SPR Script-file: MCP_Server
'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.
See also: