@mastra/mcp-docs-server 1.2.16 → 1.2.17-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/docs/agents/code-mode.md +2 -2
- package/.docs/docs/agents/skills.md +1 -1
- package/.docs/docs/agents/using-tools.md +1 -1
- package/.docs/docs/harness/agent-controller.md +1 -1
- package/.docs/docs/mcp/overview.md +4 -5
- package/.docs/docs/studio/overview.md +1 -1
- package/.docs/docs/workspace/filesystem.md +182 -153
- package/.docs/docs/workspace/lsp.md +4 -5
- package/.docs/docs/workspace/sandbox.md +234 -141
- package/.docs/docs/workspace/search.md +52 -4
- package/.docs/docs/workspace/skills.md +62 -33
- package/.docs/integrations/browsers/browser-viewer.md +2 -2
- package/.docs/integrations/file-storage/amazon-s3.md +1 -1
- package/.docs/integrations/file-storage/azure-blob.md +1 -1
- package/.docs/integrations/file-storage/google-cloud-storage.md +1 -1
- package/.docs/integrations/file-storage/mesa.md +1 -1
- package/.docs/integrations/file-storage/vercel-files.md +1 -1
- package/.docs/integrations/sandboxes/apple-container.md +1 -1
- package/.docs/integrations/sandboxes/daytona.md +1 -1
- package/.docs/integrations/sandboxes/docker.md +1 -1
- package/.docs/integrations/sandboxes/e2b.md +1 -1
- package/.docs/integrations/sandboxes/modal.md +1 -1
- package/.docs/models/environment-variables.md +1 -0
- package/.docs/models/gateways/vercel.md +3 -2
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/baseten.md +2 -1
- package/.docs/models/providers/crossmodel.md +2 -2
- package/.docs/models/providers/crusoe.md +80 -0
- package/.docs/models/providers/deepinfra.md +3 -1
- package/.docs/models/providers/fireworks-ai.md +26 -20
- package/.docs/models/providers/huggingface.md +5 -1
- package/.docs/models/providers/hyper.md +1 -1
- package/.docs/models/providers/kilo.md +4 -4
- package/.docs/models/providers/llmgateway.md +3 -2
- package/.docs/models/providers/merge-gateway.md +5 -2
- package/.docs/models/providers/nano-gpt.md +6 -6
- package/.docs/models/providers/ofox.md +5 -1
- package/.docs/models/providers/opencode-go.md +2 -1
- package/.docs/models/providers/opencode.md +3 -1
- package/.docs/models/providers/requesty.md +3 -1
- package/.docs/models/providers/zai-coding-plan.md +3 -2
- package/.docs/models/providers/zhipuai-coding-plan.md +2 -1
- package/.docs/models/providers.md +1 -0
- package/.docs/reference/agent-controller/agent-controller-class.md +26 -1
- package/.docs/reference/browser/browser-viewer.md +1 -1
- package/.docs/reference/configuration.md +1 -1
- package/.docs/reference/core/removeWorkspace.md +1 -1
- package/.docs/reference/file-based-agents/workspace.md +3 -3
- package/.docs/reference/observability/tracing/exporters/mastra-platform-exporter.md +2 -0
- package/.docs/reference/processors/skill-search-processor.md +1 -1
- package/.docs/reference/tools/create-code-mode.md +1 -1
- package/.docs/reference/tools/create-tool.md +11 -3
- package/.docs/reference/tools/mcp-server.md +4 -1
- package/.docs/reference/workspace/local-filesystem.md +1 -1
- package/.docs/reference/workspace/local-sandbox.md +1 -1
- package/.docs/reference/workspace/workspace-class.md +52 -15
- package/CHANGELOG.md +14 -0
- package/package.json +5 -5
- package/.docs/docs/workspace/overview.md +0 -416
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
|
-
|
|
3
|
-
# Workspaces
|
|
4
|
-
|
|
5
|
-
**Added in:** `@mastra/core@1.1.0`
|
|
6
|
-
|
|
7
|
-
A Mastra workspace gives agents a persistent environment for storing files and executing commands. Agents use workspace tools to read and write files and run shell commands, plus search indexed content.
|
|
8
|
-
|
|
9
|
-
A workspace supports the following features:
|
|
10
|
-
|
|
11
|
-
- **[Filesystem](https://mastra.ai/docs/workspace/filesystem)**: File storage (read, write, list, delete, copy, move, grep)
|
|
12
|
-
- **[Sandbox](https://mastra.ai/docs/workspace/sandbox)**: Command execution (shell commands) and background processes
|
|
13
|
-
- **[LSP inspection](https://mastra.ai/docs/workspace/lsp)**: Hover, definition, and implementation queries through language servers
|
|
14
|
-
- **[Search](https://mastra.ai/docs/workspace/search)**: BM25, vector, or hybrid search over indexed content
|
|
15
|
-
- **[Skills](https://mastra.ai/docs/workspace/skills)**: Reusable instructions for agents
|
|
16
|
-
|
|
17
|
-
## When to use workspaces
|
|
18
|
-
|
|
19
|
-
Use a workspace when your agent needs access to the local filesystem, shell commands, semantic code inspection, indexed search, or reusable skill instructions.
|
|
20
|
-
|
|
21
|
-
## How it works
|
|
22
|
-
|
|
23
|
-
When you assign a workspace to an agent, Mastra includes the corresponding tools in the agent's toolset. The agent can then use these tools to interact with files and execute commands.
|
|
24
|
-
|
|
25
|
-
You can create a workspace with any combination of the supported features. The agent receives only the tools relevant to what's configured.
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
|
|
29
|
-
### Creating a workspace
|
|
30
|
-
|
|
31
|
-
Create a workspace by instantiating the `Workspace` class with your desired features:
|
|
32
|
-
|
|
33
|
-
```typescript
|
|
34
|
-
import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
|
|
35
|
-
|
|
36
|
-
const workspace = new Workspace({
|
|
37
|
-
filesystem: new LocalFilesystem({
|
|
38
|
-
basePath: './workspace',
|
|
39
|
-
}),
|
|
40
|
-
sandbox: new LocalSandbox({
|
|
41
|
-
workingDirectory: './workspace',
|
|
42
|
-
}),
|
|
43
|
-
skills: ['skills'],
|
|
44
|
-
})
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
The `skills` array specifies paths to directories containing skill definitions, see [Skills](https://mastra.ai/docs/workspace/skills).
|
|
48
|
-
|
|
49
|
-
### Global workspace
|
|
50
|
-
|
|
51
|
-
Set a workspace on the Mastra instance. All agents inherit this workspace unless they define their own:
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
import { Mastra } from '@mastra/core'
|
|
55
|
-
import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
|
|
56
|
-
|
|
57
|
-
const workspace = new Workspace({
|
|
58
|
-
filesystem: new LocalFilesystem({ basePath: './workspace' }),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const mastra = new Mastra({
|
|
62
|
-
workspace,
|
|
63
|
-
})
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
### Agent-level workspace
|
|
67
|
-
|
|
68
|
-
Assign a workspace directly to an agent to override the global workspace:
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import { Agent } from '@mastra/core/agent'
|
|
72
|
-
import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
|
|
73
|
-
|
|
74
|
-
const workspace = new Workspace({
|
|
75
|
-
filesystem: new LocalFilesystem({ basePath: './agent-workspace' }),
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
export const myAgent = new Agent({
|
|
79
|
-
id: 'my-agent',
|
|
80
|
-
model: 'openai/gpt-5.6-sol',
|
|
81
|
-
workspace,
|
|
82
|
-
})
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## Lifecycle and cleanup
|
|
86
|
-
|
|
87
|
-
Mastra registers global and agent workspaces so they can be listed and retrieved at runtime. When you call `mastra.shutdown()`, Mastra destroys registered workspaces that it owns. This closes workspace resources such as language servers, browsers, sandbox processes, and filesystem provider handles.
|
|
88
|
-
|
|
89
|
-
For manual cleanup, use [`mastra.removeWorkspace()`](https://mastra.ai/reference/core/removeWorkspace). Pass `{ destroy: true }` when the workspace should be destroyed before it's removed from the registry.
|
|
90
|
-
|
|
91
|
-
Static providers are owned by the workspace. Resolver-backed providers are owned by your application because the workspace creates them at request time. See [runtime sandbox lifecycle ownership](https://mastra.ai/docs/workspace/sandbox) for the resolver cleanup model.
|
|
92
|
-
|
|
93
|
-
## Configuration patterns
|
|
94
|
-
|
|
95
|
-
Workspaces support several configuration patterns depending on what capabilities your agent needs. The main building blocks are `filesystem` (file tools) and `sandbox` (command execution), with `mounts` as the way to bridge cloud storage into sandboxes.
|
|
96
|
-
|
|
97
|
-
### Filesystem + sandbox (local)
|
|
98
|
-
|
|
99
|
-
For local development, pair a `LocalFilesystem` and `LocalSandbox` pointed at the same directory. Since both operate on the local machine, files written through the filesystem are immediately available to commands in the sandbox:
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
const workspace = new Workspace({
|
|
103
|
-
filesystem: new LocalFilesystem({ basePath: './workspace' }),
|
|
104
|
-
sandbox: new LocalSandbox({ workingDirectory: './workspace' }),
|
|
105
|
-
})
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
The agent receives both file tools and `execute_command`. This is the simplest full-featured setup.
|
|
109
|
-
|
|
110
|
-
### Mounts + sandbox (cloud storage)
|
|
111
|
-
|
|
112
|
-
When you need cloud storage accessible inside a sandbox, use `mounts`. This FUSE-mounts the cloud filesystem into the sandbox so commands can read and write files at the mount path:
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
const workspace = new Workspace({
|
|
116
|
-
mounts: {
|
|
117
|
-
'/data': new S3Filesystem({
|
|
118
|
-
bucket: 'my-bucket',
|
|
119
|
-
region: 'us-east-1',
|
|
120
|
-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
121
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
122
|
-
}),
|
|
123
|
-
'/skills': new GCSFilesystem({
|
|
124
|
-
bucket: 'agent-skills',
|
|
125
|
-
}),
|
|
126
|
-
},
|
|
127
|
-
sandbox: new E2BSandbox({ id: 'dev-sandbox' }),
|
|
128
|
-
})
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
Under the hood, `mounts` creates a [CompositeFilesystem](https://mastra.ai/docs/workspace/filesystem) that routes file tool operations to the correct provider based on path prefix. Commands in the sandbox access the mounted paths directly (e.g., `ls /data`).
|
|
132
|
-
|
|
133
|
-
You can mount multiple providers at different paths. Each mount path must be unique and non-overlapping.
|
|
134
|
-
|
|
135
|
-
> **Note:** `filesystem` and `mounts` are mutually exclusive, you can't use both in the same workspace. Use `filesystem` for a single provider without a sandbox, or `mounts` when you need to combine cloud storage with a sandbox.
|
|
136
|
-
|
|
137
|
-
### Filesystem only
|
|
138
|
-
|
|
139
|
-
Use a single `filesystem` when agents only need to read and write files. No command execution is available.
|
|
140
|
-
|
|
141
|
-
```typescript
|
|
142
|
-
const workspace = new Workspace({
|
|
143
|
-
filesystem: new S3Filesystem({
|
|
144
|
-
bucket: 'my-bucket',
|
|
145
|
-
region: 'us-east-1',
|
|
146
|
-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
147
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
148
|
-
}),
|
|
149
|
-
})
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
The agent receives file tools (`read_file`, `write_file`, `list_directory`, `grep`, etc.) that operate directly against the storage provider.
|
|
153
|
-
|
|
154
|
-
### Sandbox only
|
|
155
|
-
|
|
156
|
-
Use a single `sandbox` when agents only need to execute commands. No file tools are added.
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
const workspace = new Workspace({
|
|
160
|
-
sandbox: new E2BSandbox({ id: 'dev-sandbox' }),
|
|
161
|
-
})
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
The agent receives the `execute_command` tool.
|
|
165
|
-
|
|
166
|
-
### Dynamic filesystem (per-request)
|
|
167
|
-
|
|
168
|
-
Pass a resolver function to `filesystem` to return a different filesystem per request. This is useful for multi-tenant applications or multi-role agents where each request needs a different storage root or different permissions.
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
const workspace = new Workspace({
|
|
172
|
-
filesystem: ({ requestContext }) => {
|
|
173
|
-
const role = requestContext.get('agent-role') || 'guest'
|
|
174
|
-
return new LocalFilesystem({
|
|
175
|
-
basePath: `/workspaces/${role}`,
|
|
176
|
-
readOnly: role !== 'admin',
|
|
177
|
-
})
|
|
178
|
-
},
|
|
179
|
-
})
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
One workspace instance serves all requests. The resolver runs at tool execution time, so each request gets its own filesystem. See [dynamic filesystem](https://mastra.ai/docs/workspace/filesystem) for details.
|
|
183
|
-
|
|
184
|
-
### Dynamic sandbox (per-request)
|
|
185
|
-
|
|
186
|
-
Pass a resolver function to `sandbox` to return a different sandbox per request. This is useful for multi-tenant deployments where each user or role needs an isolated working directory or different execution permissions.
|
|
187
|
-
|
|
188
|
-
```typescript
|
|
189
|
-
const workspace = new Workspace({
|
|
190
|
-
sandbox: ({ requestContext }) => {
|
|
191
|
-
const userId = requestContext.get('user-id') as string
|
|
192
|
-
return new LocalSandbox({
|
|
193
|
-
workingDirectory: `/workspaces/${userId}`,
|
|
194
|
-
})
|
|
195
|
-
},
|
|
196
|
-
})
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
The resolver is incompatible with `mounts` and `lsp: true`, since both require a concrete sandbox instance at construction time. See [dynamic sandbox](https://mastra.ai/docs/workspace/sandbox) for details.
|
|
200
|
-
|
|
201
|
-
### Which pattern should I use?
|
|
202
|
-
|
|
203
|
-
| Scenario | Pattern |
|
|
204
|
-
| --------------------------------------------------------- | ----------------------------------------------------- |
|
|
205
|
-
| Local development with files and commands | `filesystem` + `sandbox` (both local, same directory) |
|
|
206
|
-
| Cloud storage accessible inside a cloud sandbox | `mounts` + `sandbox` |
|
|
207
|
-
| Multiple cloud providers in one sandbox | `mounts` + `sandbox` (one mount per provider) |
|
|
208
|
-
| Agent reads/writes files, no command execution needed | `filesystem` only |
|
|
209
|
-
| Agent runs commands, no file tools needed | `sandbox` only |
|
|
210
|
-
| Multi-role or multi-tenant agent with per-request storage | `filesystem` with resolver function |
|
|
211
|
-
| Multi-tenant agent with per-request execution scope | `sandbox` with resolver function |
|
|
212
|
-
|
|
213
|
-
## Tool configuration
|
|
214
|
-
|
|
215
|
-
Configure tool behavior through the `tools` option on the workspace. This controls which tools are enabled and how they behave.
|
|
216
|
-
|
|
217
|
-
```typescript
|
|
218
|
-
import { Workspace, LocalFilesystem, LocalSandbox, WORKSPACE_TOOLS } from '@mastra/core/workspace'
|
|
219
|
-
|
|
220
|
-
const workspace = new Workspace({
|
|
221
|
-
filesystem: new LocalFilesystem({ basePath: './workspace' }),
|
|
222
|
-
sandbox: new LocalSandbox({ workingDirectory: './workspace' }),
|
|
223
|
-
tools: {
|
|
224
|
-
// Global defaults
|
|
225
|
-
enabled: true,
|
|
226
|
-
requireApproval: false,
|
|
227
|
-
|
|
228
|
-
// Per-tool overrides
|
|
229
|
-
[WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE]: {
|
|
230
|
-
requireApproval: true,
|
|
231
|
-
requireReadBeforeWrite: true,
|
|
232
|
-
},
|
|
233
|
-
[WORKSPACE_TOOLS.FILESYSTEM.DELETE]: {
|
|
234
|
-
enabled: false,
|
|
235
|
-
},
|
|
236
|
-
[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND]: {
|
|
237
|
-
requireApproval: true,
|
|
238
|
-
},
|
|
239
|
-
},
|
|
240
|
-
})
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
### Tool options
|
|
244
|
-
|
|
245
|
-
| Option | Type | Description |
|
|
246
|
-
| ------------------------ | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
247
|
-
| `enabled` | `boolean \| (context) => boolean` | Whether the tool is available (default: `true`). When a function, evaluated at tool-listing time. |
|
|
248
|
-
| `requireApproval` | `boolean \| (context) => boolean` | Whether the tool requires user approval before execution (default: `false`). When a function, evaluated at execution time with access to `args`. |
|
|
249
|
-
| `requireReadBeforeWrite` | `boolean \| (context) => boolean` | For write tools: require reading the file first (default: `false`). When a function, evaluated at execution time with access to `args`. |
|
|
250
|
-
| `name` | `string` | Custom name for the tool. Replaces the default `mastra_workspace_*` name. |
|
|
251
|
-
| `maxOutputTokens` | `number` | Maximum tokens for tool output (default: `2000`). Output exceeding this limit is truncated using tiktoken. |
|
|
252
|
-
|
|
253
|
-
### Dynamic tool configuration
|
|
254
|
-
|
|
255
|
-
Tool options that accept functions receive a context object and return a boolean. It enables context-aware tool behavior.
|
|
256
|
-
|
|
257
|
-
```typescript
|
|
258
|
-
const workspace = new Workspace({
|
|
259
|
-
filesystem: new LocalFilesystem({ basePath: './workspace' }),
|
|
260
|
-
tools: {
|
|
261
|
-
// Dynamic enabled: disable command execution unless explicitly allowed
|
|
262
|
-
[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND]: {
|
|
263
|
-
enabled: async ({ requestContext }) => {
|
|
264
|
-
return requestContext['allowExecution'] === 'true'
|
|
265
|
-
},
|
|
266
|
-
},
|
|
267
|
-
|
|
268
|
-
// Dynamic requireApproval: only require approval for protected paths
|
|
269
|
-
[WORKSPACE_TOOLS.FILESYSTEM.WRITE_FILE]: {
|
|
270
|
-
requireApproval: async ({ args }) => {
|
|
271
|
-
return (args.path as string).startsWith('/protected')
|
|
272
|
-
},
|
|
273
|
-
requireReadBeforeWrite: true,
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
})
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
Functions for `enabled` receive `{ requestContext, workspace }`. Functions for `requireApproval` and `requireReadBeforeWrite` also receive `args` since they're evaluated when the tool is called.
|
|
280
|
-
|
|
281
|
-
### Tool name remapping
|
|
282
|
-
|
|
283
|
-
Rename workspace tools to match the conventions your agent expects. The config key remains the original `WORKSPACE_TOOLS` constant, only the exposed name changes.
|
|
284
|
-
|
|
285
|
-
```typescript
|
|
286
|
-
import { Workspace, LocalFilesystem, LocalSandbox, WORKSPACE_TOOLS } from '@mastra/core/workspace'
|
|
287
|
-
|
|
288
|
-
const workspace = new Workspace({
|
|
289
|
-
filesystem: new LocalFilesystem({ basePath: './workspace' }),
|
|
290
|
-
sandbox: new LocalSandbox({ workingDirectory: './workspace' }),
|
|
291
|
-
lsp: true,
|
|
292
|
-
tools: {
|
|
293
|
-
[WORKSPACE_TOOLS.FILESYSTEM.READ_FILE]: { name: 'view' },
|
|
294
|
-
[WORKSPACE_TOOLS.FILESYSTEM.GREP]: { name: 'search_content' },
|
|
295
|
-
[WORKSPACE_TOOLS.FILESYSTEM.LIST_FILES]: { name: 'find_files' },
|
|
296
|
-
[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND]: { name: 'execute_command' },
|
|
297
|
-
[WORKSPACE_TOOLS.LSP.LSP_INSPECT]: { name: 'lsp_inspect' },
|
|
298
|
-
},
|
|
299
|
-
})
|
|
300
|
-
```
|
|
301
|
-
|
|
302
|
-
The agent sees `view`, `search_content`, `find_files`, `execute_command`, and `lsp_inspect` instead of the default `mastra_workspace_*` names. Tool names must be unique, duplicate names or conflicts with other default names throw an error.
|
|
303
|
-
|
|
304
|
-
### Tool hooks
|
|
305
|
-
|
|
306
|
-
Set `tools.hooks` to run logic before and after every enabled workspace tool call. Hooks run after name remapping, so the hook context includes both the exposed `toolName` and the original `workspaceToolName`:
|
|
307
|
-
|
|
308
|
-
```typescript
|
|
309
|
-
import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
|
|
310
|
-
|
|
311
|
-
const workspace = new Workspace({
|
|
312
|
-
filesystem: new LocalFilesystem({ basePath: './workspace' }),
|
|
313
|
-
tools: {
|
|
314
|
-
hooks: {
|
|
315
|
-
beforeToolCall: ({ toolName, workspaceToolName, input }) => {
|
|
316
|
-
console.log(`Running ${toolName} (${workspaceToolName})`, input)
|
|
317
|
-
},
|
|
318
|
-
afterToolCall: ({ toolName, output, error }) => {
|
|
319
|
-
console.log(`Finished ${toolName}`, { output, error })
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
},
|
|
323
|
-
})
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
Return `{ proceed: false, output }` from `beforeToolCall` to skip the tool call and use `output` as its result.
|
|
327
|
-
|
|
328
|
-
If the owning agent also defines [tool hooks](https://mastra.ai/docs/agents/using-tools), workspace hooks run inside the agent hook wrapper. The order is agent `beforeToolCall`, workspace `beforeToolCall`, the tool, workspace `afterToolCall`, and agent `afterToolCall`.
|
|
329
|
-
|
|
330
|
-
## LSP inspection
|
|
331
|
-
|
|
332
|
-
Enable `lsp` on a workspace to add semantic code inspection through language servers. This adds the `mastra_workspace_lsp_inspect` tool by default, which can return hover information and definition locations, plus implementations for a symbol at a specific cursor position.
|
|
333
|
-
|
|
334
|
-
See [LSP inspection](https://mastra.ai/docs/workspace/lsp) for configuration, examples, and tool name remapping.
|
|
335
|
-
|
|
336
|
-
### Output truncation
|
|
337
|
-
|
|
338
|
-
Workspace tools automatically truncate large outputs to avoid exceeding LLM context limits. These layers of truncation apply:
|
|
339
|
-
|
|
340
|
-
1. **Line-based tail**: Command output is limited to the last 200 lines by default (configurable per-command via the `tail` parameter)
|
|
341
|
-
2. **Token-based limit**: Tool output is capped at 2000 tokens by default
|
|
342
|
-
|
|
343
|
-
Set `maxOutputTokens` per tool to adjust the token limit:
|
|
344
|
-
|
|
345
|
-
```typescript
|
|
346
|
-
const workspace = new Workspace({
|
|
347
|
-
// ...
|
|
348
|
-
tools: {
|
|
349
|
-
[WORKSPACE_TOOLS.SANDBOX.EXECUTE_COMMAND]: {
|
|
350
|
-
maxOutputTokens: 5000,
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
})
|
|
354
|
-
```
|
|
355
|
-
|
|
356
|
-
ANSI escape codes (colors, cursor sequences) are automatically stripped from command output before it reaches the model.
|
|
357
|
-
|
|
358
|
-
### Read-before-write
|
|
359
|
-
|
|
360
|
-
When `requireReadBeforeWrite` is enabled on write tools, agents must read a file before writing to it. This prevents overwriting files the agent hasn't seen:
|
|
361
|
-
|
|
362
|
-
- **New files**: Can be written without reading (they don't exist yet)
|
|
363
|
-
- **Existing files**: Must be read first
|
|
364
|
-
- **Externally modified files**: If a file changed since the agent read it, the write fails
|
|
365
|
-
|
|
366
|
-
File write safety is enforced at two layers:
|
|
367
|
-
|
|
368
|
-
1. **Tool layer**: Before a write tool runs, the read tracker checks whether the file was modified since it was last read. If it was, the tool throws a `FileReadRequiredError`.
|
|
369
|
-
2. **Filesystem layer**: At write time, `writeFile()` compares the file's current modification time against the expected value (passed via `expectedMtime` in write options). If they don't match, it throws a `StaleFileError`. This catches external modifications (for example, an editor saving the file) that happen between the tool-level check and the actual write.
|
|
370
|
-
|
|
371
|
-
When `requireReadBeforeWrite` is enabled, workspace tools pass the recorded modification time through automatically. You can also use `expectedMtime` directly when calling `filesystem.writeFile()` outside of tools:
|
|
372
|
-
|
|
373
|
-
```typescript
|
|
374
|
-
const stat = await filesystem.stat('/docs/file.md')
|
|
375
|
-
// ... later ...
|
|
376
|
-
await filesystem.writeFile('/docs/file.md', newContent, {
|
|
377
|
-
expectedMtime: stat.modifiedAt,
|
|
378
|
-
})
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
## Initialization
|
|
382
|
-
|
|
383
|
-
Calling `init()` is optional in most cases, some providers initialize on first operation. Call `init()` manually when using a workspace outside of Mastra (standalone scripts, tests) or when you need to pre-provision resources before the first agent interaction.
|
|
384
|
-
|
|
385
|
-
```typescript
|
|
386
|
-
import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
|
|
387
|
-
|
|
388
|
-
const workspace = new Workspace({
|
|
389
|
-
filesystem: new LocalFilesystem({ basePath: './workspace' }),
|
|
390
|
-
sandbox: new LocalSandbox({ workingDirectory: './workspace' }),
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
// Optional: pre-create directories and sandbox before first use
|
|
394
|
-
await workspace.init()
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
### What `init()` does
|
|
398
|
-
|
|
399
|
-
Initialization runs setup logic for each configured provider:
|
|
400
|
-
|
|
401
|
-
- `LocalFilesystem`: Creates the base directory if it doesn't exist
|
|
402
|
-
- `LocalSandbox`: Creates the working directory
|
|
403
|
-
- `Search` (if configured): Indexes files from `autoIndexPaths`, see [Search and Indexing](https://mastra.ai/docs/workspace/search)
|
|
404
|
-
|
|
405
|
-
External providers may perform additional setup like establishing connections or authenticating.
|
|
406
|
-
|
|
407
|
-
## Related
|
|
408
|
-
|
|
409
|
-
- [Filesystem](https://mastra.ai/docs/workspace/filesystem)
|
|
410
|
-
- [Sandbox](https://mastra.ai/docs/workspace/sandbox)
|
|
411
|
-
- [LSP inspection](https://mastra.ai/docs/workspace/lsp)
|
|
412
|
-
- [Skills](https://mastra.ai/docs/workspace/skills)
|
|
413
|
-
- [Search and indexing](https://mastra.ai/docs/workspace/search)
|
|
414
|
-
- [Workspace class reference](https://mastra.ai/reference/workspace/workspace-class)
|
|
415
|
-
- 📹 [Introduction to Mastra Workspaces workshop](https://www.youtube.com/watch?v=QcQLiYlJuNQ)
|
|
416
|
-
- [Mastra Factory](https://factory.mastra.ai) and [Mastra Code](https://code.mastra.ai) are examples of workspace-powered coding agents
|