MCP. - MCP Server Operations

<< 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

HTP.MCPGetQueueCount

Previous Top Next


SPR Script Language

 

HTP.MCPGetQueueCount

Returns the number of commands currently waiting in the Listener server's queue.

 

Intention

 

When the MCP server is running in Listener Mode, it doesn't execute commands; it simply collects them in a queue. The HTP.MCPGetQueueCount command is your way of asking the server, "How many commands are waiting for me to process?"

 

This is essential for creating a polling loop where your main script can check for work, process all available commands using HTP.MCPGetNextCommand, and then continue with other tasks.

 

Illustration

📬 Check Mailbox: Use HTP.MCPGetQueueCount|$$num to see if you have new mail.
📥 Process: If $$num is greater than 0, use HTP.MCPGetNextCommand to read it.

 

Syntax

 

HTP.MCPGetQueueCount[|$$ret]

 

Parameter Explanation

 

P1 - $$ret - (Variable, Optional)

A variable to store the numeric count of commands in the queue (e.g., $$ret receives a value of 0 or greater). If omitted, the count is pushed to the top of the stack (TOS).

 

Examples

 

'***********************************

' HTP.MCPGetQueueCount - Sample 1: Basic Check

'***********************************

' Start server in listener mode (1)

MCP.Start||1|$$thr

PAU.100|ms

HTP.MCPGetQueueCount|$$count

MBX.Commands currently in queue: $$count

MCP.Stop

'

'***********************************

' HTP.MCPGetQueueCount - Sample 2: Polling Loop

'***********************************

:Loop_Start

 HTP.MCPGetQueueCount|$$count

 JIZ.$$count|No_Commands

PRT.Found $$count commands to process...

HTP.MCPGetNextCommand|$$cmd

PRT.Processing command: $$cmd

GTO.Loop_Start ' Check for more

:No_Commands

PRT.Queue is empty. Waiting...

PAU.1000|ms

GTO.Loop_Start

'

 

Remarks

 

- This command is only meaningful when the server is running in Listener Mode (started with mode=1).

- The underlying call to the library is thread-safe.

- It will return 0 if the queue is empty, or if the server is not running.

 

See also:

 

MCP.Start

HTP.MCPGetNextCommand

MCP.ConfigQue

HTP.MCPResetQue