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-Lifecycle - Commands for managing the MCP server lifecycle (init, start, stop) >

MCP. - MCP Server Operations

MCP.Init

Previous Top Next


SPR Script Language

 

MCP.Init

Initializes the MCP server, creating a default configuration file if needed.

 

Intention

 

The MCP.Init command prepares the MCP server for operation. It sets up essential server parameters by loading a JSON configuration file. Crucially, if the specified configuration file does not exist, MCP.Init will create it for you with a set of secure, default settings, making initial setup much easier. This command initializes the signal system and client queues, enabling subsequent server operations like MCP.Start.

 

Illustration

✨ First Run: Use MCP.Init, and it creates mcp_config.json for you!
⚙️ Config: Use MCP.Init|C:\MyServer\settings.json to load or create a config at a specific path.
🚀 Ready: Then, MCP.Start can launch the server with those settings!

 

Syntax

 

MCP.Init[|$$CONFIG]

 

Parameter Explanation

 

P1 - $$CONFIG - (String, Optional)

Specifies the path to a JSON configuration file. The logic is as follows:
If the parameter is omitted, it defaults to mcp_config.json in the current directory ?exelocc\.
If the file does not exist at the specified path, a new file is created with default settings.
If the file exists, it is loaded. If parsing fails, the server uses defaults in memory without overwriting the file.

 

Examples

 

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

' MCP.Init - Sample 1: Initialize with Defaults

' If mcp_config.json doesn't exist, it will be created.

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

MCP.Init

MCP.Start||$$THR

MBX.Server started with thread handle: $$THR

MBX.Ready

'

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

' MCP.Init - Sample 2: Initialize with Custom Config Path

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

$$CON="C:\MyApp\config\server_settings.json"

MCP.Init|$$CON

MCP.Start||$$THR

PRT.Server running using config from $$CON, thread: $$THR

MBX.Ready

'

 

Remarks

 

- If a config file does not exist, a new one is automatically generated with default settings, including an example "ping_test" action.

- Sets global variables like g_MCP_Port and g_MCP_LocalOnly based on the config file or defaults.

- Initializes the signal queue and critical section for thread-safe operations.

 

Limitations

 

- If an existing config file is invalid JSON, the server will use defaults without overwriting the broken file.

 

See also:

 

MCP.Start

HTP.MCPSignal