@mastra/mcp-docs-server 1.2.18-alpha.1 → 1.2.18-alpha.5

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.
Files changed (36) hide show
  1. package/.docs/docs/mastra-platform/workspaces.md +6 -3
  2. package/.docs/docs/sandbox/filesystem.md +120 -139
  3. package/.docs/docs/sandbox/lsp.md +195 -143
  4. package/.docs/docs/sandbox/overview.md +103 -69
  5. package/.docs/docs/sandbox/search.md +172 -153
  6. package/.docs/docs/sandbox/skills.md +94 -151
  7. package/.docs/integrations/agentic-ui/ai-sdk-ui.md +2 -1
  8. package/.docs/integrations/deploy/render.md +136 -89
  9. package/.docs/integrations/frameworks/next-js.md +3 -2
  10. package/.docs/models/gateways/netlify.md +227 -70
  11. package/.docs/models/gateways/openrouter.md +3 -4
  12. package/.docs/models/gateways/vercel.md +5 -3
  13. package/.docs/models/index.md +1 -1
  14. package/.docs/models/providers/crossmodel.md +3 -2
  15. package/.docs/models/providers/edenai.md +4 -7
  16. package/.docs/models/providers/empiriolabs.md +3 -2
  17. package/.docs/models/providers/huggingface.md +2 -1
  18. package/.docs/models/providers/hyper.md +9 -9
  19. package/.docs/models/providers/inceptron.md +4 -5
  20. package/.docs/models/providers/kilo.md +10 -11
  21. package/.docs/models/providers/llmgateway.md +4 -3
  22. package/.docs/models/providers/nano-gpt.md +3 -1
  23. package/.docs/models/providers/ofox.md +5 -5
  24. package/.docs/models/providers/opencode-go.md +1 -1
  25. package/.docs/models/providers/opencode.md +65 -65
  26. package/.docs/models/providers/pioneer.md +12 -12
  27. package/.docs/models/providers/runinfra.md +2 -1
  28. package/.docs/models/providers/umans-ai-coding-plan.md +1 -2
  29. package/.docs/models/providers/umans-ai.md +1 -2
  30. package/.docs/reference/agent-controller/agent-controller-class.md +1 -1
  31. package/.docs/reference/ai-sdk/handle-chat-stream.md +2 -1
  32. package/.docs/reference/observability/tracing/exporters/langfuse.md +2 -0
  33. package/.docs/reference/rag/metadata-filters.md +16 -8
  34. package/.docs/reference/rag/retrieval.md +113 -5
  35. package/CHANGELOG.md +14 -0
  36. package/package.json +5 -5
@@ -2,215 +2,267 @@
2
2
 
3
3
  # LSP inspection
4
4
 
5
- LSP inspection gives workspace-backed agents semantic code intelligence. When you enable LSP on a workspace, agents can inspect symbols in supported files to retrieve hover information and jump to definitions. They can also find implementations.
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
- ## When to use LSP inspection
7
+ ## What LSP adds
8
8
 
9
- Use LSP inspection when your agent needs semantic code understanding instead of plain-text search alone:
9
+ File and search tools answer different questions about a codebase:
10
10
 
