|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > MCP Commands - Server Lifecycle |
MiniRobot Language (MRL) - MCP Server Operations
MCP Server Lifecycle
Initialize, Start, Stop, and Manage the MCP Server
Overview
The MCP (Model Context Protocol) Server Lifecycle commands control the initialization, startup, operation, and shutdown of the MCP server. These commands form the foundation for all MCP functionality - without a properly initialized and running server, no other MCP operations can be performed.
Lifecycle Commands
1. Initialization Phase
Initializes the MCP server with optional configuration file. Sets up internal data structures, loads tool definitions, and prepares the server for startup. Can be called explicitly or is automatically called by MCP.Start if not already done.
2. Startup Phase
Starts the MCP server in a separate thread. This command initializes the server (if not already done), starts the HTTP listener, and begins accepting connections. Returns immediately with a thread handle while the server runs in the background.
3. Runtime Phase
Checks if the MCP server is currently running and accepting connections. Useful for verifying server status before attempting operations or for monitoring health.
4. Shutdown Phase
Gracefully shuts down the MCP server. Stops accepting new connections, waits for pending operations to complete, saves persistent data, and terminates the server thread. This is the recommended way to stop the server.
Sends an immediate END signal to terminate the MCP server. Forces shutdown without waiting for pending operations. Use only when MCP.Stop fails or for emergency shutdown.
Typical Lifecycle Patterns
Pattern 1: Simple Start and Stop
' Start the server with default configuration
MCP.Start|$$ThreadHandle
LBL.|Server started with handle: $$ThreadHandle
' ... perform MCP operations ...
' Stop the server gracefully
MCP.Stop
Pattern 2: With Custom Configuration
' Initialize with custom config
MCP.Init|C:\\Config\\mcp_custom.json|$$InitResult
IVV.$$InitResult!1
MCP.Start|$$Handle
LBL.|Server started successfully
EIV.
Pattern 3: Health Monitoring
' Check if server is running before operations
MCP.IsRunning|$$Running
IVV.$$Running!1
' Server is running, proceed with operations
MCP.Exec|some_tool|$$Result
EIV.
' Server not running, start it
MCP.Start|$$Handle
EIF.
Server States
Uninitialized: No server data structures exist. No operations possible.
Initialized: Server structures ready but not accepting connections. MCP.Start required.
Running: Server active, accepting connections and processing requests.
Stopping: Graceful shutdown in progress. New requests rejected.
Stopped: Server terminated. Can be restarted with MCP.Start.
Important Notes
• MCP.Start automatically calls MCP.Init if not already initialized.
• MCP.Stop is preferred over MCP.End for normal shutdown.
• Server configuration can be loaded from JSON file during initialization.
• Multiple start/stop cycles are supported within a single MiniRobot session.
• Use MCP.IsRunning before operations to ensure server availability.
See Also
• MCP.Init - Initialize server
• MCP.Start - Start server
• MCP.Stop - Stop server gracefully
• MCP.End - Force stop server
• MCP.IsRunning - Check server status