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

MCP. - MCP Server Operations

HTP.MCPSignal

Previous Top Next


SPR Script Language

 

HTP.MCPSignal

Send a signal to the MCP server with a type and optional data, returning the queue index.

 

Intention

 

The HTP.MCPSignal command allows you to send a generic signal to the MCP (Multi-Client Protocol) server running in an SPR script. You specify a signal type (e.g., "STATUS" or "CUSTOM") and optionally include data, and the command queues it for the server to process. It returns the index of the signal in the queue, which can be used to track its status. This is a key mechanism for communicating with the server after it’s initialized with MCP.Init and started with MCP.Start.

 

Imagine it as sending a message to your server crew—HTP.MCPSignal drops a note in their inbox (the signal queue), and you get a ticket number (queue index) to check on it later.

 

Illustration

📩 Signal: Use HTP.MCPSignal|STATUS||$$idx to ask the server how it’s doing.
✅ Queue: The server queues it, and $$idx tells you its position!

 

Syntax

 

HTP.MCPSignal|$$typ[|$$dat|$$ret]

 

Parameter Explanation

 

P1 - $$typ - (Variable, Required)

A variable containing the signal type (e.g., $$typ=STATUS). Defines the purpose of the signal, such as "STATUS", "PERMISSION", or a custom type. Limited to 32 characters internally.

 

P2 - $$dat - (Variable, Optional)

A variable containing optional data to accompany the signal (e.g., $$dat=Check this). If omitted, an empty string is sent.

 

P3 - $$ret - (Variable, Optional)

A variable to store the queue index of the signal (e.g., $$ret receives 0 for the first signal). Returns -1 if the queue is full (max 100 signals). If omitted, the index is placed on the top of the stack (TOS).

 

Examples

 

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

' HTP.MCPSignal - Sample 1: Send a Status Signal

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

MCP.Init

MCP.Start||$$thr

HTP.MCPSignal|STATUS||$$idx

MBX.Signal queued at index: $$idx

MBX.Ready

'

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

' HTP.MCPSignal - Sample 2: Send a Custom Signal with Data

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

$$typ=CUSTOM

$$dat=Process this

HTP.MCPSignal|$$typ|$$dat|$$idx

PRT.Custom signal queued at $$idx with data: $$dat

MBX.Ready

'

 

Remarks

 

- Thread-safe operation using a critical section to manage the signal queue.

- Signals are processed by the server thread via HTP_MCP_ProcessSignals, with responses stored in g_MCP_SignalResponse.

- Requires the server to be initialized (via MCP.Init) and running (via MCP.Start) to process signals.

 

Limitations

 

- Queue size is limited to 100 signals; returns -1 if full.

- Signal type is truncated to 32 characters internally.

- Does not wait for a response; use HTP.MCPPerm for synchronous permission requests.

 

See also:

 

MCP.Init

MCP.Start

MCP.End

HTP.MCPPerm

MCP.Stop