@mastra/mcp-docs-server 1.2.18-alpha.3 → 1.2.18-alpha.6
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/datasets/running-experiments.md +86 -1
- package/.docs/docs/mastra-platform/deploy.md +3 -1
- package/.docs/docs/mastra-platform/workspaces.md +6 -3
- package/.docs/docs/sandbox/filesystem.md +120 -139
- package/.docs/docs/sandbox/lsp.md +195 -143
- package/.docs/docs/sandbox/overview.md +103 -69
- package/.docs/docs/sandbox/search.md +172 -153
- package/.docs/docs/sandbox/skills.md +94 -151
- package/.docs/integrations/deploy/render.md +136 -89
- package/.docs/integrations/observability/arize.md +8 -6
- package/.docs/models/index.md +1 -1
- package/.docs/models/providers/edenai.md +2 -3
- package/.docs/models/providers/empiriolabs.md +1 -1
- package/.docs/models/providers/kilo.md +2 -2
- package/.docs/models/providers/llmgateway.md +2 -1
- package/.docs/models/providers/nano-gpt.md +3 -1
- package/.docs/models/providers/ofox.md +1 -1
- package/.docs/models/providers/opencode.md +65 -65
- package/.docs/reference/cli/mastra.md +2 -2
- package/.docs/reference/client-js/datasets.md +146 -0
- package/.docs/reference/configuration.md +58 -0
- package/.docs/reference/datasets/createExperiment.md +76 -0
- package/.docs/reference/datasets/finalizeExperiment.md +43 -0
- package/.docs/reference/datasets/runExperimentItem.md +55 -0
- package/.docs/reference/datasets/submitExperimentResult.md +56 -0
- package/.docs/reference/index.md +5 -0
- package/.docs/reference/observability/tracing/exporters/langfuse.md +2 -0
- package/.docs/reference/pubsub/redis-streams.md +11 -1
- package/.docs/reference/rag/metadata-filters.md +16 -8
- package/.docs/reference/rag/retrieval.md +113 -5
- package/.docs/reference/server/routes.md +111 -0
- package/CHANGELOG.md +14 -0
- package/package.json +3 -3
|
@@ -2,215 +2,267 @@
|
|
|
2
2
|
|
|
3
3
|
# LSP inspection
|
|
4
4
|
|
|
5
|
-
LSP inspection gives
|
|
5
|
+
Language Server Protocol (LSP) inspection gives agents semantic information about project code. A language server can identify a symbol's type, declaration, implementations, and diagnostics because it understands the language and project structure.
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## What LSP adds
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
File and search tools answer different questions about a codebase:
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
| Tool | Best for |
|
|
12
|
+
| ----------------------------------------------- | --------------------------------------------------------------------- |
|
|
13
|
+
| `read_file` | Reading the exact contents and surrounding context of a known file |
|
|
14
|
+
| `grep` | Finding text or regular-expression matches across files |
|
|
15
|
+
| [Search](https://mastra.ai/docs/sandbox/search) | Retrieving indexed files by keyword or semantic similarity |
|
|
16
|
+
| LSP inspection | Getting type-aware information and following symbols across a project |
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
LSP inspection complements these tools rather than replacing them. An agent can use `grep` to find a symbol and inspect it through LSP to locate its declaration. It can then use `read_file` to read the full implementation before making a change.
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
## Set up LSP
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
|
|
22
|
+
LSP starts a long-running language-server process and exchanges JSON-RPC messages with it. Before enabling LSP, ensure your configuration includes:
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
- A static [sandbox](https://mastra.ai/docs/sandbox/overview) with a process manager whose process handles provide readable output and writable input streams. Sandbox resolvers aren't supported.
|
|
25
|
+
- The `vscode-jsonrpc` and `vscode-languageserver-protocol` packages installed in the Mastra application.
|
|
26
|
+
- A language-server binary and its runtime installed where the sandbox process runs.
|
|
27
|
+
- An absolute project root and project files available through matching paths to both the Mastra application and the sandbox process.
|
|
28
|
+
|
|
29
|
+
Mastra has built-in server definitions for TypeScript and JavaScript, Python, Go, and Rust. The matching language-server binary must still be installed. You can [register another server](#custom-language-servers) for other file types.
|
|
30
|
+
|
|
31
|
+
Install the shared protocol packages:
|
|
32
|
+
|
|
33
|
+
**npm**:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install vscode-jsonrpc vscode-languageserver-protocol
|
|
29
37
|
```
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
**pnpm**:
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
```bash
|
|
42
|
+
pnpm add vscode-jsonrpc vscode-languageserver-protocol
|
|
43
|
+
```
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
**Yarn**:
|
|
36
46
|
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
"path": "/absolute/path/to/file.ts",
|
|
40
|
-
"line": 10,
|
|
41
|
-
"match": "const foo = <<<bar()"
|
|
42
|
-
}
|
|
47
|
+
```bash
|
|
48
|
+
yarn add vscode-jsonrpc vscode-languageserver-protocol
|
|
43
49
|
```
|
|
44
50
|
|
|
45
|
-
|
|
51
|
+
**Bun**:
|
|
46
52
|
|
|
47
|
-
|
|
53
|
+
```bash
|
|
54
|
+
bun add vscode-jsonrpc vscode-languageserver-protocol
|
|
55
|
+
```
|
|
48
56
|
|
|
49
|
-
|
|
50
|
-
| ---------------- | ---------------------------------------------------------------- |
|
|
51
|
-
| `hover` | Type information or documentation for the symbol at the cursor |
|
|
52
|
-
| `diagnostics` | Line-scoped LSP diagnostics for the inspected line, when present |
|
|
53
|
-
| `definition` | Declaration locations with a one-line preview |
|
|
54
|
-
| `implementation` | Implementation or usage locations |
|
|
57
|
+
Then install a language server for your project. For example, install TypeScript and its language server:
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
**npm**:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npm install typescript typescript-language-server
|
|
63
|
+
```
|
|
57
64
|
|
|
58
|
-
|
|
65
|
+
**pnpm**:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pnpm add typescript typescript-language-server
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Yarn**:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
yarn add typescript typescript-language-server
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Bun**:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
bun add typescript typescript-language-server
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Create a static `LocalSandbox` and point the filesystem, sandbox, and LSP root at the same directory:
|
|
59
84
|
|
|
60
85
|
```typescript
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
86
|
+
import { resolve } from 'node:path'
|
|
87
|
+
import { LocalFilesystem, LocalSandbox, Workspace } from '@mastra/core/workspace'
|
|
88
|
+
|
|
89
|
+
const projectPath = resolve('./workspace')
|
|
90
|
+
|
|
91
|
+
export const workspace = new Workspace({
|
|
92
|
+
filesystem: new LocalFilesystem({
|
|
93
|
+
basePath: projectPath,
|
|
94
|
+
}),
|
|
95
|
+
sandbox: new LocalSandbox({
|
|
96
|
+
workingDirectory: projectPath,
|
|
97
|
+
}),
|
|
98
|
+
lsp: {
|
|
99
|
+
root: projectPath,
|
|
70
100
|
},
|
|
71
101
|
})
|
|
72
102
|
```
|
|
73
103
|
|
|
74
|
-
|
|
104
|
+
The filesystem gives the agent file tools for the project. The sandbox starts the language server in the same directory when an LSP query first needs it. If any required protocol package, process manager, or server binary is unavailable, Mastra disables LSP or returns that no language server is available.
|
|
75
105
|
|
|
76
|
-
|
|
106
|
+
## Inspect code with the agent tool
|
|
77
107
|
|
|
78
|
-
|
|
108
|
+
When LSP is enabled, the agent receives `mastra_workspace_lsp_inspect`. Its input identifies a file and places a cursor on one symbol:
|
|
79
109
|
|
|
80
|
-
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"path": "/absolute/path/to/workspace/src/orders.ts",
|
|
113
|
+
"line": 10,
|
|
114
|
+
"match": "const order = await <<<findOrder(orderId)"
|
|
115
|
+
}
|
|
116
|
+
```
|
|
81
117
|
|
|
82
|
-
|
|
83
|
-
import { Workspace, LocalFilesystem } from '@mastra/core/workspace'
|
|
118
|
+
`line` is 1-indexed. Copy the content of that line into `match`, then insert exactly one `<<<` marker immediately before the symbol to inspect. The marker isn't part of the source file.
|
|
84
119
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
120
|
+
The tool returns the fields that the language server can provide:
|
|
121
|
+
|
|
122
|
+
| Field | Output |
|
|
123
|
+
| ---------------- | ----------------------------------------------------------------------- |
|
|
124
|
+
| `hover` | Type information or documentation, with its markup kind |
|
|
125
|
+
| `diagnostics` | Severity, message, and source for diagnostics on the inspected line |
|
|
126
|
+
| `definition` | Declaration locations with a one-line preview when the file is readable |
|
|
127
|
+
| `implementation` | Implementation locations |
|
|
128
|
+
| `error` | A setup, server, or query error when inspection can't run |
|
|
129
|
+
|
|
130
|
+
Unavailable result fields are omitted. Definition and implementation locations identify where to continue with `read_file` for full context.
|
|
131
|
+
|
|
132
|
+
## Configure LSP
|
|
133
|
+
|
|
134
|
+
Set `lsp: true` to use the defaults. Replace it with an object when you need to control the root, server discovery, timeouts, or retained clients:
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
lsp: {
|
|
138
|
+
root: projectPath,
|
|
139
|
+
diagnosticTimeout: 4_000,
|
|
140
|
+
initTimeout: 8_000,
|
|
141
|
+
maxOpenClients: 4,
|
|
142
|
+
disableServers: ['eslint'],
|
|
143
|
+
binaryOverrides: {
|
|
144
|
+
typescript: '/opt/mastra-tools/typescript-language-server --stdio',
|
|
96
145
|
},
|
|
97
|
-
|
|
146
|
+
searchPaths: ['/opt/mastra-tools'],
|
|
147
|
+
},
|
|
98
148
|
```
|
|
99
149
|
|
|
100
|
-
|
|
150
|
+
`binaryOverrides` maps a built-in server ID to its full startup command. `searchPaths` adds package roots whose `node_modules` may contain binaries or required modules. You can also set `packageRunner`, such as `pnpm dlx`, as a last-resort fallback. Package-runner fallback is disabled by default because it may install software or hang in some project layouts.
|
|
101
151
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
-
|
|
105
|
-
- Point Mastra at custom language server binaries
|
|
106
|
-
- Add extra binary search paths in constrained environments
|
|
152
|
+
`diagnosticTimeout` controls how long the direct `getDiagnostics()` and `getDiagnosticsMulti()` APIs wait for diagnostics. The agent inspection tool currently waits up to five seconds.
|
|
153
|
+
|
|
154
|
+
Mastra normally finds a project root for each file by walking upward for that server's project markers. It falls back to `lsp.root` when it finds no marker. See the [LSP configuration reference](https://mastra.ai/reference/workspace/workspace-class) for all options and defaults.
|
|
107
155
|
|
|
108
156
|
### Limit retained clients
|
|
109
157
|
|
|
110
|
-
|
|
158
|
+
`maxOpenClients` limits the language-server clients retained for one configuration. It must be a positive integer. When the limit is reached, Mastra closes the least recently used client that has no active query lease.
|
|
111
159
|
|
|
112
|
-
|
|
160
|
+
If every retained client has an active lease, the next acquisition waits up to five seconds for a lease to be released. If none becomes available, `prepareQuery()` and `getDiagnostics()` return `null`. `getDiagnosticsMulti()` omits a server it couldn't acquire. Omitting `maxOpenClients` leaves the number of retained clients unlimited. Mastra Code uses a default limit of `4`.
|
|
113
161
|
|
|
114
|
-
###
|
|
162
|
+
### Tool name remapping
|
|
115
163
|
|
|
116
|
-
|
|
164
|
+
Configure the agent inspection tool through `tools`. For example, add this entry to expose a shorter name:
|
|
117
165
|
|
|
118
166
|
```typescript
|
|
119
|
-
|
|
167
|
+
import { WORKSPACE_TOOLS } from '@mastra/core/workspace'
|
|
120
168
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
query.client.notifyClose(filePath)
|
|
126
|
-
query.release()
|
|
127
|
-
}
|
|
169
|
+
const tools = {
|
|
170
|
+
[WORKSPACE_TOOLS.LSP.LSP_INSPECT]: {
|
|
171
|
+
name: 'lsp_inspect',
|
|
172
|
+
},
|
|
128
173
|
}
|
|
129
174
|
```
|
|
130
175
|
|
|
131
|
-
|
|
176
|
+
Add `tools` alongside `lsp` in the configuration. The `name` changes the exposed tool name, but the configuration key remains `WORKSPACE_TOOLS.LSP.LSP_INSPECT`. Set `enabled: false` on the same entry to remove the tool.
|
|
177
|
+
|
|
178
|
+
See the [tool configuration reference](https://mastra.ai/reference/workspace/workspace-class) for approval settings, dynamic policies, output limits, and hooks shared by generated agent tools.
|
|
132
179
|
|
|
133
180
|
## Custom language servers
|
|
134
181
|
|
|
135
|
-
|
|
182
|
+
Add a server under `lsp.servers` when a language isn't built in or when you need to replace a built-in definition:
|
|
136
183
|
|
|
137
184
|
```typescript
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
markers: ['composer.json'],
|
|
151
|
-
command: 'phpactor language-server',
|
|
185
|
+
lsp: {
|
|
186
|
+
root: projectPath,
|
|
187
|
+
servers: {
|
|
188
|
+
phpactor: {
|
|
189
|
+
id: 'phpactor',
|
|
190
|
+
name: 'Phpactor Language Server',
|
|
191
|
+
languageIds: ['php'],
|
|
192
|
+
extensions: ['.php'],
|
|
193
|
+
markers: ['composer.json'],
|
|
194
|
+
command: 'phpactor language-server',
|
|
195
|
+
initializationOptions: {
|
|
196
|
+
indexer: { enabled: true },
|
|
152
197
|
},
|
|
153
198
|
},
|
|
154
199
|
},
|
|
155
|
-
}
|
|
200
|
+
},
|
|
156
201
|
```
|
|
157
202
|
|
|
158
|
-
Each
|
|
203
|
+
Each definition supports these fields:
|
|
159
204
|
|
|
160
|
-
| Field
|
|
161
|
-
|
|
|
162
|
-
| `id`
|
|
163
|
-
| `name`
|
|
164
|
-
| `languageIds` |
|
|
165
|
-
| `extensions`
|
|
166
|
-
| `markers`
|
|
167
|
-
| `command`
|
|
205
|
+
| Field | Required | Description |
|
|
206
|
+
| ----------------------- | -------- | --------------------------------------------------------------- |
|
|
207
|
+
| `id` | Yes | Unique server ID. Use a built-in ID to replace that definition. |
|
|
208
|
+
| `name` | Yes | Human-readable name used in logs and errors. |
|
|
209
|
+
| `languageIds` | Yes | LSP language identifiers handled by the server. |
|
|
210
|
+
| `extensions` | Yes | File extensions handled by the server, including the dot. |
|
|
211
|
+
| `markers` | Yes | Files or directories used to find the project root. |
|
|
212
|
+
| `command` | Yes | Full command that starts the server. |
|
|
213
|
+
| `initializationOptions` | No | Settings sent during the LSP initialization handshake. |
|
|
168
214
|
|
|
169
|
-
When a server
|
|
215
|
+
Custom definitions are merged with the built-in definitions. A custom definition with the same `id` replaces the built-in one. When a server lists multiple language IDs, Mastra maps each configured extension to the first ID.
|
|
170
216
|
|
|
171
|
-
|
|
217
|
+
## Query LSP directly
|
|
172
218
|
|
|
173
|
-
|
|
219
|
+
Application code can query the configured LSP manager directly. `getDiagnostics()` and `getDiagnosticsMulti()` manage their client leases and document open and close notifications internally.
|
|
220
|
+
|
|
221
|
+
`prepareQuery()` exposes the client for hover, definition, implementation, and other direct queries. Pass it an absolute file path. It opens the file and returns a lease. Close the file before releasing that lease, and put both calls in a `finally` block:
|
|
174
222
|
|
|
175
223
|
```typescript
|
|
176
|
-
|
|
224
|
+
async function inspectHover(filePath: string, line: number, character: number) {
|
|
225
|
+
const query = await workspace.lsp?.prepareQuery(filePath)
|
|
226
|
+
if (!query) return null
|
|
177
227
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
markers: ['composer.json'],
|
|
189
|
-
command: 'phpactor language-server',
|
|
190
|
-
},
|
|
191
|
-
solargraph: {
|
|
192
|
-
id: 'solargraph',
|
|
193
|
-
name: 'Solargraph',
|
|
194
|
-
languageIds: ['ruby'],
|
|
195
|
-
extensions: ['.rb', '.erb'],
|
|
196
|
-
markers: ['Gemfile'],
|
|
197
|
-
command: 'solargraph stdio',
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
})
|
|
228
|
+
try {
|
|
229
|
+
return await query.client.queryHover(query.uri, {
|
|
230
|
+
line,
|
|
231
|
+
character,
|
|
232
|
+
})
|
|
233
|
+
} finally {
|
|
234
|
+
query.client.notifyClose(filePath)
|
|
235
|
+
query.release()
|
|
236
|
+
}
|
|
237
|
+
}
|
|
202
238
|
```
|
|
203
239
|
|
|
204
|
-
|
|
240
|
+
Direct client positions are 0-indexed. A leaked lease can prevent an idle client from being evicted when `maxOpenClients` is set. During teardown, Mastra waits up to five seconds for active leases before forcing the language servers to shut down. Managed LSP clients close before the sandbox is destroyed.
|
|
241
|
+
|
|
242
|
+
## Limitations
|
|
243
|
+
|
|
244
|
+
- LSP only works for file types with a matching built-in or custom server.
|
|
245
|
+
- A filesystem alone can't run a language server. LSP requires a static sandbox with a bidirectional process manager.
|
|
246
|
+
- `LocalFilesystem` containment and `allowedPaths` don't constrain LSP inspection. Restrict `lsp.root` to a trusted project, and don't expose the LSP tool when users can submit untrusted host paths.
|
|
247
|
+
- External package inspection may resolve to declaration files such as `.d.ts` instead of runtime source.
|
|
248
|
+
- Language servers may omit hover, diagnostic, definition, or implementation results that they don't support.
|
|
249
|
+
|
|
250
|
+
### Remote sandboxes
|
|
251
|
+
|
|
252
|
+
Remote LSP isn't backend-transparent. The language-server command runs through the remote sandbox process manager, but binary discovery, file reads, and some source previews still use the Mastra host.
|
|
253
|
+
|
|
254
|
+
Use remote LSP only when all of these conditions are met:
|
|
255
|
+
|
|
256
|
+
- The remote process manager provides readable output and writable input streams.
|
|
257
|
+
- The project uses matching absolute paths on the Mastra host and in the remote sandbox.
|
|
258
|
+
- The resolved server command is installed in the remote image. Configure it with `binaryOverrides` for a built-in server or `lsp.servers.command` for a custom server.
|
|
259
|
+
- The host can read files needed for inspection and definition previews.
|
|
205
260
|
|
|
206
|
-
|
|
207
|
-
- The `path` you inspect must resolve inside the workspace filesystem or allowed paths
|
|
208
|
-
- External package inspection may resolve to declaration files such as `.d.ts` instead of runtime source files
|
|
209
|
-
- `lsp_inspect` complements `view` and `search_content`, but doesn't replace reading implementation code when you need full context
|
|
261
|
+
A local filesystem and remote sandbox don't synchronize automatically. A binary installed only on the host can't run in the remote sandbox, and remote-only files can't provide all host-side results. For remote-only projects, use `grep`, indexed [search](https://mastra.ai/docs/sandbox/search), and sandbox commands until LSP file access is backend-transparent.
|
|
210
262
|
|
|
211
263
|
## Related
|
|
212
264
|
|
|
213
265
|
- [Filesystem](https://mastra.ai/docs/sandbox/filesystem)
|
|
214
|
-
- [
|
|
215
|
-
- [Search
|
|
216
|
-
- [
|
|
266
|
+
- [Sandboxes](https://mastra.ai/docs/sandbox/overview)
|
|
267
|
+
- [Search](https://mastra.ai/docs/sandbox/search)
|
|
268
|
+
- [Configuration reference](https://mastra.ai/reference/workspace/workspace-class)
|