|
<< 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) > !Listener-Queue - Commands for managing the Listener Mode queue > MCP. - MCP Server Operations |
SPR Script Language
HTP.MCPGetNextCommand
Retrieves the next command string from the MCP server's queue when in Listener mode.
Intention
When the MCP server is running in Listener Mode, it does not execute commands. Instead, it places them in an internal queue. The HTP.MCPGetNextCommand command is the primary way for your main application script to retrieve these commands one by one for processing.
This command is typically used in a polling loop where the script repeatedly checks for and processes new commands. It returns an empty string if the queue is empty. The order in which commands are returned (FIFO or LIFO) can be configured with MCP.ConfigQue.
Syntax
HTP.MCPGetNextCommand[|$$ret]
Parameter Explanation
P1 - $$ret - (Variable, Optional)
A variable to store the retrieved command string. If the queue is empty, the variable will contain an empty string. If omitted, the result is pushed to the stack.
Examples
'***********************************
' HTP.MCPGetNextCommand - Sample: Polling Loop
'***********************************
' Start the server in Listener mode (1)
MCP.Start||1|$$thr
JIZ.$$thr|Fail
PRT.Server is listening. Polling for commands for 10 seconds...
TIM.SET|10
:Loop
HTP.MCPGetNextCommand|$$cmd
JIN.$$cmd|NoCmd
PRT.Command received: $$cmd
:NoCmd
PAU.250|ms
JIT|Loop
PRT.Polling finished.
MCP.Stop
Remarks
- This command is only useful when the server is running in Listener Mode. If called while in Executor Mode, the queue will always be empty.
- The operation is thread-safe and removes the command from the queue, so each command is only ever retrieved once.
- The command string returned is raw UTF-8. If it is JSON, you may need to parse it using `PSJ.Parse`.
See also: