Skip to main content

Overview

The ACP SDK provides methods for agents to read and write files in the client’s file system. These operations are only available if the client advertises the corresponding capabilities during initialization.
File system operations require the client to explicitly enable these capabilities. Always check that the client advertised the capability before attempting to use these methods.

Reading Files

The readTextFile method reads content from a text file:
string
required
The session ID making the request
string
required
Absolute path to the file to read
string
required
The file contents as a string
Only available if the client advertises the fs.readTextFile capability during initialization.
See protocol docs: Client

Example

All paths in the protocol should be absolute paths.

Writing Files

The writeTextFile method writes content to a text file:
string
required
The session ID making the request
string
required
Absolute path to the file to write
string
required
The content to write to the file
Only available if the client advertises the fs.writeTextFile capability during initialization.
Allows the agent to create or modify files within the client’s environment. See protocol docs: Client

Example

Error Handling

Handle errors appropriately when working with file system operations:

Error Codes

number
Resource not found - the file does not exist
number
Internal error - an error occurred while reading or writing the file

Security Considerations

File system operations can be sensitive. Always follow these security best practices:

Path Validation

Ensure paths are absolute and within expected boundaries:

Permission Requests

Request user permission before writing sensitive files:

Capability Checking

Always verify capabilities before attempting operations:

Complete Example

Here’s a complete example that demonstrates safe file operations:

Best Practices

Check Capabilities

Always verify the client supports file operations before attempting them

Use Absolute Paths

All paths in the protocol must be absolute, not relative

Handle Errors

Gracefully handle file not found and permission errors

Request Permission

Request user permission before writing sensitive files