|
<< 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 |
SPR Script Language
HTP.MCPPerm
Request permission from the MCP server with a request string, optional timeout, returning result and response.
Intention
The HTP.MCPPerm command sends a "PERMISSION" signal to the MCP (Multi-Client Protocol) server and waits synchronously for a response, unlike the asynchronous HTP.MCPSignal. You provide a request string (e.g., "Can I proceed?") and an optional timeout in milliseconds, and it returns a result code (0 for granted, 1 for denied, -1 for error/timeout) along with the server’s response (e.g., "GRANTED"). This is ideal for scenarios requiring immediate feedback from the server, which must be running via MCP.Start.
Picture it as asking the server bouncer for entry—HTP.MCPPerm knocks on the door, waits for a "yes" or "no," and tells you right away if you’re in.
Illustration
🚪 Request: Use HTP.MCPPerm|Can I proceed?|2000|$$res to ask permission with a 2-second timeout.
✅ Answer: $$res might return "0 GRANTED" if approved!
Syntax
HTP.MCPPerm|$$req[|$$tim|$$ret]
Parameter Explanation
P1 - $$req - (Variable, Required)
A variable containing the permission request string (e.g., $$req=Can I proceed?). Sent as data with the "PERMISSION" signal type.
P2 - $$tim - (Variable, Optional)
A variable containing the timeout in milliseconds (e.g., $$tim=2000). Defaults to 5000 ms (5 seconds) if omitted or zero.
P3 - $$ret - (Variable, Optional)
A variable to store the result and response (e.g., $$ret receives "0 GRANTED"). Result codes: 0 (granted), 1 (denied), -1 (error/timeout). If omitted, the result is pushed to the top of the stack (TOS).
Examples
'***********************************
' HTP.MCPPerm - Sample 1: Basic Permission Request
'***********************************
MCP.Init
MCP.Start||$$thr
HTP.MCPPerm|Can I proceed?||$$res
MBX.Permission result: $$res
MCP.Stop
MBX.Ready
'
'***********************************
' HTP.MCPPerm - Sample 2: Permission with Timeout
'***********************************
MCP.Init
MCP.Start||$$thr
$$req=Access resource
$$tim=2000
HTP.MCPPerm|$$req|$$tim|$$res
PRT.Request: $$req, Result: $$res (timeout 2s)
MCP.Stop
MBX.Ready
'
Remarks
- Synchronously waits for the server to process the "PERMISSION" signal, polling every 10 ms until the timeout expires.
- Returns a string combining the result code and response (e.g., "0 GRANTED" or "-1 Timeout"), stored in $$ret or TOS.
- Thread-safe, using a critical section to access the signal queue.
Limitations
- Requires the server to be initialized (via MCP.Init) and running (via MCP.Start).
- Signal queue limit (100) applies; if full, returns -1 immediately.
- Server response logic is currently fixed (always "GRANTED"); future updates may add configurable rules.
See also:
• MCP.Init
• MCP.End
• MCP.Stop