@mastra/mcp 1.15.1 → 1.16.0-alpha.0

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 (45) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/client/actions/elicitation.d.ts +1 -1
  3. package/dist/client/actions/elicitation.d.ts.map +1 -1
  4. package/dist/client/actions/progress.d.ts +1 -1
  5. package/dist/client/actions/progress.d.ts.map +1 -1
  6. package/dist/client/actions/prompt.d.ts +1 -1
  7. package/dist/client/actions/prompt.d.ts.map +1 -1
  8. package/dist/client/actions/resource.d.ts +38 -11
  9. package/dist/client/actions/resource.d.ts.map +1 -1
  10. package/dist/client/client.d.ts +3 -2
  11. package/dist/client/client.d.ts.map +1 -1
  12. package/dist/client/configuration.d.ts +50 -14
  13. package/dist/client/configuration.d.ts.map +1 -1
  14. package/dist/client/types.d.ts +65 -10
  15. package/dist/client/types.d.ts.map +1 -1
  16. package/dist/client/url-policy.d.ts +67 -0
  17. package/dist/client/url-policy.d.ts.map +1 -0
  18. package/dist/docs/SKILL.md +3 -3
  19. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  20. package/dist/docs/references/docs-connections-overview.md +94 -0
  21. package/dist/docs/references/docs-mcp-overview.md +229 -278
  22. package/dist/docs/references/reference-tools-mcp-client.md +54 -0
  23. package/dist/docs/references/reference-tools-mcp-server.md +1 -1
  24. package/dist/index.cjs +2435 -275
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.js +2403 -243
  27. package/dist/index.js.map +1 -1
  28. package/dist/server/__tests__/mock-extra.d.ts +15 -0
  29. package/dist/server/__tests__/mock-extra.d.ts.map +1 -0
  30. package/dist/server/notificationBroadcast.d.ts +1 -1
  31. package/dist/server/notificationBroadcast.d.ts.map +1 -1
  32. package/dist/server/promptActions.d.ts +1 -1
  33. package/dist/server/promptActions.d.ts.map +1 -1
  34. package/dist/server/resourceActions.d.ts +1 -1
  35. package/dist/server/resourceActions.d.ts.map +1 -1
  36. package/dist/server/server.d.ts +10 -12
  37. package/dist/server/server.d.ts.map +1 -1
  38. package/dist/server/toolActions.d.ts +1 -1
  39. package/dist/server/toolActions.d.ts.map +1 -1
  40. package/dist/server/types.d.ts +7 -7
  41. package/dist/server/types.d.ts.map +1 -1
  42. package/dist/shared/oauth-types.d.ts +8 -6
  43. package/dist/shared/oauth-types.d.ts.map +1 -1
  44. package/package.json +18 -14
  45. package/dist/docs/references/docs-mcp-mcp-apps.md +0 -306
@@ -37,6 +37,8 @@ Each server in the `servers` map is configured using the `MastraMCPServerDefinit
37
37
 
38
38
  **env** (`Record<string, string>`): For Stdio servers: Environment variables to set for the command.
39
39
 
40
+ **inheritDefaultEnv** (`boolean`): For Stdio servers: Whether the subprocess environment starts from the MCP SDK's default inherited environment. The default is a curated whitelist, not the full process environment: on POSIX it inherits HOME, LOGNAME, PATH, SHELL, TERM, and USER; on Windows it inherits APPDATA, HOMEDRIVE, HOMEPATH, LOCALAPPDATA, PATH, PROCESSOR\_ARCHITECTURE, SYSTEMDRIVE, SYSTEMROOT, TEMP, USERNAME, and USERPROFILE. When set to false, only the variables explicitly listed in env are passed to the subprocess. Note that a subprocess without PATH may fail to spawn commands that are not absolute paths. (Default: `true`)
41
+
40
42
  **url** (`URL`): For HTTP servers (Streamable HTTP or SSE): The URL of the server.
41
43
 
42
44
  **requestInit** (`RequestInit`): For HTTP servers: Request configuration for the fetch API.
@@ -45,6 +47,8 @@ Each server in the `servers` map is configured using the `MastraMCPServerDefinit
45
47
 
46
48
  **fetch** (`MastraFetchLike`): For HTTP servers: Custom fetch implementation used for all network requests. Receives an optional third requestContext parameter containing request-scoped data (e.g., authentication cookies, bearer tokens) from the incoming request. When provided, this function will be used for all HTTP requests, allowing you to add dynamic authentication headers, forward request-scoped credentials to the MCP server, customize request behavior per-request, or intercept and modify requests/responses. When fetch is provided, requestInit, eventSourceInit, and authProvider become optional, as you can handle these concerns within your custom fetch function.
47
49
 
50
+ **allowedHosts** (`string[]`): For HTTP servers: Opt-in allowlist of hosts the client may contact on behalf of this server. Each entry is matched against the URL host (hostname plus port when the URL carries a non-default port), for example "api.example.com" or "localhost:8080". Matching is exact and case-insensitive on the hostname; wildcards are not supported and the URL scheme is not checked. An empty array denies all requests. When unset, no restriction is applied. See the Security section below for enforcement details.
51
+
48
52
  **logger** (`LogHandler`): Optional additional handler for logging.
