Skip to main content

Overview

File system capabilities allow agents to read and write files in the client’s environment. These operations require careful security considerations to prevent unauthorized access.

Advertising Capabilities

Declare file system support during initialization:
Only advertise capabilities you actually implement. The agent will call these methods if you declare support.

readTextFile()

Reads content from a text file in the client’s file system.

Method Signature

string
The session making the request.
string
Absolute file path to read.
string
required
The file contents as a UTF-8 string.

Basic Implementation

Secure Implementation

Add path validation and sandboxing:

writeTextFile()

Writes content to a text file in the client’s file system.

Method Signature

string
The session making the request.
string
Absolute file path to write.
string
The content to write (UTF-8).
object
Returns an empty object {} on success.

Basic Implementation

Secure Implementation

Add validation, backups, and atomic writes:

Security Considerations

Path Sandboxing

Restrict file access to specific directories:

File Type Restrictions

Restrict which file types can be accessed:

Size Limits

Enforce file size limits:

Binary File Detection

Prevent reading binary files as text:

Error Handling

Standard Errors

Use standard error codes:

User Notifications

Notify users about file operations:

Version Control Integration

For editors with git integration:

Testing

See Also