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.AnalyzeFile - Analyze a File

PreviousTopNext


MiniRobot Language (MRL) - MCP FileTools Commands

 

MCP.AnalyzeFile

Analyze a File

 

Purpose

 

The MCP.AnalyzeFile command retrieves detailed information about a specified file, including size, modification date, file type, encoding, and other metadata. This command is useful for file validation, size checking before operations, and obtaining file properties programmatically.

 

Syntax

 

MCP.AnalyzeFile|$$FILE_PATH|$$RESULT_VAR

 

Parameters

 

$$FILE_PATH - The full path to the file to analyze. Supports both absolute and relative paths.

 

$$RESULT_VAR - The variable that will receive the JSON-formatted analysis result containing file metadata.

 

Return Value

 

The command returns a JSON object containing the following file properties:

• exists - Boolean indicating if the file exists

• size - File size in bytes

• modified - Last modification timestamp (ISO format)

• created - Creation timestamp (ISO format)

• extension - File extension (e.g., ".txt", ".xml")

• isText - Boolean indicating if the file appears to be text-based

• encoding - Detected encoding (UTF-8, UTF-16, ASCII, etc.)

• lineCount - Number of lines (for text files)

 

Examples

 

' Example 1: Basic file analysis

MCP.AnalyzeFile|C:\Data\Report.txt|$$FileInfo

PRT.File analysis result: $$FileInfo

 

' Example 2: Check if file exists and get size

MCP.AnalyzeFile|$$TargetFile|$$Analysis

' Parse the JSON result to check existence

JSN.Get|$$Analysis|exists|$$Exists

IVV.$$Exists!true

JSN.Get|$$Analysis|size|$$FileSize

PRT.File size: $$FileSize bytes

ELS.

PRT.File does not exist

EIF.

 

' Example 3: Verify file before processing

MCP.AnalyzeFile|$$InputFile|$$Info

JSN.Get|$$Info|isText|$$IsText

IVV.$$IsText!true

MCP.GetContent|file:$$InputFile|$$Content

' Process text content...

ELS.

PRT.Error: File is not a text file

EIF.

 

Remarks

 

The MCP.AnalyzeFile command requires the FileTools feature to be enabled in the MCP server configuration. If the file does not exist, the command will still return a valid JSON object with exists set to false and other fields null or zero.

 

For large files, the line count operation may take some time as the file must be read entirely. The encoding detection uses BOM (Byte Order Mark) analysis and heuristics for files without BOM.

 

Error Conditions

 

The command will fail with an error if:

• The file path parameter is missing

• The return variable parameter is missing

• The file path is invalid or contains illegal characters

• The user does not have permission to access the file

 

See also:

 

MCP.GetContent - Get Content from File or Memory

MCP.SetContent - Set Content to File or Memory

FileTools Overview