MesaFilesystem
Stores workspace files in Mesa repos through the standard Mastra WorkspaceFilesystem interface.
Use MesaFilesystem when agents need versioned file storage. For a local directory, use LocalFilesystem. For object storage, use S3Filesystem, GCSFilesystem, or AzureBlobFilesystem.
MesaFilesystem runs in the Mastra process.
Mesa's POSIX mount (for using a Mesa filesystem within a sandbox) is not yet part of the @mastra/mesa package. Support is coming soon.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/mesa
pnpm add @mastra/mesa
yarn add @mastra/mesa
bun add @mastra/mesa
Usage exampleDirect link to Usage example
Mount one Mesa repo and pass the filesystem to a workspace:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { MesaFilesystem } from '@mastra/mesa'
const workspace = new Workspace({
filesystem: new MesaFilesystem({
apiKey: process.env.MESA_API_KEY,
org: 'acme',
repos: [{ name: 'docs', bookmark: 'main' }],
}),
})
const agent = new Agent({
id: 'file-agent',
name: 'file-agent',
model: 'anthropic/claude-opus-4-7',
workspace,
})
apiKey falls back to MESA_API_KEY when omitted.
Constructor parametersDirect link to Constructor parameters
apiKey?:
org?:
repos:
cache?:
ttl?:
readOnly?:
PropertiesDirect link to Properties
id:
name:
provider:
readOnly:
client:
filesystem:
change:
bookmark:
MethodsDirect link to Methods
MesaFilesystem implements the WorkspaceFilesystem interface.
File operationsDirect link to File operations
readFile(path, options?)Direct link to readfilepath-options
Reads a file from Mesa.
const content = await filesystem.readFile('/acme/docs/README.md', {
encoding: 'utf-8',
})
Returns: Promise<string | Buffer>
writeFile(path, content, options?)Direct link to writefilepath-content-options
Writes a file to Mesa.
await filesystem.writeFile('/acme/docs/report.md', '# Report')
Returns: Promise<void>
appendFile(path, content)Direct link to appendfilepath-content
Appends content to a file.
await filesystem.appendFile('/acme/docs/log.txt', 'new line\n')
Returns: Promise<void>
deleteFile(path, options?)Direct link to deletefilepath-options
Deletes a file.
await filesystem.deleteFile('/acme/docs/old-report.md')
Returns: Promise<void>
copyFile(src, dest, options?)Direct link to copyfilesrc-dest-options
Copies a file.
await filesystem.copyFile('/acme/docs/report.md', '/acme/docs/archive/report.md')
Returns: Promise<void>
moveFile(src, dest, options?)Direct link to movefilesrc-dest-options
Moves or renames a file.
await filesystem.moveFile('/acme/docs/draft.md', '/acme/docs/final.md')
Returns: Promise<void>
Directory operationsDirect link to Directory operations
mkdir(path, options?)Direct link to mkdirpath-options
Creates a directory.
await filesystem.mkdir('/acme/docs/reports', { recursive: true })
Returns: Promise<void>
rmdir(path, options?)Direct link to rmdirpath-options
Removes a directory.
await filesystem.rmdir('/acme/docs/reports', { recursive: true })
Returns: Promise<void>
readdir(path, options?)Direct link to readdirpath-options
Lists directory entries.
const entries = await filesystem.readdir('/acme/docs', {
recursive: true,
extension: '.md',
})
Returns: Promise<FileEntry[]>
Path operationsDirect link to Path operations
exists(path)Direct link to existspath
Checks whether a path exists.
const exists = await filesystem.exists('/acme/docs/README.md')
Returns: Promise<boolean>
stat(path)Direct link to statpath
Returns file or directory metadata.
const stat = await filesystem.stat('/acme/docs/README.md')
Returns: Promise<FileStat>
realpath(path)Direct link to realpathpath
Returns the canonical path from Mesa.
const realPath = await filesystem.realpath('/acme/docs/README.md')
Returns: Promise<string>
Mesa operationsDirect link to Mesa operations
bash(options?)Direct link to bashoptions
Creates a Mesa-backed Bash runtime for this filesystem.
const bash = await filesystem.bash({
cwd: '/acme/docs',
})
Returns: Promise<Bash>
Path semanticsDirect link to Path semantics
Methods expect absolute paths. For MesaFilesystem, paths are rooted at the Mesa mount and must include the org slug and repo name:
await filesystem.readFile('/acme/docs/README.md')
Do not omit the leading slash:
await filesystem.readFile('acme/docs/README.md') // Incorrect
await filesystem.readFile('/acme/docs/README.md') // Correct
The org comes from org in the constructor, or from the Mesa SDK's default org inference when org is omitted. It still appears as the first path segment.
When you mount multiple repos, each repo is available under the org segment:
const filesystem = new MesaFilesystem({
org: 'acme',
repos: [
{ name: 'docs', bookmark: 'main' },
{ name: 'website', bookmark: 'main' },
],
})
await filesystem.readFile('/acme/docs/README.md')
await filesystem.readFile('/acme/website/package.json')
Mesa versioning APIsDirect link to Mesa versioning APIs
Access the underlying Mesa filesystem for Mesa-specific change and bookmark operations:
await filesystem.writeFile('/acme/docs/draft.md', 'Draft')
const current = await filesystem.change.current({
repo: 'docs',
})
await filesystem.bookmark.move({
repo: 'docs',
name: 'main',
changeId: current.changeId,
})
More details on versioning semantics can be found in Mesa's docs.
Read-only modeDirect link to Read-only mode
Set readOnly: true to block write operations through Mastra:
const filesystem = new MesaFilesystem({
repos: [{ name: 'docs', bookmark: 'main' }],
readOnly: true,
})
Read operations still work. Write operations throw WorkspaceReadOnlyError.
ConcurrencyDirect link to Concurrency
overwrite: false and expectedMtime use preflight checks before writing. These checks are not atomic unless Mesa adds native conditional writes for app mounts.