MCP Commands - FileTools

<< Click to Display Table of Contents >>

Navigation:  3. Script Language > Internet and Network > MCP. - MCP (Model-Context Protocol) server operations >

MCP Commands - FileTools

MCP FileTools - Overview

PreviousTopNext


MiniRobot Language (MRL) - MCP Server Feature

 

MCP FileTools

File Operations and Content Management

 

What are FileTools?

 

The MCP FileTools category provides a comprehensive set of commands for file operations, content management, and text manipulation. These tools enable robot scripts to read, write, analyze, and modify files, as well as work with memory and clipboard content through a unified interface.

 

Key Features

 

Unified Content Interface: Read and write content from files, memory, or clipboard using consistent URI syntax

Diff/Patch Support: Apply unified diff patches to strings, files, memory, or clipboard content

File Analysis: Retrieve detailed file metadata including size, encoding, and modification dates

Automatic Directory Creation: Parent directories are created automatically when writing files

Encoding Detection: Automatic detection of file encodings (UTF-8, UTF-16, ASCII)

 

Available Commands

 

Content Analysis Commands:

MCP.AnalyzeFile - Analyze a file and retrieve metadata (size, encoding, modification date, etc.)

 

Content I/O Commands:

MCP.GetContent - Read content from a file or memory bank (URI: file:path or memory:key)

MCP.SetContent - Write content to a file or memory bank (URI: file:path or memory:key)

MCP.CTF - Copy a file to a new location (with optional overwrite)

 

Diff/Patch Commands:

MCP.ApplyDiffToString - Apply a unified diff patch to a string variable

MCP.DiffEditFile - Apply a unified diff patch directly to a file

MCP.DiffEditMemory - Apply a unified diff patch to content stored in memory

MCP.DiffEditClipboard - Apply a unified diff patch to the current clipboard content

 

SLL Implementation

 

The FileTools category is implemented in the MCP Server SLL (Shared Library) with the following components:

 

MCP_Filetools.inc - Core dispatcher and shared helpers

 

The following tools are implemented in the SLL library:

AnalyzeFile - File analysis and metadata retrieval

GetContent - Unified content retrieval from files or memory

SetContent - Unified content writing to files or memory

ApplyDiffToString - Apply diff patches to string variables

DiffEditFile - Apply diff patches directly to files

DiffEditMemory - Apply diff patches to memory bank entries

DiffEditClipboard - Apply diff patches to clipboard content

CTF - Copy To File (file duplication)

 

Use Cases

 

File-Based Data Processing:

Read configuration files, process data files, and write results to output files with automatic directory creation.

 

Code and Text Modification:

Use diff patches for automated code refactoring, configuration updates, and batch text replacements across multiple targets.

 

Memory-Based Caching:

Store frequently accessed data in memory for fast retrieval, modify cached content with diff patches, and persist to files when needed.

 

Clipboard Automation:

Transform clipboard content programmatically for copy-paste workflows, code formatting, and template substitution.

 

Common Parameters

 

URI Format (for GetContent/SetContent):

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

memory:key - Memory bank key (e.g., memory:myData)

 

Diff Format:

All diff commands use standard unified diff format:

• Lines starting with " " (space) are context lines

• Lines starting with "-" are removed

• Lines starting with "+" are added

• @@ markers indicate hunk headers with line numbers

 

Error Handling

 

FileTools commands return detailed error messages when operations fail. Common error conditions include:

 

Missing Parameters: Required arguments not provided

File Not Found: Source file does not exist

Permission Denied: Insufficient access rights for file operations

Invalid Diff: Malformed or incompatible diff format

Context Mismatch: Diff context does not match target content

Memory Key Not Found: Specified memory key does not exist

Clipboard Error: Clipboard access denied or empty

 

Example Usage

 

' Example: Read, modify, and save file content

' 1. Analyze the file first

MCP.AnalyzeFile|C:\Config\app.ini|$$FileInfo

 

' 2. Read the content

MCP.GetContent|file:C:\Config\app.ini|$$ConfigContent

 

' 3. Apply a patch to modify settings

VAR.Patch = "--- app.ini\n+++ app.ini\n@@ -5,3 +5,3 @@\n-debug=1\n+debug=0\n loglevel=info"

MCP.ApplyDiffToString|$$ConfigContent|$$Patch|$$NewConfig

 

' 4. Save the modified content

MCP.SetContent|file:C:\Config\app.ini|$$NewConfig

 

' Alternative: Direct file patching

MCP.DiffEditFile|C:\Config\app.ini|$$Patch

 

Important Notes

 

• FileTools commands require the RESOURCES capability in MCP server configuration

• Always create backups before applying diff patches to important files

• The diff commands use fuzzy matching to handle minor context variations

• File paths support both absolute and relative paths

• For large files (over 10MB), consider memory usage implications

 

See also:

 

MCP.AnalyzeFile - Analyze a File

MCP.GetContent - Get Content

MCP.SetContent - Set Content

MCP Memory Bank Overview

MCP Tool Categories