Remote Filesystem Support for Mastra Agents

Give your agents access to filesystems your team already use.

Paul ScanlonPaul Scanlon·

Sep 7, 2026

·

3 min read

Your agents can now access the same filesystems your team's already using. Attach a provider to the workspace and the agent gets tools to read, write, edit, list, search, and delete files. Any changes made by either humans or agents happen in the same bucket, folder, or drive.

Filesystems are configurable — grant access by user, role, or tenant, or restrict agent access to read-only.

Mastra currently supports the following remote filesystems:

And our own filesystem on the Mastra Platform.

Every filesystem exposes the following tools your agents can use:

ToolDescription
read_fileReads all or part of a file.
write_fileCreates or overwrites a file.
edit_fileReplaces matching text in an existing file.
list_filesLists files and directories.
deleteDeletes a file or directory.
file_statReturns metadata about a file or directory.
mkdirCreates a directory and any missing parent directories.
grepSearches file contents with a regular expression.
ast_editApplies structural code edits. Available when @ast-grep/napi is installed.

Get started

Install a filesystem provider. This example uses Google Drive:

GNU BashTerminal
npm install @mastra/google-drive
note
All listed providers work with @mastra/core@1.51.0 or later, added in PR #18908.

Create a workspace with a GoogleDriveFilesystem pointed at a Shared Drive folder:

TypeScriptsrc/mastra/workspaces/google-drive-workspace.ts
import { Workspace } from "@mastra/core/workspace";
import { GoogleDriveFilesystem } from "@mastra/google-drive";
 
export const googleDriveWorkspace = new Workspace({
  id: "google-drive-workspace",
  filesystem: new GoogleDriveFilesystem({
    folderId: process.env.GOOGLE_DRIVE_FOLDER_ID,
    serviceAccount: {
      clientEmail: process.env.GOOGLE_DRIVE_CLIENT_EMAIL,
      privateKey: process.env.GOOGLE_DRIVE_PRIVATE_KEY
    }
  })
});

Attach the workspace to an agent. The filesystem's file-management tools are exposed to the agent automatically:

TypeScriptsrc/mastra/agents/recruiter-agent.ts
import { Agent } from "@mastra/core/agent";
import { Memory } from "@mastra/memory";
import { readPdfTool } from "../tools/read-pdf-tool";
import { googleDriveWorkspace } from "../workspaces/google-drive-workspace";
 
export const recruiterAgent = new Agent({
  id: "recruiter-agent",
  // ...
  workspace: googleDriveWorkspace
});

Register the workspace on your main Mastra instance:

TypeScriptsrc/mastra/index.ts
import { Mastra } from "@mastra/core/mastra";
import { googleDriveWorkspace } from "./workspaces/google-drive-workspace";
 
export const mastra = new Mastra({
  // ...
  workspace: googleDriveWorkspace
});

Dynamic filesystems

Pass filesystem a function that reads values from requestContext to scope the folder per user, tenant, or thread:

TypeScriptsrc/mastra/workspaces/google-drive-workspace.ts
import { Workspace } from "@mastra/core/workspace";
import { GoogleDriveFilesystem } from "@mastra/google-drive";
 
const workspace = new Workspace({
  // ...
  filesystem: ({ requestContext }) => {
    return new GoogleDriveFilesystem({
      folderId: requestContext.get("folder-id") as string,
      serviceAccount: {
        clientEmail: process.env.GOOGLE_DRIVE_CLIENT_EMAIL,
        privateKey: process.env.GOOGLE_DRIVE_PRIVATE_KEY
      }
    });
  }
});

Filesystem constraints

Policies and containment vary by provider with some supporting allowedPaths and others prefix, but every provider listed above supports readOnly: true:

TypeScriptsrc/mastra/workspaces/google-drive-workspace.ts
import { Workspace } from "@mastra/core/workspace";
import { GoogleDriveFilesystem } from "@mastra/google-drive";
 
const workspace = new Workspace({
  // ...
  filesystem: new GoogleDriveFilesystem({
    folderId: process.env.GOOGLE_DRIVE_FOLDER_ID,
    serviceAccount: {
      clientEmail: process.env.GOOGLE_DRIVE_CLIENT_EMAIL,
      privateKey: process.env.GOOGLE_DRIVE_PRIVATE_KEY
    },
    readOnly: true
  })
});

For more information and full configuration options, see:

Share on X or LinkedIn
Paul Scanlon
Paul ScanlonTechnical Product Marketing Manager

Paul Scanlon sits between Developer Education and Product Marketing at Mastra. Previously, he was a Technical Product Marketing Manager at Neon and worked in Developer Relations at Gatsby, where he created educational content and developer experiences.

All articles by Paul Scanlon