|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > !Server-Lifecycle - Commands for managing the MCP server lifecycle (init, start, stop) > MCP. - MCP Server Operations |
SPR Script Language
MCP.End
Sends an "END" signal to gracefully terminate the MCP server.
Intention
The MCP.End command provides a clean way to shut down a running MCP server. When executed, it sends a specific "END" signal to the server's internal signal queue. The server's main thread will detect this signal, perform its cleanup operations (like closing sockets and destroying the log window), and then terminate gracefully. This is the recommended method for stopping the server, often used by a separate shutdown script.
Illustration
[Client Script] [MCP Server]
| Signal Queue |
MCP.End ---> "END" Signal ---> (Process Signals Loop)
|
v
(Server Shutdown)
Syntax
MCP.End
Parameter Explanation
(No parameters)
Return Value (on Stack)
The command pushes the index of the signal in the queue (numeric) onto the stack. Returns -1 if the signal queue is full.
Examples
'***********************************
' MCP.End - Sample 1: Send Shutdown Signal
'***********************************
PRT.Sending shutdown signal...
MCP.End
POP.$$SIGNAL_INDEX ' Get signal queue index (or -1 if queue full)
JIL.$$SIGNAL_INDEX!-1|Error_Handler ' Check if signal was successfully queued
PRT.Shutdown signal sent.
PAU.1000|ms ' Give server time to shut down
MCP.IsRunning|$$IS_RUNNING
JNZ.$$IS_RUNNING|Error_Handler ' Server should no longer be running
'
'***********************************
' MCP.End - Sample 2: Terminate After Other Signals
'***********************************
MCP.Init
MCP.Start||$$thr
HTP.MCPSignal|STATUS||$$sig
PRT.Status signal queued at $$sig
MCP.End
POP.$$END_SIGNAL_INDEX
PRT.END signal queued at $$END_SIGNAL_INDEX
PAU.500|ms
MCP.IsRunning|$$IS_RUNNING_AFTER_END
JNZ.$$IS_RUNNING_AFTER_END|Error_Handler
Remarks
- This command sends a signal to the running MCP server thread. The actual shutdown occurs asynchronously when the server processes the signal.
- The return value (index) indicates if the signal was successfully queued; it does not confirm server shutdown.
- To ensure the server has fully stopped, use MCP.IsRunning after a short pause.
- Does not clean up all resources; for complete cleanup, including freeing JSON handles and critical sections, consider MCP.Stop.
Limitations
- Requires the server to be initialized (via MCP.Init) and running (via MCP.Start).
- Asynchronous; shutdown may not be immediate, depending on queue processing.
See also:
• MCP.Init
• MCP.Perm
• MCP.Stop