|
<< Click to Display Table of Contents >> Navigation: 3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations > File Tools - File and content operations > MCP Commands - FileTools |
MiniRobot Language (MRL) - MCP FileTools Commands
MCP.SetContent
Set Content to File or Memory
Purpose
The MCP.SetContent command writes content to either a file or the MCP memory bank using a unified URI-style syntax. This command provides a consistent interface for saving data regardless of whether the destination is the filesystem or memory, making it easy to persist data across different storage types.
Syntax
MCP.SetContent|$$URI|$$CONTENT
Parameters
$$URI - The destination URI specifying where to store content. Format: "file:path" or "memory:key"
$$CONTENT - The content to store. Can be a string variable or literal value.
URI Format
The URI parameter uses a prefix scheme to identify the storage destination:
file:path - Write to file system (e.g., file:C:\Data\output.txt)
memory:key - Store in MCP memory bank (e.g., memory:tempData)
Return Value
The command returns the number of bytes written (as a string) on success, or an error message on failure. For memory storage, this reflects the string length of the stored content.
Examples
' Example 1: Write content to a file
VAR.Data = "This is my report data"
MCP.SetContent|file:C:\Reports\Output.txt|$$Data
' Example 2: Store in memory bank
MCP.SetContent|memory:sessionData|$$ProcessedResult
' Example 3: Copy between file and memory
' Read from file, modify, save back
MCP.GetContent|file:C:\Input.txt|$$Content
STR.Replace|$$Content|old|new|$$Modified
MCP.SetContent|file:C:\Output.txt|$$Modified
' Example 4: Save JSON data
JSN.Set|$$JsonObj|name|John
JSN.Set|$$JsonObj|age|30
MCP.SetContent|file:C:\Data\User.json|$$JsonObj
' Example 5: Temporary storage in memory
' Store intermediate result for later use
CAL.ComputeExpensiveOperation|$$Result
MCP.SetContent|memory:cachedResult|$$Result
Remarks
When writing to files, the command automatically creates parent directories if they don't exist. Files are written with UTF-8 encoding by default. If the file already exists, it will be overwritten without warning.
When storing to memory, the command behaves like MEM.STO but with a unified interface. Memory storage is temporary unless the MCP server is configured for persistence.
For large content (over 10MB), consider using chunked writing or file streaming to avoid memory issues.
Error Conditions
The command will fail with an error if:
• The URI parameter is missing or malformed
• Cannot create parent directories (insufficient permissions)
• Disk is full or quota exceeded
• File is locked by another process
• Content parameter is missing
See also:
• MCP.GetContent - Get Content from File or Memory
• MEM.STO - Store Value in Memory