docs/src/content/en/reference/workspace/gcs-filesystem.mdx
Stores files in Google Cloud Storage.
:::info
For interface details, see WorkspaceFilesystem Interface.
:::
npm install @mastra/gcs
Add a GCSFilesystem to a workspace and assign it to an agent:
import { Agent } from '@mastra/core/agent'
import { Workspace } from '@mastra/core/workspace'
import { GCSFilesystem } from '@mastra/gcs'
const workspace = new Workspace({
filesystem: new GCSFilesystem({
bucket: 'my-gcs-bucket',
projectId: 'my-project-id',
credentials: JSON.parse(process.env.GCS_SERVICE_ACCOUNT_KEY),
}),
})
const agent = new Agent({
name: 'file-agent',
model: 'anthropic/claude-opus-4-6',
workspace,
})
If running on Google Cloud or with gcloud CLI configured, you can omit credentials:
import { GCSFilesystem } from '@mastra/gcs'
const filesystem = new GCSFilesystem({
bucket: 'my-gcs-bucket',
// Uses Application Default Credentials automatically
})
Application Default Credentials (ADC) automatically discovers credentials in this order:
GOOGLE_APPLICATION_CREDENTIALS environment variable (path to a service account key file)gcloud auth application-default login (for local development)You can also pass a path to a service account key file:
import { GCSFilesystem } from '@mastra/gcs'
const filesystem = new GCSFilesystem({
bucket: 'my-gcs-bucket',
projectId: 'my-project-id',
credentials: '/path/to/service-account-key.json',
})
<PropertiesTable content={[ { name: 'bucket', type: 'string', description: 'GCS bucket name', }, { name: 'projectId', type: 'string', description: 'GCS project ID. Required when using service account credentials.', isOptional: true, }, { name: 'credentials', type: 'object | string', description: 'Service account key JSON object or path to key file. If not provided, uses Application Default Credentials.', isOptional: true, }, { name: 'prefix', type: 'string', description: 'Optional prefix for all keys (acts like a subdirectory)', isOptional: true, }, { name: 'id', type: 'string', description: 'Unique identifier for this filesystem instance', isOptional: true, defaultValue: 'Auto-generated', }, { name: 'displayName', type: 'string', description: 'Human-friendly display name for the UI', isOptional: true, }, { name: 'icon', type: 'FilesystemIcon', description: 'Icon identifier for the UI', isOptional: true, }, { name: 'description', type: 'string', description: 'Short description of this filesystem for the UI', isOptional: true, }, { name: 'readOnly', type: 'boolean', description: 'When true, all write operations are blocked', isOptional: true, defaultValue: 'false', }, { name: 'endpoint', type: 'string', description: 'Custom API endpoint URL. Used for local development with emulators.', isOptional: true, }, ]} />
<PropertiesTable content={[ { name: 'id', type: 'string', description: 'Filesystem instance identifier', }, { name: 'name', type: 'string', description: "Provider name ('GCSFilesystem')", }, { name: 'provider', type: 'string', description: "Provider identifier ('gcs')", }, { name: 'bucket', type: 'string', description: 'The GCS bucket name', }, { name: 'readOnly', type: 'boolean | undefined', description: 'Whether the filesystem is in read-only mode', }, ]} />
GCSFilesystem implements the WorkspaceFilesystem interface, providing all standard filesystem methods:
readFile(path, options?) - Read file contentswriteFile(path, content, options?) - Write content to a fileappendFile(path, content) - Append content to a filedeleteFile(path, options?) - Delete a filecopyFile(src, dest, options?) - Copy a filemoveFile(src, dest, options?) - Move or rename a filemkdir(path, options?) - Create a directoryrmdir(path, options?) - Remove a directoryreaddir(path, options?) - List directory contentsexists(path) - Check if a path existsstat(path) - Get file or directory metadatainit()Initialize the filesystem. Verifies bucket access and credentials.
await filesystem.init()
getInfo()Returns metadata about this filesystem instance.
const info = filesystem.getInfo()
// { id: '...', name: 'GCSFilesystem', provider: 'gcs', status: 'ready' }
getMountConfig()Returns the mount configuration for sandboxes that support mounting this filesystem type.
const config = filesystem.getMountConfig()
// { type: 'gcs', bucket: 'my-bucket', ... }
GCSFilesystem can be mounted into E2B sandboxes, making the bucket accessible as a local directory:
import { Workspace } from '@mastra/core/workspace'
import { GCSFilesystem } from '@mastra/gcs'
import { E2BSandbox } from '@mastra/e2b'
const workspace = new Workspace({
mounts: {
'/data': new GCSFilesystem({
bucket: 'my-gcs-bucket',
projectId: 'my-project-id',
credentials: JSON.parse(process.env.GCS_SERVICE_ACCOUNT_KEY),
}),
},
sandbox: new E2BSandbox({ id: 'dev-sandbox' }),
})
See E2BSandbox reference for more details on mounting.