11
- - Inspect symbols and their inferred types in any supported language
12
- - Find where a symbol is declared before editing related code
13
- - Explore implementations across a codebase without manually tracing every file
14
- - Combine semantic inspection with `view` and `search_content` for faster navigation
15
- - Add LSP support for additional languages by [registering custom language servers](#custom-language-servers)
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
- ## Quickstart
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
- Enable LSP on a workspace by setting `lsp: true`:
20
+ ## Set up LSP
20
21
 
21
- ```typescript
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
- const workspace = new Workspace({
25
- filesystem: new LocalFilesystem({ basePath: './workspace' }),
26
- sandbox: new LocalSandbox({ workingDirectory: './workspace' }),
27
- lsp: true,
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
- With this configuration, the workspace registers the default LSP inspection tool alongside the configured filesystem and sandbox tools.
39
+ **pnpm**:
32
40
 
33
- ## Agent tool
41
+ ```bash
42
+ pnpm add vscode-jsonrpc vscode-languageserver-protocol
43
+ ```
34
44
 
35
- When LSP is enabled, the workspace exposes `mastra_workspace_lsp_inspect` by default.
45
+ **Yarn**:
36
46
 
37
- ```json
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
- The `match` field must include exactly one `<<<` cursor marker. The marker identifies the symbol position on the specified line.
51
+ **Bun**:
46
52
 
47
- The tool returns up to three result groups:
53
+ ```bash
54
+ bun add vscode-jsonrpc vscode-languageserver-protocol
55
+ ```
48
56
 
49
- | Result | Description |
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
- ## Tool name remapping
59
+ **npm**:
60
+
61
+ ```bash
62
+ npm install typescript typescript-language-server
63
+ ```
57
64
 
58
- Use `WORKSPACE_TOOLS.LSP.LSP_INSPECT` to configure the inspection tool. Set `enabled: false` to remove it from the agent's toolset, or set `name` if the agent expects a different name:
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 { Workspace, LocalFilesystem, WORKSPACE_TOOLS } from '@mastra/core/workspace'
62
-
63
- const workspace = new Workspace({
64
- filesystem: new LocalFilesystem({ basePath: './workspace' }),
65
- lsp: true,
66
- tools: {
67
- [WORKSPACE_TOOLS.LSP.LSP_INSPECT]: {
68
- name: 'lsp_inspect',
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
- This changes the exposed tool name only. The configuration key stays `WORKSPACE_TOOLS.LSP.LSP_INSPECT`.
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
- See [`WorkspaceToolsConfig`](https://mastra.ai/reference/workspace/workspace-class) for approval settings, dynamic policies, output limits, and hooks shared by workspace tools.
106
+ ## Inspect code with the agent tool
77
107
 
78
- ## LSP configuration
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
- Set `lsp` to `true` for default behavior, or provide an object to customize server startup and diagnostics:
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
- ```typescript
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
- const workspace = new Workspace({
86
- filesystem: new LocalFilesystem({ basePath: './workspace' }),
87
- lsp: {
88
- diagnosticTimeout: 4000,
89
- initTimeout: 8000,
90
- maxOpenClients: 4,
91
- disableServers: ['eslint'],
92
- binaryOverrides: {
93
- typescript: '/custom/path/to/typescript-language-server --stdio',
94
- },
95
- searchPaths: ['/opt/homebrew/bin'],
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
- Use custom configuration when you need to:
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
- - Increase timeouts for large repositories
103
- - Limit retained language server processes
104
- - Disable specific language servers
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
- Set `maxOpenClients` to a positive integer to limit the language server clients retained by a workspace. When the limit is reached, the workspace closes the least recently used client that has no active query lease. If every retained client is active, the next acquisition waits up to five seconds for a lease to be released. If no lease becomes available, `prepareQuery()` and `getDiagnostics()` return `null`, while `getDiagnosticsMulti()` omits the unavailable server.
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
- Workspaces retain an unlimited number of clients when `maxOpenClients` is omitted. Mastra Code sets `maxOpenClients` to `4` by default.
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
- ### Release prepared queries
162
+ ### Tool name remapping
115
163
 
116
- When you call `prepareQuery()` directly, close the file before releasing the client lease. Use a `finally` block so the client can be evicted even if the query fails:
164
+ Configure the agent inspection tool through `tools`. For example, add this entry to expose a shorter name:
117
165
 
118
166
  ```typescript
119
- const query = await workspace.lsp?.prepareQuery(filePath)
167
+ import { WORKSPACE_TOOLS } from '@mastra/core/workspace'
120
168
 
121
- if (query) {
122
- try {
123
- const hover = await query.client.queryHover(query.uri, position)
124
- } finally {
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
- During workspace teardown, Mastra waits up to five seconds for active leases to be released before it forces language server shutdown.
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
- By default, Mastra includes built-in support for TypeScript, JavaScript, Python, Go, and Rust. To use LSP inspection with other languages (e.g. PHP, Ruby, Java, Kotlin, Swift, Elixir), register a custom language server via the `servers` field:
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
- import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
139
-
140
- const workspace = new Workspace({
141
- filesystem: new LocalFilesystem({ basePath: './workspace' }),
142
- sandbox: new LocalSandbox({ workingDirectory: './workspace' }),
143
- lsp: {
144
- servers: {
145
- phpactor: {
146
- id: 'phpactor',
147
- name: 'Phpactor Language Server',
148
- languageIds: ['php'],
149
- extensions: ['.php'],
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 custom server definition requires these fields:
203
+ Each definition supports these fields:
159
204
 
160
- | Field | Description |
161
- | ------------- | ------------------------------------------------------------------------------------- |
162
- | `id` | Unique identifier for the server |
163
- | `name` | Human-readable name shown in logs |
164
- | `languageIds` | Language Server Protocol (LSP) language identifiers this server handles |
165
- | `extensions` | File extensions, including the dot |
166
- | `markers` | Files or directories that identify the project root (e.g. `composer.json`, `Gemfile`) |
167
- | `command` | Full command string to start the server |
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 has multiple language IDs, Mastra maps each extension to the first entry in `languageIds`.
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
- You can also pass optional `initializationOptions` to send custom settings during the LSP handshake.
217
+ ## Query LSP directly
172
218
 
173
- Custom servers are merged with built-in servers. To replace a built-in server, use the same `id` (e.g. `id: 'go'` replaces the built-in Go server). Register multiple servers to support several languages at once:
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
- import { Workspace, LocalFilesystem, LocalSandbox } from '@mastra/core/workspace'
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
- const workspace = new Workspace({
179
- filesystem: new LocalFilesystem({ basePath: './workspace' }),
180
- sandbox: new LocalSandbox({ workingDirectory: './workspace' }),
181
- lsp: {
182
- servers: {
183
- phpactor: {
184
- id: 'phpactor',
185
- name: 'Phpactor Language Server',
186
- languageIds: ['php'],
187
- extensions: ['.php'],
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
- ## Requirements and limitations
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
- - LSP inspection only works for file types with a matching built-in or custom language server
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
- - [Sandbox](https://mastra.ai/docs/sandbox/overview)
215
- - [Search and indexing](https://mastra.ai/docs/sandbox/search)
216
- - [Workspace class reference](https://mastra.ai/reference/workspace/workspace-class)
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)