MCP Commands - FileTools

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

MCP.GetContent - Get Content from File or Memory

PreviousTopNext


MiniRobot Language (MRL) - MCP FileTools Commands

 

MCP.GetContent

Get Content from File or Memory

 

Purpose

 

The MCP.GetContent command retrieves content from either a file or the MCP memory bank using a unified URI-style syntax. This command provides a consistent interface for reading data regardless of whether it's stored in the filesystem or in memory, simplifying scripts that need to work with data from multiple sources.

 

Syntax

 

MCP.GetContent|$$URI|$$RESULT_VAR

 

Parameters

 

$$URI - The source URI specifying where to get content from. Format: "file:path" or "memory:key"

 

$$RESULT_VAR - The variable that will receive the retrieved content.

 

URI Format

 

The URI parameter uses a prefix scheme to identify the content source:

 

file:path - Read from file system (e.g., file:C:\Data\file.txt)

memory:key - Read from MCP memory bank (e.g., memory:myData)

 

Return Value

 

The command returns the content as a string. For binary files, the content is returned as a base64-encoded string. If the source does not exist, an error is returned.

 

Examples

 

' Example 1: Read content from a file

MCP.GetContent|file:C:\Documents\Report.txt|$$FileContent

PRT.File content: $$FileContent

 

' Example 2: Read from memory bank

MCP.GetContent|memory:cachedData|$$CachedValue

PRT.Cached: $$CachedValue

 

' Example 3: Process file with variable path

VAR.FilePath = "C:\Data\Input.xml"

MCP.GetContent|file:$$FilePath|$$XmlData

' Parse and process the XML data...

 

' Example 4: Transfer between file and memory

' Load file into memory for repeated access

MCP.GetContent|file:C:\Config\Settings.json|$$ConfigJson

MCP.SetContent|memory:config|$$ConfigJson

 

' Example 5: Use with diff operations

MCP.GetContent|file:C:\Source\Code.bas|$$SourceCode

MCP.GetContent|memory:patch|$$PatchData

MCP.ApplyDiffToString|$$SourceCode|$$PatchData|$$ModifiedCode

 

Remarks

 

The MCP.GetContent command automatically handles encoding detection for text files. For files with BOM (Byte Order Mark), the encoding is detected automatically. For files without BOM, UTF-8 is assumed for text files.

 

When reading from memory, the command behaves like MEM.RCL but with a unified interface. The memory key must exist or an error will be returned.

 

For large files (over 10MB), consider using chunked reading or streaming approaches to avoid memory issues.

 

Error Conditions

 

The command will fail with an error if:

• The URI parameter is missing or malformed

• The file does not exist (for file: URIs)

• The memory key does not exist (for memory: URIs)

• Permission is denied for file access

• The return variable parameter is missing

 

See also:

 

MCP.SetContent - Set Content to File or Memory

MEM.RCL - Recall Value from Memory

MCP.AnalyzeFile - Analyze a File

FileTools Overview