49
53
 
50
54
  **timeout** (`number`): Server-specific timeout in milliseconds.
@@ -159,6 +163,56 @@ When `forwardInstructions` is omitted (the default), instructions are still cach
159
163
 
160
164
  > **Security note:** server instructions are forwarded verbatim (subject only to length truncation) into the agent's system prompt. A malicious or compromised MCP server can use them to inject instructions the agent will treat as trusted system guidance. Only enable `forwardInstructions` for servers you trust, and prefer reviewing instructions with `getServerInstructions()` before forwarding instructions from third-party servers.
161
165
 
166
+ ## Security
167
+
168
+ ### Subprocess environment for Stdio servers
169
+
170
+ Stdio subprocesses don't inherit the full parent process environment. By default the subprocess environment starts from the MCP SDK's curated whitelist (POSIX: `HOME`, `LOGNAME`, `PATH`, `SHELL`, `TERM`, `USER`; Windows: `APPDATA`, `HOMEDRIVE`, `HOMEPATH`, `LOCALAPPDATA`, `PATH`, `PROCESSOR_ARCHITECTURE`, `SYSTEMDRIVE`, `SYSTEMROOT`, `TEMP`, `USERNAME`, `USERPROFILE`), merged with any variables you set in `env`. Sensitive variables such as API keys aren't inherited unless you pass them explicitly.
171
+
172
+ For stricter isolation, set `inheritDefaultEnv: false` so only your configured `env` entries reach the subprocess:
173
+
174
+ ```typescript
175
+ const mcp = new MCPClient({
176
+ servers: {
177
+ myTool: {
178
+ command: '/usr/local/bin/my-mcp-server',
179
+ inheritDefaultEnv: false,
180
+ env: { MY_TOOL_API_KEY: process.env.MY_TOOL_API_KEY! },
181
+ },
182
+ },
183
+ })
184
+ ```
185
+
186
+ Variables you place in `env` are forwarded verbatim, so treat server configurations that come from untrusted sources (for example, user-supplied config files) as untrusted input.
187
+
188
+ ### Restricting outbound hosts with `allowedHosts`
189
+
190
+ When HTTP server URLs come from untrusted configuration, an attacker-controlled URL can point the client at internal services (server-side request forgery). Set `allowedHosts` on such servers to restrict which hosts the client will contact:
191
+
192
+ ```typescript
193
+ const mcp = new MCPClient({
194
+ servers: {
195
+ remote: {
196
+ url: new URL(untrustedConfig.serverUrl),
197
+ allowedHosts: ['api.example.com'],
198
+ },
199
+ },
200
+ })
201
+ ```
202
+
203
+ Enforcement details:
204
+
205
+ - On the default fetch path, requests to disallowed hosts, including every redirect hop, are blocked **before** they're sent. Redirects are followed manually (up to 5 hops) so each hop is validated, and the `Authorization` header isn't carried across hops to a different origin (any scheme, host, or port change drops it, matching standard fetch behavior).
206
+ - When you supply a custom `fetch` (or a custom `eventSourceInit.fetch`), the initial URL is still checked before the request, but redirect hops are validated **after the fact** using `response.url`: the outbound hop may occur, and the response is discarded when its final URL points at a disallowed host. A hand-built `Response` with an empty `response.url` skips this post-hoc check.
207
+ - OAuth requests made through `authProvider` (authorization server metadata discovery, token exchange, refresh) are also validated. If your authorization server runs on a different host than the MCP server, add that host to `allowedHosts` too.
208
+ - A blocked host fails the connection with a clear error and is never retried by the reconnect logic.
209
+
210
+ `allowedHosts` is intentionally minimal: it matches exact hosts and doesn't support wildcards or scheme checks. If you need richer policy (scheme checks, IP-range rules), supply a custom `fetch` implementation, which is invoked for every request the client makes.
211
+
212
+ ### Treat tool responses as untrusted input
213
+
214
+ Tool results returned by MCP servers flow into your agent's context as model input. A malicious or compromised server can use tool output for prompt injection. The transport client doesn't sanitize tool responses: sanitization policy belongs at the agent layer, where Mastra's [input and output processors](https://mastra.ai/docs/agents/processors) let you inspect, transform, or block content before and after it reaches the model. Combine this with `requireToolApproval` and the `forwardInstructions` security note above when working with third-party servers.
215
+
162
216
  ## Methods
163
217
 
164
218
  ### `listTools()`
@@ -1660,7 +1660,7 @@ const server = new MCPServer({
1660
1660
  })
1661
1661
  ```
1662
1662
 
1663
- Link a tool to its app resource by setting `_meta.ui.resourceUri` on the tool to the matching `ui://` URI. The server auto-normalizes this metadata when registering tools. Visit [MCP Apps](https://mastra.ai/docs/mcp/mcp-apps) for the full app bridge API and usage patterns.
1663
+ Link a tool to its app resource by setting `_meta.ui.resourceUri` on the tool to the matching `ui://` URI. The server auto-normalizes this metadata when registering tools. Visit [MCP Apps](https://mastra.ai/docs/mcp/overview) for the full app bridge API and usage patterns.
1664
1664
 
1665
1665
  ## Related information
1666
1666