Skip to main content

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.

info

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.

Installation
Direct link to Installation

npm install @mastra/mesa

Usage example
Direct link to Usage example

Mount one Mesa repo and pass the filesystem to a workspace:

src/mastra/workspace.ts
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 parameters
Direct link to Constructor parameters

apiKey?:

string
Mesa API key. Falls back to `MESA_API_KEY` when omitted.

org?:

string
Mesa org slug. When omitted, the Mesa SDK resolves the default org.

repos:

RepoConfig[]
Mesa repos to mount.

cache?:

{ diskCache?: { path: string; maxSizeBytes?: number } }
Mesa filesystem cache configuration.

ttl?:

number
Mesa mount token lifetime in seconds.

readOnly?:

boolean
= false
Mount all repos as read-only.

Properties
Direct link to Properties

id:

string
Filesystem instance identifier.

name:

string
Provider name (`'MesaFilesystem'`).

provider:

string
Provider identifier (`'mesa'`).

readOnly:

boolean | undefined
Whether write operations are blocked.

client:

Mesa | undefined
Mesa SDK client created by this provider. Undefined before initialization.

filesystem:

MesaFileSystem
Active Mesa filesystem. Access this after initialization when you need the raw Mesa SDK filesystem.

change:

MesaFileSystem["change"]
Mesa change management operations for the mounted filesystem.

bookmark:

MesaFileSystem["bookmark"]
Mesa bookmark management operations for the mounted filesystem.

Methods
Direct link to Methods

MesaFilesystem implements the WorkspaceFilesystem interface.

File operations
Direct 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 operations
Direct 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 operations
Direct 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 operations
Direct 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 semantics
Direct 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 APIs
Direct 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 mode
Direct 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.

Concurrency
Direct 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.