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

Previous Top Next


SPR Script Language

 

HTP.MCPWriteConfig

Creates a default mcp_config.json file if one does not already exist.

 

Intention

 

The MCP server relies on a JSON file named mcp_config.json for its settings. The HTP.MCPWriteConfig command is a setup utility that ensures this file exists.

If you run it and the file is missing, it will create a new one with standard default settings (e.g., port 5555, logging enabled).

If the file already exists, the command does nothing, making it safe to run at the start of any script.

 

This is perfect for ensuring your application can always find its configuration, especially on a first-time run.

 

Illustration

blueprint: If the house plans (config file) are missing, this command lays down a fresh blueprint with default room layouts. If the plans are already there, it leaves them untouched.

 

Syntax

 

HTP.MCPWriteConfig[|$$RET]

 

Parameter Explanation

 

P1 - $$RET - (Variable, Optional)

A variable to store the result code. Returns 0 if the file was written, 1 if the file already existed, or -1 on error. If omitted, the code is pushed to the stack.

 

Examples

 

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

' HTP.MCPWriteConfig - Sample 1: Ensure Config Exists

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

DEL.?path\mcp_config.json ' Ensure file is deleted for this test

HTP.MCPWriteConfig|$$ret

IVV.$$ret=0

 MBX.Config file was created successfully.

ELS.

 MBX.Something went wrong. Result code: $$ret

EIF.

ENR.

'

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

' HTP.MCPWriteConfig - Sample 2: File Already Exists

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

' First, make sure the file is there

HTP.MCPWriteConfig

' Now, run the command again

HTP.MCPWriteConfig|$$ret

IVV.$$ret=1

 MBX.Command finished. File already existed.

EIF.

ENR.

 

Remarks

 

- The configuration file is always named mcp_config.json and is created in the same directory as the robot executable.

- This command is safe to run multiple times as it will not overwrite an existing file.

 

See also:

 

MCP.Init