mirror of
https://github.com/mastra-ai/mastra.git
synced 2026-11-17 08:44:46 +00:00
857 commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
d60ba71be0 | chore: version - exit prerelease mode | ||
|
|
5c87442ed7 |
chore: version packages (alpha) (#30203)
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. ⚠️⚠️⚠️⚠️⚠️⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`. ⚠️⚠️⚠️⚠️⚠️⚠️ # Releases > The changelog information of each package has been omitted from this message, as the content exceeds the size limit. ## @mastra/auth-auth0@1.3.0-alpha.0 ## @mastra/auth-clerk@1.4.0-alpha.0 ## @mastra/auth-okta@0.3.0-alpha.0 ## @mastra/auth-supabase@1.2.0-alpha.0 ## @mastra/client-js@1.60.0-alpha.13 ## @mastra/auth@1.2.0-alpha.0 ## @mastra/core@1.83.0-alpha.13 ## @mastra/playground-ui@69.0.0-alpha.15 ## @mastra/rag@2.8.0-alpha.3 ## @mastra/server@1.83.0-alpha.13 ## @mastra/server-adapters-test-suite@0.3.0-alpha.5 ## @mastra/auth-better-auth@1.1.11-alpha.2 ## @mastra/auth-cloud@1.2.9-alpha.0 ## @mastra/auth-neon@0.3.6-alpha.1 ## @mastra/auth-workos@1.6.9-alpha.0 ## @mastra/discord@1.3.4-alpha.0 ## @mastra/react@1.15.0-alpha.13 ## @mastra/deployer-cloud@1.83.0-alpha.13 ## @mastra/deployer-cloudflare@1.2.42-alpha.3 ## @mastra/deployer-netlify@1.2.42-alpha.1 ## @mastra/deployer-sandbox@0.3.27-alpha.1 ## @mastra/deployer-vercel@1.2.42-alpha.1 ## @mastra/longmemeval@1.1.42-alpha.13 ## @mastra/opencode@0.1.42-alpha.13 ## @mastra/factory@0.28.0-alpha.15 ## create-factory@0.4.3-alpha.15 ## @mastra/code-sdk@1.19.0-alpha.15 ## mastracode@0.50.0-alpha.14 ## @mastra/agent-builder@1.2.1-alpha.5 ## mastra@1.39.0-alpha.15 ## @mastra/connect@1.4.0-alpha.6 ## @mastra/deployer@1.83.0-alpha.13 ## @mastra/editor@0.17.1-alpha.7 ## @mastra/mcp@2.9.0-alpha.5 ## @mastra/mcp-docs-server@1.3.13-alpha.17 ## @mastra/memory@1.41.1-alpha.5 ## @mastra/schema-compat@1.4.0-alpha.2 ## @mastra/elysia@0.1.23-alpha.13 ## @mastra/express@1.5.27-alpha.13 ## @mastra/fastify@1.5.27-alpha.13 ## @mastra/hono@1.7.25-alpha.13 ## @mastra/koa@1.7.27-alpha.13 ## @mastra/nestjs@0.3.0-alpha.13 ## @mastra/next@0.2.41-alpha.13 ## @mastra/tanstack-start@0.2.41-alpha.13 ## @mastra/voice-google-gemini-live@0.14.19-alpha.2 ## @mastra/voice-openai-realtime@0.14.9-alpha.3 ## @mastra/voice-xai-realtime@0.2.18-alpha.2 ## @mastra/inngest@1.11.2-alpha.9 ## @mastra/temporal@0.6.0-alpha.13 ## create-mastra@1.39.0-alpha.15 ## @internal/playground@1.39.0-alpha.15 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
392c7b69d5 |
feat(server): built-in MCP endpoint for agents, workflows and tools (#29929)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
055a8c3b82 | chore: version packages | ||
|
|
2d4284603a |
Fix MCP core compatibility, Windows browser paths, and AI SDK tool titles (#30125) | ||
|
|
056d35d943 |
Enforce JSON Schema formats in MCP tool validation (#30113) | ||
|
|
c22107fce3 |
chore(deps): update dependency @ai-sdk/provider-utils@>=3.0.0 <3.0.38 to v3.0.45 (#29844) | ||
|
|
5c0f12c5a2 |
ci(mcp): fix MCP compatibility job on version-packages PRs (#29988)
Co-authored-by: YJ <yj@example.com> Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
23cc34a9c5 |
chore: version packages (alpha) (#29938)
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. ⚠️⚠️⚠️⚠️⚠️⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`. ⚠️⚠️⚠️⚠️⚠️⚠️ # Releases > The changelog information of each package has been omitted from this message, as the content exceeds the size limit. ## @mastra/factory@0.28.0-alpha.6 ## @mastra/code-sdk@1.19.0-alpha.6 ## @mastra/playground-ui@69.0.0-alpha.7 ## @mastra/client-js@1.60.0-alpha.6 ## @mastra/react@1.15.0-alpha.6 ## @mastra/deployer-cloud@1.83.0-alpha.6 ## @mastra/longmemeval@1.1.42-alpha.6 ## @mastra/opencode@0.1.42-alpha.6 ## create-factory@0.4.3-alpha.6 ## mastracode@0.50.0-alpha.6 ## @mastra/agent-builder@1.2.1-alpha.3 ## mastra@1.39.0-alpha.6 ## @mastra/core@1.83.0-alpha.6 ## @mastra/deployer@1.83.0-alpha.6 ## @mastra/editor@0.17.1-alpha.4 ## @mastra/mcp@2.9.0-alpha.3 ## @mastra/mcp-docs-server@1.3.13-alpha.9 ## @mastra/memory@1.41.1-alpha.3 ## @mastra/rag@2.7.3-alpha.2 ## @mastra/schema-compat@1.3.18-alpha.0 ## @mastra/server@1.83.0-alpha.6 ## @mastra/elysia@0.1.23-alpha.6 ## @mastra/express@1.5.27-alpha.6 ## @mastra/fastify@1.5.27-alpha.6 ## @mastra/hono@1.7.25-alpha.6 ## @mastra/koa@1.7.27-alpha.6 ## @mastra/nestjs@0.3.0-alpha.6 ## @mastra/next@0.2.41-alpha.6 ## @mastra/server-adapters-test-suite@0.3.0-alpha.3 ## @mastra/tanstack-start@0.2.41-alpha.6 ## @mastra/upstash@1.6.1-alpha.0 ## @mastra/vectorize@1.1.5-alpha.0 ## @mastra/voice-google-gemini-live@0.14.19-alpha.0 ## @mastra/voice-openai-realtime@0.14.9-alpha.0 ## @mastra/voice-xai-realtime@0.2.18-alpha.0 ## @mastra/inngest@1.11.2-alpha.4 ## @mastra/temporal@0.6.0-alpha.6 ## create-mastra@1.39.0-alpha.6 ## @internal/playground@1.39.0-alpha.6 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
c3ef10ee30 |
fix(core,mcp): warn when same-named MCP tools replace each other (#29415)
## Summary
When two MCP servers expose a tool with the same name and you pass
`toolsets: await mcp.listToolsets()` to an agent, the agent flattens
toolsets by tool name, so only the later server's tool reaches the model
and nothing is logged. `listTools()` has a smaller variant of the same
problem: server and tool names can both contain `_`, so `local` +
`x_status` and `local_x` + `status` both become `local_x_status`, and
one tool is dropped. This PR makes both cases log a warning, without
changing which tool wins, and fixes the `listToolsets()` reference,
which said its keys were namespaced.
```diff
Agent.listToolsets (packages/core/src/agent/agent.ts)
for each toolset, for each tool
+ if an earlier toolset already used this tool name
+ logger.warn(tool, [earlier toolset, this toolset])
toolsForRequest[toolName] = tool # last still wins
MCPClient.listToolsWithErrors / toolsFromDefinitions (packages/mcp/src/client/configuration.ts)
- tools[`${server}_${tool}`] = tool
+ setNamespacedTool(...) # same key, warns when a different pair already took it
```
Docs: the `listToolsets()` reference now says tools keep their raw
names, explains what happens on a collision, and shows `toolsets: { mcp:
await mcp.listTools() }` as a way to keep both tools at request time.
The `listTools()` reference describes the `_` key collision. The "Static
and runtime tools" table in the MCP guide gets a "Tool names" row.
## Evidence
New tests:
`packages/core/src/agent/__tests__/toolset-name-collisions.test.ts`
(real `Agent`, `stream` and `generate`, mock model, checks which tools
reach the model) and
`packages/mcp/src/client/tool-name-collisions.test.ts` (real MCP servers
over HTTP on 127.0.0.1, real `MCPClient`). Only the logger's `warn` is
spied on.
- **Before** (main's `agent.ts` and `configuration.ts` swapped in, same
tests):
```
× warns, naming both toolsets, when two toolsets expose `search`
(stream)
× warns, naming both toolsets, when two toolsets expose `search`
(generate)
Tests 2 failed | 1 passed (3)
× warns, naming both servers and tools, when `local`/`x_status` and
`local_x`/`status` collide
× warns the same way when rebuilding a cached catalog with
toolsFromDefinitions()
Tests 2 failed | 1 passed (3)
```
**After:** `Tests 3 passed (3)` in each file. Each test also asserts
that the winning tool is the same as on main (the later toolset or
server), and that tools with different names produce no warning.
What the warnings look like (captured from a real run):
```
[AGENT] Tool "search" from toolset "tickets" replaces the tool with the same name from toolset "docs", so the "docs" tool is not used. Give the tools distinct names to keep both. {
agent: 'Support Agent', tool: 'search', toolsets: [ 'docs', 'tickets' ], runId: '...'
}
[LLM] MCP tool key "local_x_status" from server "local_x" (tool "status") replaces the tool from server "local" (tool "x_status"), which produces the same key. Only the tool from "local_x" is kept. Rename one of the servers in `servers` to keep both. {
key: 'local_x_status', replaced: { serverName: 'local', toolName: 'x_status' }, replacedBy: { serverName: 'local_x', toolName: 'status' }
}
```
I also ran the docs workaround against two real MCP servers that both
expose `search`: with `toolsets: { mcp: await mcp.listTools() }` the
model received `docs_search` and `tickets_search`, and the snippet
typechecks.
Other checks run: existing `tools.test.ts`, `tool-handling.test.ts` and
`mcp-instructions.test.ts` (core), plus `configuration.test.ts` and
`discovery-settled.test.ts` (mcp), all pass. `tsc --noEmit` is clean for
core and for the touched mcp files. `oxlint` and `oxfmt` pass on the
touched files, and remark, oxfmt-mdx and Vale (error level) pass on both
docs pages. I took no docs screenshots: the change is two paragraphs, a
code block and one table row.
## Merge Danger
**Door:** two-way. The change only adds `logger.warn` calls and docs
text. No tool names, keys or winners change.
**Blast radius:** agents called with `toolsets` whose tool names
collide, and `MCPClient.listTools()` / `toolsFromDefinitions()` with
colliding `server_tool` keys. Those users now see one warning per
request (agent) or per discovery call (MCP client). Everyone else sees
no change.
Closes #29360
## Follow-ups
- Namespacing `listToolsets()` keys (the issue's first suggested fix)
would change the tool names the model sees, so it needs a maintainer
decision and is left out here.
- A toolset tool that replaces one of the agent's own `tools`, or a
`clientTools` entry that replaces a toolset tool, is still silent. That
is a different and possibly intentional override path, so this PR
doesn't warn on it.
- `mastra-mcp` typegen builds the same `${server}_${tool}` keys, so the
same `_` collision can produce a duplicate key in the generated types.
## Council review
| Round | Sol (GPT-6.1 Sol) | Opus (Claude Opus 5.5) | Grok 4.7 |
|---|---|---|---|
| 1 | Correctness 10, Tests 9, Scope 10, Code quality 10 | not run
(Sol-only round) | empty seat |
| 2 | 10 / 9 / 10 / 9 | 9 / 9 / 9 / 8 | empty seat |
| 3 | 10 / 9 / 10 / 9 | 9 / 9 / 10 / 9 | empty seat |
| 4 | 10 / 9 / 10 / 10 | 9 / 9 / 9 / 9 | empty seat |
Created with Claude Opus 5.5 in T3 Code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## ELI5
When tools from different servers have the same name, one can replace
another without notice. This change adds warnings when that happens and
updates the documentation, while keeping the existing rule that the
later tool wins.
## Changes
- Warn when an agent combines toolsets that contain the same raw tool
name.
- Warn when `listTools()` or `toolsFromDefinitions()` produce the same
`serverName_toolName` key for different server and tool pairs.
- Update the MCP documentation to explain raw tool names, collision
behavior, and how `listTools()` keeps server-prefixed names.
- Add tests for collisions, which tool remains, and distinct names.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
8a301f6d66 |
chore(deps): force minimatch 11 and glob 14 for Vanta findings (#29916) | ||
|
|
779d2875b1 |
chore: version packages (alpha) (#29912)
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. ⚠️⚠️⚠️⚠️⚠️⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`. ⚠️⚠️⚠️⚠️⚠️⚠️ # Releases > The changelog information of each package has been omitted from this message, as the content exceeds the size limit. ## @mastra/auth-studio@1.4.0-alpha.1 ## @mastra/factory@0.28.0-alpha.5 ## @mastra/mcp-apps-components@0.1.0-alpha.5 ## @mastra/playground-ui@69.0.0-alpha.6 ## @mastra/client-js@1.60.0-alpha.5 ## @mastra/react@1.15.0-alpha.5 ## @mastra/deployer-cloud@1.83.0-alpha.5 ## @mastra/longmemeval@1.1.42-alpha.5 ## @mastra/opencode@0.1.42-alpha.5 ## create-factory@0.4.3-alpha.5 ## @mastra/code-sdk@1.19.0-alpha.5 ## mastracode@0.50.0-alpha.5 ## @mastra/agent-builder@1.2.1-alpha.2 ## mastra@1.39.0-alpha.5 ## @mastra/core@1.83.0-alpha.5 ## @mastra/deployer@1.83.0-alpha.5 ## @mastra/editor@0.17.1-alpha.3 ## @mastra/mcp@2.9.0-alpha.2 ## @mastra/mcp-docs-server@1.3.13-alpha.8 ## @mastra/memory@1.41.1-alpha.2 ## @mastra/rag@2.7.3-alpha.1 ## @mastra/server@1.83.0-alpha.5 ## @mastra/elysia@0.1.23-alpha.5 ## @mastra/express@1.5.27-alpha.5 ## @mastra/fastify@1.5.27-alpha.5 ## @mastra/hono@1.7.25-alpha.5 ## @mastra/koa@1.7.27-alpha.5 ## @mastra/nestjs@0.3.0-alpha.5 ## @mastra/next@0.2.41-alpha.5 ## @mastra/server-adapters-test-suite@0.3.0-alpha.2 ## @mastra/tanstack-start@0.2.41-alpha.5 ## @mastra/libsql@1.30.0-alpha.2 ## @mastra/turso@0.1.21-alpha.2 ## @mastra/inngest@1.11.2-alpha.3 ## @mastra/temporal@0.6.0-alpha.5 ## create-mastra@1.39.0-alpha.5 ## @internal/playground@1.39.0-alpha.5 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
92f9771a0f |
fix(mcp): send a hydrated tool's lazy connect with the call's requestContext (#29539)
## Summary
A tool rebuilt with `toolsFromDefinitions()` or `toolFromDefinition()`
connects on its first `execute()`, but that connect ran before
`execute()` entered the call's context. The handshake
(`server/discover`, and `initialize` + `notifications/initialized` on
2025-11-25 servers) reached the server definition's custom `fetch` with
`requestContext === null`, so a server that authenticates every request
refused it and a client built only from a cached catalog never
connected. This PR runs the lazy connect inside a connection-scoped
context that only the transport's `fetch` reads.
```diff
buildToolFromListEntry → execute(input, context) (packages/mcp/src/client/client.ts)
+ operationContext = context.requestContext ?? null
if connectFirst
- await connect() # fetch saw null
+ connectAsCall(operationContext, connect) # exits any operation scope, sets the connection context
operationContextStore.run(operationContext, tools/call)
forceReconnect, inside a tool call (reconnectAfterTransportFailure)
- connect() # in the call's operation scope
+ connectAsCall(operationContext, connect)
transport fetch wrapper
- requestContext = operationContextStore ?? null
+ requestContext = operation scope (even an explicit null)
+ ?? connectionContextStore # handshake, event stream
+ ?? replyContextStore, for JSON-RPC replies only
+ ?? null
connectHttp, before client.connect()
+ every transport.onmessage runs outside connectionContextStore,
+ with the reply context captured when the transport was created
```
Why a second store instead of moving the connect into
`operationContextStore.run` (the fix the issue proposed):
`operationContextStore` also labels the entries `logger` receives.
Connecting inside it would put the first caller's context on every later
server log that arrives on the connection's event stream, or from a
stdio child process, including logs from other users' calls. The
connection store gives the handshake and the long-lived event stream the
opening call's credentials, while those logs stay unlabelled as on main.
Calls with no `requestContext`, and handshakes no call started
(`listTools()`, `listToolDefinitions()`), still pass `null`.
Server messages on an HTTP connection are delivered outside the
connection context, starting with the handshake. A request your code
starts from a server log or notification on that connection (for example
`client.listTools()` from a `logger` callback) gets `null`, as on main,
not the opening caller's context. The client's own JSON-RPC replies to
server requests on the connection, such as an elicitation answer on the
event stream, still go out with the connection's context.
A tool call that reconnects (a refused request, or a stdio server that
exited) now connects the same way. On main it reconnected inside the
call's operation scope, so the new event stream or stdio child delivered
every later server message in it. Later server logs were labelled with
the reconnecting caller, and a request started from a log handler
reached `fetch` as that caller. The new handshake, event stream and
replies still carry the caller's context. Logs on a call's own response
stream keep that call's label, as on main, which is why the fix exits
the operation scope when connecting rather than on every inbound
message.
Docs: the `fetch` paragraph in the `MCPClient` reference and the
`MastraFetchLike` JSDoc now say when the handshake gets a call's
`requestContext`. The reference example now shows how discovery
authenticates when the server checks every request (an app token limited
to discovery, or a cached catalog), and the auth-failure section no
longer says every request is a `POST`: on 2025-11-25 servers the event
stream is a `GET`.
## Evidence
New test file
`packages/mcp/src/client/hydrated-tool-request-context.test.ts`: real
MCP servers over HTTP on 127.0.0.1 (a 2026-07-28 stateless server and a
stateful 2025-11-25 server), plus a real stdio child
(`src/__fixtures__/logging-echo-server.ts`). The client's custom `fetch`
puts the `requestContext` user into an `x-user` header, and the server
records the header it actually received for each JSON-RPC method.
- **Before** (origin/main's `client.ts`, same tests):
```
× sends the lazy connect's handshake with the requestContext of the call
that opened it (2026-07-28)
× opens one connection for concurrent first calls and sends each
tools/call as its own user (2026-07-28)
× sends the lazy connect's handshake with the requestContext of the call
that opened it (2025-11-25)
× opens one connection for concurrent first calls and sends each
tools/call as its own user (2025-11-25)
× opens the event stream as the first call but does not label a later
call's server logs with it
AssertionError: expected [ { method: 'server/discover', … } ] to deeply
equal []
AssertionError: expected Set{ 'no-request-context' } to deeply equal
Set{ 'alice' }
Tests 5 failed | 3 passed (8)
```
**After:** `Tests 17 passed (17)`, 5 of 5 repeated runs on the latest
head.
- **Requests started from server messages** (3 tests added after
review): a `client.listTools()` started from a server log on the event
stream, or from a log sent during the handshake, reaches `fetch` without
alice's context; a reply to an `elicitation/create` the server sends on
the event stream reaches it as alice. Against the previous head's
`client.ts`, the two leak tests fail (`tools/list` sent as `alice`);
with the reply branch disabled, the elicitation test fails.
- **Reconnects** (4 tests added after the CodeRabbit re-review). An HTTP
server stops, alice's call is refused and reconnects as the server comes
back. The handshake, event stream and retried call reach `fetch` as
alice. A server log on the new stream is unlabelled, and a `listTools()`
it starts gets `null`; on the previous head they were `alice`. An
elicitation reply on the new stream still goes as alice. A stdio server
exits, bob's call respawns it, and carol's later log is unlabelled; on
the previous head it was `bob`. A `reconnectServer()` from a log
callback answers elicitation as no one (was `alice`). A hydrated tool
connecting from a callback inside alice's call handshakes as bob, its
own caller (was `alice`). A guard test checks that a log on a call's own
response stream stays labelled with that call.
- **The issue's proposed fix** (connect inside
`operationContextStore.run`) passes the handshake tests but fails the
two log tests: `expected 'alice' to be null` for bob's server log on the
event stream and from the stdio child.
- **The issue's `repro.ts`**, run against a local build of this package:
on main it prints `server/discover (requestContext is null)` and `BUG: 1
of 2 requests reached fetch without the call's requestContext`; with
this change, `server/discover alice`, `tools/call alice`, `OK: all 2
requests reached fetch with the call's requestContext`. The `--listed`
control passes on both.
Other checks run: every non-e2e test file in `packages/mcp/src/client`
(622 tests) passes; `tsc --noEmit -p tsconfig.build.json` is clean, and
the new test file typechecks; `oxlint --type-aware --deny-warnings
src/client` and prettier pass on the changed files (oxfmt ignores
`src/client`); the docs page passes `oxfmt-mdx --check`, remark and
Vale. Not run: the client e2e project.
## Merge Danger
**Door:** two-way. Only the `requestContext` that a custom `fetch`
receives during a hydrated tool's first connect changes; reverting
restores `null`.
**Blast radius:** apps that build tools with `toolsFromDefinitions()` /
`toolFromDefinition()` and pass a 3-argument `fetch`. Their handshake,
and on 2025-11-25 servers the long-lived event stream and its re-opens,
now carry the first caller's `requestContext`. For a client shared
across users, that stream is authenticated as whoever's call opened the
connection, as already happens today after a reconnect inside a call. A
reconnect inside a call no longer labels later server logs with that
caller. Servers without a custom `fetch` (including stdio) see no
change.
Closes #29531
## Council review
Rounds: 5
| Seat | Round 1 | Round 2 | Round 3 | Round 4 | Round 5 |
| --- | --- | --- | --- | --- | --- |
| Claude Opus 5.5 | not run | 9/10 | 8.5/10 | 9/10 | 9/10 |
| GPT-6.1 Sol | 9.5/10 | 9.5/10 | 9.5/10 | 8/10 | 9.5/10 |
| Grok 4.7 | empty seat | empty seat | empty seat | empty seat | empty
seat |
CodeRabbit re-review fixes (reconnect context), GPT-6.1 Sol (Correctness
/ Tests / Scope / Code quality):
| Round | Scores | Finding fixed |
| --- | --- | --- |
| 1 | 8 / 8 / 10 / 9 | a `reconnectServer()` from a log callback kept
the old caller's reply context |
| 2 | 8 / 8 / 10 / 9 | a hydrated connect inside another call's scope
handshook as that caller |
| 3 | 9 / 9 / 10 / 9 | none |
Created with Claude Opus 5.5 in T3 Code.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## ELI5
When a tool connects to a server, the server may need the caller’s
information to allow the connection. This change sends that information
during the handshake when a tool call opens the connection, without
attaching it to later server messages.
## Changes
- Pass the opening tool call’s `requestContext` to lazy connection
handshakes and reconnect handshakes for tools rebuilt with
`toolsFromDefinitions()` or `toolFromDefinition()`.
- Keep handshakes started by `listTools()` or `listToolDefinitions()`
context-free. Calls without a `requestContext` also pass `null`.
- Keep server messages and requests started by their handlers outside
the opening call’s context. Replies to server requests use the
connection’s context.
- Add HTTP and stdio tests for context propagation, concurrent first
calls, discovery handshakes, streams, server logs, and reconnects.
- Update the custom-fetch documentation and `MastraFetchLike` JSDoc.
Clarify discovery authentication and the `GET` event stream, and add a
patch changeset for `@mastra/mcp`.
## Validation
Test and CI results: not available.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
||
|
|
4bd4b7f48e |
chore(deps): update better-auth monorepo to v1.7.18 (#29714)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> |
||
|
|
f21e0742ce | chore: version packages | ||
|
|
a873e2df43 |
fix(mcp): don't hang OAuth sign-in on the browser's spare callback connections (#29560)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
544224c38f |
fix(mcp): read resources expanded from advertised templates (#29493) | ||
|
|
3cf319b5af |
fix(mcp): don't resend a tool call whose outcome is unknown (#29492) | ||
|
|
bfe3af4ae1 |
chore(deps): update better-auth monorepo to v1.7.15 (#29497) | ||
|
|
675caf0613 |
chore: version packages (alpha) (#29336)
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. ⚠️⚠️⚠️⚠️⚠️⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`. ⚠️⚠️⚠️⚠️⚠️⚠️ # Releases > The changelog information of each package has been omitted from this message, as the content exceeds the size limit. ## @mastra/client-js@1.60.0-alpha.0 ## @mastra/react@1.15.0-alpha.0 ## @mastra/factory@0.28.0-alpha.0 ## @mastra/code-sdk@1.19.0-alpha.0 ## mastra@1.39.0-alpha.0 ## @mastra/core@1.83.0-alpha.0 ## @mastra/mcp@2.9.0-alpha.0 ## @mastra/mcp-apps-components@0.1.0-alpha.0 ## @mastra/playground-ui@69.0.0-alpha.0 ## @mastra/server@1.83.0-alpha.0 ## @mastra/nestjs@0.3.0-alpha.0 ## @mastra/clickhouse@1.30.0-alpha.0 ## @mastra/duckdb@1.19.0-alpha.0 ## @mastra/libsql@1.30.0-alpha.0 ## @mastra/pg@1.36.0-alpha.0 ## @mastra/temporal@0.6.0-alpha.0 ## @mastra/auth-better-auth@1.1.11-alpha.0 ## @mastra/deployer-cloud@1.83.0-alpha.0 ## @mastra/deployer-cloudflare@1.2.42-alpha.0 ## @mastra/deployer-netlify@1.2.42-alpha.0 ## @mastra/deployer-sandbox@0.3.27-alpha.0 ## @mastra/deployer-vercel@1.2.42-alpha.0 ## @mastra/longmemeval@1.1.42-alpha.0 ## @mastra/opencode@0.1.42-alpha.0 ## create-factory@0.4.3-alpha.0 ## mastracode@0.49.1-alpha.0 ## @mastra/arize@1.3.30-alpha.0 ## @mastra/arthur@0.4.30-alpha.0 ## @mastra/braintrust@1.3.27-alpha.0 ## @mastra/datadog@1.4.22-alpha.0 ## @mastra/deepeval@0.1.24-alpha.0 ## @mastra/laminar@1.3.32-alpha.0 ## @mastra/langfuse@1.6.6-alpha.0 ## @mastra/langsmith@1.4.3-alpha.0 ## @mastra/observability@1.23.2-alpha.0 ## @mastra/otel-bridge@1.5.22-alpha.0 ## @mastra/otel-exporter@1.5.2-alpha.0 ## @mastra/posthog@1.4.7-alpha.0 ## @mastra/sentry@1.2.32-alpha.0 ## @mastra/agent-builder@1.2.1-alpha.0 ## @mastra/connect@1.3.2-alpha.0 ## create-mastra@1.39.0-alpha.0 ## @mastra/deployer@1.83.0-alpha.0 ## @mastra/editor@0.17.1-alpha.0 ## @mastra/mcp-docs-server@1.3.13-alpha.0 ## @mastra/memory@1.41.1-alpha.0 ## @mastra/rag@2.7.3-alpha.0 ## @mastra/redis-streams@0.8.1-alpha.0 ## @mastra/elysia@0.1.23-alpha.0 ## @mastra/express@1.5.27-alpha.0 ## @mastra/fastify@1.5.27-alpha.0 ## @mastra/hono@1.7.25-alpha.0 ## @mastra/koa@1.7.27-alpha.0 ## @mastra/next@0.2.41-alpha.0 ## @mastra/tanstack-start@0.2.41-alpha.0 ## @mastra/spanner@1.11.2-alpha.0 ## @mastra/turso@0.1.21-alpha.0 ## @mastra/inngest@1.11.2-alpha.0 ## @mastra/gcs@0.3.6-alpha.0 ## @internal/playground@1.39.0-alpha.0 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
944d4bcb13 |
feat(mcp-apps-components): add prebuilt MCP Apps with a dashboard renderer (#29321)
This adds `@mastra/mcp-apps-components`, a package of prebuilt MCP Apps
you can serve from any `MCPServer`, plus the server and client changes
they need to read data safely as the signed-in user. Each app has its
own entry point (no root barrel). The first one is a dashboard renderer:
a tool returns a dashboard definition and the host renders it as live
observability charts.
```ts
import { MCPServer } from '@mastra/mcp';
import { dashboardRendererApp } from '@mastra/mcp-apps-components/dashboard-renderer';
import { observabilityAppTools } from '@mastra/mcp-apps-components/observability-tools';
new MCPServer({
id: 'dashboard-mcp-server',
name: 'Dashboard MCP Server',
version: '1.0.0',
appResources: { 'ui://mastra/dashboard': dashboardRendererApp() },
tools: { showObservabilityDashboard, ...observabilityAppTools },
});
```
## How it works
**The app.** A single self-contained HTML page, inlined into the
package's JS so it survives deployer bundling (Vercel, Netlify,
Cloudflare) with no file reads at runtime. Its iframe never reaches the
network: it reads data with `callServerTool` over the host's existing
MCP connection, so no CSP or `baseUrl` setup is needed. It follows the
host's light/dark theme. Drilldowns continue the conversation when the
host supports `ui/message`; on hosts that also support
`ui/update-model-context`, the app passes the exact filters as
structured context and posts a short prompt, otherwise it spells the
filters out in the message.
**Typed observability tools.** `observabilityAppTools` is 11 app-only
tools, one per read-only observability route the dashboard uses
(trace/span/metric/score aggregates, breakdowns, time series,
percentiles, and score listing). Each takes the route's own input schema
and runs the route in-process through the new `invokeRoute()`.
**`invokeRoute()` (`@mastra/server/server-adapter`).** Runs a JSON
server route in-process as the caller, with the same validation, RBAC
permission and FGA checks its HTTP endpoint applies on every adapter,
and returns `{ status, body }`. It does not re-authenticate: when auth
is configured, the request context must carry the user Mastra server
auth resolved, or the call gets a 401. Non-JSON routes throw, and
HTTP-only handler params (`request`, `registeredTools`, `taskStore`,
`routePrefix`) are not supplied.
**Caller identity in MCP tools.** MCP tools served over HTTP now see the
caller Mastra server auth resolved (user, permissions, roles, resource,
organization) in their `requestContext`, on Hono, Express, Fastify, Koa,
Elysia and NestJS. The server attaches it to the MCP request under a
symbol key, so it can only come from the server, never from
client-supplied auth claims.
**Hiding app-only tools.** `MCPClient.listTools()`/`listToolsets()` hide
tools marked `_meta.ui.visibility: ['app']` from agents.
**Studio host.** Studio advertises the host capabilities it handles
(tool calls, messages, model context), passes its theme, routes app tool
calls to the requested tool in the MCP tool playground, and refuses app
calls to model-only tools. App model context is added to the next user
message only, as a clearly delimited block of untrusted app data, never
as system instructions.
## Try it
`examples/agent` has a `dashboard-agent`. In Studio, try "Show me agent
runs over the last 7 days as a line chart".
## Docs
- New reference page for `invokeRoute()`.
- New "Use prebuilt Mastra apps" section in the MCP connections guide.
## Testing
- `invokeRoute` unit tests (auth, permission, validation, handler
errors, non-JSON routes).
- Shared MCP transport suite case, run on every adapter, checking tools
see the server-resolved user and permissions and unauthenticated calls
get 401.
- `observability-tools` tests through a real Hono server with auth and
RBAC: MCP calls, Studio relay, permission denial, invalid input, and a
bundled-consumer test for the inlined HTML.
- Playground and playground-ui tests for the app viewer and model
context handling.
- Manual Studio run: dashboard renders live data and drilldown sends the
context block with the next message.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## ELI5
This PR adds ready-made MCP apps, including a dashboard that shows
observability data. It also lets Studio display these apps and pass
their context to chat as untrusted user content.
## What changed
- Added `@mastra/mcp-apps-components` with a dashboard renderer and
app-only observability tools. The tools invoke server routes in-process
and use the routes’ validation and authorization checks.
- Added `invokeRoute()` for in-process execution of eligible JSON
routes.
- Updated MCP server adapters to pass trusted, server-resolved caller
identity to MCP tools. MCP client discovery filters app-only tools from
agent-facing listings.
- Updated Studio and the playground to render MCP apps, relay app tool
calls, provide host capabilities, restrict tool calls and links, and
attach app context to the next chat message.
- Added a dashboard agent example and documentation for MCP Apps and
`invokeRoute()`.
## Validation
The author reports tests for route invocation, observability tools, MCP
transports across all six adapters, and playground app and chat
behavior. The author also reports a manual Studio check. These results
were not independently verified.
The author reports that the npm reservation for
`@mastra/mcp-apps-components` remained open and required an npm
organization admin before merge.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com>
|
||
|
|
f0ad164646 |
chore(security): Vanta 2026-11-02 - @hono/node-server 2.1.6 (MCP SDK/templates), graphql-scalars 2.0.1, raw-body 4, jose 6 (overrides) (#29199) | ||
|
|
9ce7e350ea |
chore(deps): lock file maintenance (#29341)
Co-authored-by: wardpeet <ward@coding-tech.com> Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
aa6777693d |
feat(core): load storage v2 workflow result steps lazily (#29362)
Co-authored-by: Tony Kovanen <rase-@users.noreply.github.com> |
||
|
|
f9feb98ba3 |
fix(core,mcp): keep submitted values out of tool validation logs (#29331)
> Opened by @user_01KN2T7F5T2WYEMHY58VJGPZ8R Fixes #29318 ## Problem When a tool rejects its input, output, suspend data, or resume data, the validation error message repeats the submitted values (for example `Provided arguments: {"email": "person@example.com"}`). That's on purpose, so the model can see what it sent and fix the call. But the same message was also written to the logs, which put user data such as email addresses into log output. ## Change - **Core** (`tools/validation.ts`, `tool-builder/builder.ts`, `tool.ts`): a new `getValidationIssuePaths()` helper returns the dotted field paths that failed validation (or `root` for top-level issues). Validation-failure logs now contain the tool metadata plus `issuePaths` and no longer include the full message. This covers input, output, suspend-data, and resume-data validation. - **MCP** (`server/server.ts`): the "rejected its input" warnings for plain tools and `run_` workflow tools log `issuePaths` instead of the message. `MCP_SERVER_TOOL_EXECUTE_FAILED` no longer puts the serialized `args` into exception details. - The error returned to the model or MCP caller is the same as before. ## Tests - `builder.test.ts`: five new tests (input, resume data, suspend data, AI SDK tool output, Mastra tool output). Each one checks that no logger call contains the sensitive value and that `issuePaths` is logged. All five fail without the fix. - `server-validation-logging.test.ts`: a new MCP end-to-end test over HTTP. It checks that the caller still gets the validation error and that server logs only contain `issuePaths`. It fails without the fix. - Two existing assertions in `validation.test.ts` expected the old message in the log. They now expect the sanitized form. - Results: `packages/core` `src/tools` 531 passed, `tsc` clean. `packages/mcp` `src/server` 565 passed. One stdio events test failed only when the full suite ran in parallel; it passed when rerun on its own. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 When a tool rejects information, its logs should not repeat the information people sent. This change logs the tool and the fields that failed, while keeping errors available to callers. ## Summary - Updated core validation logs for tool input, output, suspend data, and resume data. Logs include tool metadata and failing field paths instead of validation messages that may contain submitted values. - Added the public `getValidationIssuePaths` helper. It returns dotted paths, uses `root` for top-level errors, and masks undeclared property names. - Updated MCP server validation logs to report failing field paths. MCP tool-execution failure details no longer include serialized arguments. - Updated MCP client logs to omit submitted arguments, server error text, and full error messages or stacks. Output-validation logs report issue paths. Other error logs use `errorKind`, which filters error names and codes. - Sanitized tracked exceptions for remote MCP tool and task failures. Caller-facing errors remain available. - Added core and MCP logging tests. - Raised the minimum `@mastra/core` peer version to `1.82.0-0` for `@mastra/mcp`, `@mastra/connect`, and `@mastra/code-sdk`. ## Test results The PR reports 531 passing core tool tests and a clean TypeScript check. It reports 565 passing MCP server tests. One stdio events test failed in a parallel full-suite run, then passed when rerun alone. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastra-platform[bot] <mastra-platform[bot]@users.noreply.github.com> Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
6e8dfcb83f | chore: version - exit prerelease mode | ||
|
|
4bc3aa672f |
chore: version packages (alpha) (#29255)
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. ⚠️⚠️⚠️⚠️⚠️⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`. ⚠️⚠️⚠️⚠️⚠️⚠️ # Releases > The changelog information of each package has been omitted from this message, as the content exceeds the size limit. ## @mastra/factory@0.27.0-alpha.3 ## @mastra/agent-builder@1.2.0-alpha.3 ## @mastra/core@1.82.0-alpha.3 ## @mastra/mcp@2.8.0-alpha.2 ## @mastra/memory@1.41.0-alpha.3 ## @mastra/playground-ui@68.0.0-alpha.3 ## @mastra/ring-signals@0.1.0-alpha.0 ## @mastra/libsql@1.29.0-alpha.2 ## @mastra/mongodb@1.26.0-alpha.2 ## @mastra/mysql@0.16.0-alpha.3 ## @mastra/pg@1.35.0-alpha.3 ## @mastra/discord@1.3.3-alpha.0 ## @mastra/slack@1.8.1-alpha.0 ## @mastra/teams@0.1.4-alpha.0 ## @mastra/telegram@0.2.5-alpha.0 ## @mastra/client-js@1.59.0-alpha.3 ## @mastra/react@1.14.1-alpha.3 ## @mastra/deployer-cloud@1.82.0-alpha.3 ## @mastra/longmemeval@1.1.41-alpha.3 ## @mastra/opencode@0.1.41-alpha.3 ## create-factory@0.4.2-alpha.3 ## @mastra/code-sdk@1.18.0-alpha.3 ## mastracode@0.49.0-alpha.3 ## @mastra/arize@1.3.29-alpha.2 ## @mastra/arthur@0.4.29-alpha.2 ## @mastra/laminar@1.3.31-alpha.2 ## @mastra/langfuse@1.6.5-alpha.2 ## @mastra/otel-bridge@1.5.21-alpha.2 ## @mastra/otel-exporter@1.5.1-alpha.2 ## @mastra/sentry@1.2.31-alpha.3 ## mastra@1.38.0-alpha.3 ## @mastra/connect@1.3.1-alpha.1 ## @mastra/deployer@1.82.0-alpha.3 ## @mastra/editor@0.17.0-alpha.3 ## @mastra/evals@1.10.11-alpha.0 ## @mastra/mcp-docs-server@1.3.12-alpha.4 ## @mastra/server@1.82.0-alpha.3 ## @mastra/elysia@0.1.22-alpha.3 ## @mastra/express@1.5.26-alpha.3 ## @mastra/fastify@1.5.26-alpha.3 ## @mastra/hono@1.7.24-alpha.3 ## @mastra/koa@1.7.26-alpha.3 ## @mastra/nestjs@0.2.41-alpha.3 ## @mastra/next@0.2.40-alpha.3 ## @mastra/tanstack-start@0.2.40-alpha.3 ## @mastra/turso@0.1.20-alpha.2 ## @mastra/inngest@1.11.1-alpha.2 ## @mastra/temporal@0.5.0-alpha.3 ## create-mastra@1.38.0-alpha.3 ## @internal/playground@1.38.0-alpha.3 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
3015ac82d0 |
feat(mcp): let MCPServer return images, audio and files from tools via toModelOutput (#29247)
Co-authored-by: Arthur Fiorette <47537704+arthurfiorette@users.noreply.github.com> |
||
|
|
e6b6811a95 |
feat(mcp,playground-ui): answer MCP task input requests from the agent chat (#29032)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
47a6cd82e5 |
chore(deps): update ai sdk (#29242)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> |
||
|
|
886679eb10 |
chore: version packages (alpha) (#29205)
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and publish to npm yourself or [setup this action to publish automatically](https://github.com/changesets/action#with-publishing). If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. ⚠️⚠️⚠️⚠️⚠️⚠️ `main` is currently in **pre mode** so this branch has prereleases rather than normal releases. If you want to exit prereleases, run `changeset pre exit` on `main`. ⚠️⚠️⚠️⚠️⚠️⚠️ # Releases > The changelog information of each package has been omitted from this message, as the content exceeds the size limit. ## @mastra/client-js@1.59.0-alpha.2 ## @mastra/factory@0.27.0-alpha.2 ## @mastra/code-sdk@1.18.0-alpha.2 ## mastra@1.38.0-alpha.2 ## @mastra/core@1.82.0-alpha.2 ## @mastra/editor@0.17.0-alpha.2 ## @mastra/server@1.82.0-alpha.2 ## @mastra/clickhouse@1.29.0-alpha.1 ## @mastra/duckdb@1.18.0-alpha.1 ## @mastra/pg@1.35.0-alpha.2 ## @mastra/platform-workspace@1.12.0-alpha.1 ## @mastra/react@1.14.1-alpha.2 ## @mastra/deployer-cloud@1.82.0-alpha.2 ## @mastra/deployer-sandbox@0.3.26-alpha.1 ## @mastra/longmemeval@1.1.41-alpha.2 ## @mastra/opencode@0.1.41-alpha.2 ## @mastra/parallel@0.1.5-alpha.0 ## create-factory@0.4.2-alpha.2 ## mastracode@0.49.0-alpha.2 ## @mastra/arize@1.3.29-alpha.1 ## @mastra/arthur@0.4.29-alpha.1 ## @mastra/braintrust@1.3.26-alpha.1 ## @mastra/datadog@1.4.21-alpha.1 ## @mastra/deepeval@0.1.23-alpha.1 ## @mastra/laminar@1.3.31-alpha.1 ## @mastra/langfuse@1.6.5-alpha.1 ## @mastra/langsmith@1.4.2-alpha.1 ## @mastra/observability@1.23.1-alpha.1 ## @mastra/otel-bridge@1.5.21-alpha.1 ## @mastra/otel-exporter@1.5.1-alpha.1 ## @mastra/posthog@1.4.6-alpha.1 ## @mastra/sentry@1.2.31-alpha.2 ## @mastra/agent-builder@1.1.33-alpha.2 ## @mastra/deployer@1.82.0-alpha.2 ## @mastra/mcp@2.8.0-alpha.1 ## @mastra/mcp-docs-server@1.3.12-alpha.3 ## @mastra/memory@1.41.0-alpha.2 ## @mastra/playground-ui@68.0.0-alpha.2 ## @mastra/rag@2.7.2-alpha.0 ## @mastra/elysia@0.1.22-alpha.2 ## @mastra/express@1.5.26-alpha.2 ## @mastra/fastify@1.5.26-alpha.2 ## @mastra/hono@1.7.24-alpha.2 ## @mastra/koa@1.7.26-alpha.2 ## @mastra/nestjs@0.2.41-alpha.2 ## @mastra/next@0.2.40-alpha.2 ## @mastra/tanstack-start@0.2.40-alpha.2 ## @mastra/dsql@1.5.6-alpha.0 ## @mastra/libsql@1.29.0-alpha.1 ## @mastra/mongodb@1.26.0-alpha.1 ## @mastra/mssql@1.11.1-alpha.0 ## @mastra/mysql@0.16.0-alpha.2 ## @mastra/oracledb@0.5.6-alpha.0 ## @mastra/spanner@1.11.1-alpha.0 ## @mastra/turso@0.1.20-alpha.1 ## @mastra/voice-google@0.14.5-alpha.0 ## @mastra/inngest@1.11.1-alpha.1 ## @mastra/temporal@0.5.0-alpha.2 ## @mastra/e2b@0.16.1-alpha.1 ## create-mastra@1.38.0-alpha.2 ## @internal/playground@1.38.0-alpha.2 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
96b1bfbf50 |
fix(mcp): reject calls to unknown tools with a JSON-RPC protocol error (#29204) | ||
|
|
eed9cc214e | chore: version packages | ||
|
|
a69d91af24 |
chore(deps): update security updates [security] (#28883) | ||
|
|
8bea9662c5 |
fix(mcp): authorize hosted MCP tool calls once, against the server's resource (#29077) | ||
|
|
eddb0605db |
fix(mcp, mastracode): report each MCP server as it settles so one stalled server can't block the others (#29028)
> Opened by @abhiaiyer91 Fixes #29004 ## Summary Mastra Code discovers MCP tools through one shared `MCPClient`, and it didn't set any server's status until the combined `listToolsetsWithErrors()` call returned. That call waits for every server, and requests have a 7-day timeout. So one server that never finished its handshake left **every** server on "connecting...", and reconnecting a healthy server had to wait for the stalled one. The fix is in two parts. **`@mastra/mcp` (minor)** - **`onServerSettled` option:** `listToolsWithErrors()`, `listToolsetsWithErrors()` and `listToolDefinitionsWithErrors()` accept an `onServerSettled(serverName, { value | error, duration })` callback. It fires for each server as soon as that server succeeds, fails or hits `perServerTimeoutMs`, before the aggregate call resolves. If the callback throws or its promise rejects, the error is logged and discovery carries on. A rejected callback never becomes an unhandled rejection. - **`serverNames` option:** the discovery calls accept an optional `serverNames` list, so a caller can discover only the servers it needs. Mastra Code uses it to retry just the servers that timed out, and to refresh the tools of just the server being reconnected. - **Timeout error code:** a discovery timeout now has `code: MCP_DISCOVERY_TIMEOUT_CODE` (exported), so callers can tell a slow server from a failed one. - **Stalled connects are torn down (patch):** if a stdio server never answered its handshake, `disconnect()` could hang behind a pending `reconnectServer()`, and the server process was left running. Two causes: the SDK's version-negotiation probe child is never attached as the client transport, and a failed attempt could drop a client that a newer attempt still owned. Now an in-flight connect is tracked and closed by `disconnect()` and `reconnectServer()`, attempts from an older lifecycle generation stop, and a failed attempt can't remove a client a newer attempt is still using. - Docs: `onServerSettled` and `serverNames` are added to the `MCPClient` reference, including a retry example that only rediscovers the servers that timed out. **`@mastra/code-sdk` (patch)** - **Single client:** the manager still uses one `MCPClient`. It passes `perServerTimeoutMs` (60s by default, configurable via `createMcpManager(..., { discoveryTimeoutMs })`) and sets each server's status and tools from `onServerSettled`. Healthy servers show as connected as soon as they're ready. - **Late servers:** a server that times out shows as failed. If it finishes later (for example a cold `npx` install), it switches to connected and its tools are registered. Tools are resolved per agent request, so they're available from the next turn. - **Attempt guard:** per-server attempt tokens drop results from a superseded attempt, a reload, a disabled server or a disconnected manager. - **Reconnect:** a reconnect from `/mcp` calls `client.reconnectServer(name)` and returns once *that* server settles. It shares one 60s deadline across reconnect and tool listing, and doesn't wait for other servers. - **Exact tool removal:** a server's previous tools are removed by the exact tool names that server reported, not by a `${name}_` prefix. A server named `foo` no longer deletes `foo_bar_ping` from the unrelated server `foo_bar`. - **Scoped rediscovery:** the late retry for timed-out servers rediscovers only those servers, and a reconnect refreshes only the server being reconnected. A server that failed on start is no longer relaunched (and no longer re-prompts for auth) every time a sibling times out or is reconnected. - **Stable tool order:** `getTools()` returns tools in server config order, whatever order servers settle in, so the tool list sent to the model doesn't change between runs. ## Test plan - `packages/mcp/src/client/discovery-settled.test.ts` (real stdio processes): the callback fires for the healthy server while the stalled one is still pending, and the aggregate call is still waiting. A throwing callback doesn't break discovery. - `packages/mcp/src/client/discovery-settled.test.ts`: an `async` callback that rejects doesn't break discovery and doesn't raise an unhandled rejection. - `packages/mcp/src/client/stalled-connect.test.ts` (real stdio, pid files): - `disconnect()` kills the stalled child of a timed-out discovery. - `disconnect()` resolves promptly while a reconnect to a stalled server is pending. - A new connection works after a disconnect that cut a reconnect short. - Each test checks that no child process is left. - `mastracode/sdk/src/mcp/__tests__/manager-stalled-server.test.ts` (real `@mastra/mcp` client and stdio fixtures; HOME, app data and CODEX_HOME isolated). 8 tests: - The healthy server is connected while the stalled one is still `connecting`. - The stalled server fails with a timeout error. - A slow server that finishes after the timeout switches to connected. - Reconnecting a healthy server while another is stalled. - A stalled reconnect is bounded by one 1s deadline (under 1.9s total), and `disconnect()` then takes under 3s with no child left. - Reconnecting while the timed-out startup attempt is still finishing never shows a failure. - A late discovery doesn't re-add tools after the server is disabled. - A server that failed on start is not relaunched when a sibling times out or is reconnected. - `manager.test.ts`: tools come back in config order when a later server settles first, a reconnect asks the client to discover only that server (`serverNames: ['fs']`), and a server whose name starts with another server name keeps its own tools. - `packages/mcp/src/client/discovery-settled.test.ts`: discovery can be scoped to a list of server names, and the other servers are not touched. - `manager-stalled-server.test.ts`: a server that failed on start is not relaunched when a sibling times out or is reconnected. - `manager.test.ts` is back to single-client assertions. Its `@mastra/mcp` mock emulates `onServerSettled` from each test's aggregate result. - `@mastra/mcp`: `vitest run` gives 1448 passed, 6 skipped (78 files). `@mastra/code-sdk`: `vitest run src/mcp` gives 145/145. ACP conformance (`test:acp:conformance`, built SDK) passes in all three shutdown modes. `tsc --noEmit`, oxlint and oxfmt are clean, and the MDX lint passes. - The `onServerSettled` option type stays `(serverName, result) => void`. An `async` callback is assignable to that type, so async callbacks are supported without widening the type to `void | Promise<void>` — that union rejects any callback that returns a value and broke `tsc --noEmit` in `mastracode/sdk`. The implementation still observes the callback's return value at runtime and logs a rejected promise instead of leaving it unhandled. ## Proof **Revert checks** - `configuration.ts` without `onServerSettled`: both discovery-settled tests fail (`expected [] to include 'healthy'`). - `client.ts` and `handleConnectError` back to main: all 3 stalled-connect tests fail. The first leaves a live child; the other two hang to the 20s test timeout. - `manager.ts` from main (`b0e86c50`), with the fixed `@mastra/mcp`: 6 of the 7 manager tests that existed before the `serverNames` change fail, and the new no-respawn test fails on main too (8 spawns instead of 4). The healthy server never reports connected, which is the #29004 symptom. The disable test passes on main because main has no late-discovery path at all. - `getTools()` back to insertion order: the config-order test fails (`remote_context` first), and ACP conformance fails `follow-up turn and client MCP subprocess cwd/environment`, the same failure as the CI Mastra Code E2E job on `04378d98`. Its mocked model calls the first tool whose name contains `context`, and that was the HTTP probe's tool. - Fixed `manager.ts` with the attempt guard forced to `true`: the disable test fails 3/3, because the late result marks the disabled server connected. - The exact-tool removal reverted to the `${name}_` prefix: the prefix-sharing test fails, because `foo` settling drops `foo_bar_ping` while `foo_bar`'s status still says connected. - The `serverNames` filter reverted: the failing-server test fails. The server that failed on start is spawned 8 times instead of 4, because each sibling timeout and each reconnect relaunches it. - The async-callback rejection handler removed: the new async-callback test fails, because the rejection escapes as an unhandled rejection. - The `onServerSettled` type widened back to `void | Promise<void>`: `tsc --noEmit` in `mastracode/sdk` fails with TS2322 at `manager.ts:553`, because the callback returns `record(...)`'s value. **Real servers (Linux sandbox, real manager via `tsx`, status changes logged with timestamps)** - `everything`: `npx -y @modelcontextprotocol/server-everything` with an empty npm cache - `stalled`: a stdio process that reads stdin and never replies - `remote-stalled`: `npx -y mcp-remote http://127.0.0.1:<port>/mcp --allow-http`, cold cache, pointed at an HTTP server that never responds | Scenario | `everything` | `stalled` / `remote-stalled` | `init()` | `disconnect()` | |---|---|---|---|---| | Pre-fix `manager.ts` (`b0e86c50`), 80s | still `connecting` | still `connecting` | never settled | n/a | | This PR, 60s cap | connected (13 tools) at 11.5s | failed (timeout) at 60.7s | settled at 60.6s | 161ms, no child left | | This PR, 5s cap (forces a late connect) | failed at 5.7s, then connected (13 tools) at 12.6s | failed (timeout) at 5.7s | settled at 5.7s | 160ms, no child left | ## Unverified - **Reconnect-while-starting guard:** the test passes even with the guard removed. With one shared client, the abandoned startup attempt joins the reconnect's connection and also ends up connected, so the stale-write order can't be forced reliably. The guard is proven by the disable test. - **fal-ai, figma-console and devrev:** not run, because they need credentials. The `mcp-remote` dead-endpoint run stands in for devrev's stall. - **TUI:** not driven. `/mcp` reads `getServerStatuses()`, which is what the real-server runs recorded. - **macOS and Windows:** the sandbox is Linux-only, and no CI workflow uses macOS or Windows runners. - **CI "Affected UNIT Test":** the only failing test in that job is `packages/connect/src/__tests__/channels.test.ts:473` — a 5s timeout on the first cold import of the real `@mastra/discord`, which takes ~4.6s under runner load. It passes in isolation on this head, the rest of the file's MCP-free import graph never reaches `@mastra/mcp`, and another test in the same file fails on `main` in this sandbox. Everything else in the job is green: 16143 passed, 15 skipped, no type errors. ## Risk: medium This changes connect, reconnect and disconnect lifecycle code in `@mastra/mcp`, which every `MCPClient` user goes through, not just Mastra Code. The new option is additive, and the full `@mastra/mcp` suite passes. One visible change: `disconnect()` during a stalled connect now logs that connect's abandonment as an `MCP_CLIENT_CONNECT_FAILED` error. A manual reconnect that takes longer than 60s shows as failed until it finishes or is retried. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 When one MCP server gets stuck, Mastra Code can still show tools from the servers that connected successfully. A stuck server gets its own timeout, and it can still connect later if its attempt is still current. ## Summary - `@mastra/mcp` adds `onServerSettled` to tool, toolset, and tool-definition discovery. The callback reports each server’s result and discovery duration. Callback errors are logged and ignored. - Discovery timeouts use the exported `MCP_DISCOVERY_TIMEOUT_CODE`. The new `serverNames` option limits discovery to selected configured servers. - MCP client lifecycle handling stops stalled connection attempts during disconnect or reconnect and prevents superseded attempts from changing current state. - Mastra Code keeps one shared `MCPClient` and updates each server’s status and tools as discovery settles. Its per-server discovery timeout defaults to 60 seconds and can be configured with `discoveryTimeoutMs`. - A timed-out server can connect later and register its tools if its attempt is still current. Attempt checks prevent stale results from overriding newer attempts or affecting disabled servers and disconnected managers. - Reconnecting from `/mcp` waits only for the selected server, with one timeout covering reconnect and tool listing. Tool order follows server configuration order. - The MCP client reference documents the discovery callback and server selection option. ## Validation The author reports 1,445 tests passed and 6 skipped in the `@mastra/mcp` suite, and 143/143 passed for `@mastra/code-sdk`’s `vitest run src/mcp`. The author also reports passing ACP conformance in all three shutdown modes. The author reports that macOS and Windows were not tested, the TUI was not driven, and credential-dependent fal-ai, figma-console, and devrev servers were not run. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
77076a1012 | chore: version - exit prerelease mode | ||
|
|
582ef17a2b |
chore: version packages (alpha) (#28888)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
||
|
|
80f2f21133 |
feat: show MCP tasks in Studio (server Tasks panel and tool-call task chip) (#28629)
> **Targets `main`.** #28343, #28521, and #28619, which this builds on, are merged, so the diff shows only the Studio work. ## What this adds MCP servers with `tasks` enabled run some tool calls (and, with the workflows/agents PR, `run_<workflow>` / `ask_<agent>` calls) as long-running MCP tasks. Until now Studio showed nothing about them: the server page didn't say which tools run as tasks or list any tasks, and a chat tool-call card for a task-backed tool showed only the final result, with no task id, status or running time. **Server page (`/mcps/:serverId`)** - Tools list gets a **Task** column: `always` / `auto`, `required` when clients without task support are refused for that tool, and `recover` when the call is retried after a restart. - New **Tasks** panel: surface, status, created, updated, expiry, open input requests, a short task key and the **client** that sent the task. It refreshes every 2s while any task is still running. - Filter by status, surface or client (filters live in the URL). Clicking a client in a row filters to that client, so you can see which client's tasks keep failing. - Shows 50 tasks at a time with **Load more** for older ones. - **Find by MCP task id**: paste the id a client shows (e.g. from the chat chip) to open that task. - Opening a task shows its metadata and result or error. You can answer an `elicitation/create` request with a form built from its `requestedSchema`: Accept is the primary action, Decline the secondary one. Cancel task is a quieter red action below the form. Other input methods are shown read-only. **Chat tool-call card** - A chip `task · working · 0:42` → `completed` / `failed` / `cancelled`, with a button that copies the **MCP** task id. The Mastra background-task id is a different id. ## How it's built The layering is the same as the MCP events Studio PR: core contract → `@mastra/mcp` → `@mastra/server` → `@mastra/client-js` → Studio. - **`@mastra/core`**: experimental, optional `getTasksInfo()` / `getTasksInspector()` on `MCPServer`, the same pattern as `getEventsInfo` / `getEventsInspector`. Each task surface reports its own `mode`, `required`, `recover` and `ttlMs`. Nothing new goes into `tools/list` or onto the wire. - **`@mastra/mcp`**: the protocol store still can't list tasks. A separate optional `MCPTaskStoreAdmin` (`list`, `updateByKey`, `cancelByKey`) is keyed by the stored task key, which is a hash of the task id. `get/update/cancel` now go through the same key-based paths, so Studio's cancel and answer run the exact code that `tasks/cancel` and `tasks/update` run, with the same fencing and persist-before-ack. The in-memory and background-task stores implement it. Custom stores that don't implement it get "this store can't be listed". The MCP client writes an `mcp-task` progress entry (`MCPTaskProgress`) to the tool's output stream when the task is created and on each status change. - **`@mastra/server`**: - `GET /mcp/:serverId/tasks`: newest first, `limit` 50 by default and at most 200; filters `status`, `surface`, `client` (the hashed client key) and `key`; returns `nextCursor` for the next page. The background-task store pushes surface, client and key into its query; status is checked after reading, because an expired running row reads as failed. - `POST /mcp/:serverId/tasks/find`: body `{ taskId }`, hashed on the server, so raw ids never land in URLs or access logs - `POST /mcp/:serverId/tasks/:taskKey/cancel` - `POST /mcp/:serverId/tasks/:taskKey/input` - `tasks_capability` on server list/detail. - **`@mastra/client-js`**: `getMcpServerTasks` (filters + cursor), `findMcpServerTask`, `cancelMcpServerTask`, `answerMcpServerTaskInput`. ### Access and privacy - Responses carry hashed task keys, hashed caller keys and, since #28521 (`ebcfb2bbe96`), the caller's `clientLabel`: client id plus token subject or user id, or plus a short prefix of the token's hash for token-only callers. The label is never a credential and is never used to authorize. Raw task ids and tokens never reach Studio. The client filter matches the hashed key, not the label. Tasks stored before labels existed show a short form of the key. - Only operators see this view: the routes need Mastra auth, resource-scoped sessions get nothing, and MCP itself has no list method. - **Permissions:** listing and finding tasks need `mcp:read` (same model as `/background-tasks`). Cancelling and answering need `mcp:write`, because they act on another client's task. With the default roles, `admin` can act on tasks, while `member` and `viewer` can only see them. Studio hides Cancel, Accept and Decline for users without `mcp:write` and says why. - Since #28521 (`19dbb7732b0`), task rows store only a hash of the caller's principal, so neither the store nor `/background-tasks` holds the raw principal. - **Resource-scoped Studio sessions fail closed.** They get no list and a 404 on cancel/answer, because Mastra resource ids and MCP principals have no defined mapping. Only unscoped sessions see a server's tasks. - Unknown or expired keys return 404. ### Known limits - **The chip's task id is live-only.** Progress isn't saved with the thread, so a reloaded thread shows only the final result. - **Deferred calls:** - Background-task progress and completion chunks don't reach the tool-call card after the chat turn ends. - The server-side SSE has them, but the thread stream never delivers them to the browser. This looks like an existing stream/association gap and isn't fixed here. - The chip works around it: until progress shows the task ended, it polls `GET /background-tasks/:id` to learn how the task ended. - The agent still quotes the Mastra background-task id in its reply. Changing what the model is told is out of scope. - Answering client-side `inputRequests` from chat is out of scope. ## Test plan - `@mastra/mcp`: - admin contract suite against both stores: list, filters (status, surface, client, key), cursor paging over every task exactly once, idempotent cancel/answer, cross-principal, raw id rejected; - inspector `find` by raw id (a task key or unknown id finds nothing) and `clientLabel` on listed tasks for both stores; - the background store fills a full page even when newer rows can't be read as tasks; - `getTasksInfo` / `getTasksInspector` on `MCPServer`, checking that `tools/list` doesn't change; - client `onStatus` and progress writes. - All existing 3c task tests are green before and after the `*ByKey` refactor. - `@mastra/server`: handler tests for `tasks_capability`, unscoped list, default limit and `nextCursor`, filters and cursor passed to the store, unknown status rejected, limit cap, `clientLabel` kept, find by raw id (id only in the body, 404 for unknown/scoped/not listable), scoped callers failing closed (an empty-string resource id is also treated as scoped), not-listable stores, and 404s. A mutation check confirmed the scoping tests fail without the guard. - `@mastra/client-js`: request shapes, including key URL-encoding, filter/cursor query and the find body. - Studio: - MSW tests for the Tasks panel (every status, empty, not listable, resource scoped, live refresh, cancel, answer form, Load more, URL status filter, click-a-client filter showing its label, no-match state, find by id (opens the task / says not found), drawer client label, tool Task column with `required` per tool); - chip tests (live progress, terminal states, polling the background task for deferred calls, `readToolPart`). - Mutation checks confirmed the key tests fail without the change. - Manual, in the showcase app: - answering an elicitation and cancelling from the drawer both drive the task to its end state; - the chip goes from `working` to `completed · 0:12` on a live deferred `slow_report`. - Lint passes for every touched package, and typecheck passes for core, mcp, client-js, playground-ui and playground. `@mastra/server` typecheck shows only an existing `@mastra/agent-builder` resolution error. ## Screenshots **Before: server page, no task information** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-before-server-mcp.png" alt="Before: server page, no task information" width="720"> **Before: tool card shows only the result** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-before-client-slow-report-completed.png" alt="Before: tool card shows only the result" width="720"> **After: Task column per surface (`required` only on `gated`)** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tools.png" alt="After: Task column per surface (`required` only on `gated`)" width="720"> **After: Tasks panel with filters, find box and Client column** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tasks.png" alt="After: Tasks panel with filters, find box and Client column" width="720"> **After: filtered to failed tasks from one client** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tasks-failing-client.png" alt="After: filtered to failed tasks from one client" width="720"> **After: Load more under the first 50 tasks** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tasks-load-more.png" alt="After: Load more under the first 50 tasks" width="720"> **After: a pasted task id opens its task** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tasks-find.png" alt="After: a pasted task id opens its task" width="720"> **After: drawer, working** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-drawer-working.png" alt="After: drawer, working" width="720"> **After: drawer, input required** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-drawer-input-required.png" alt="After: drawer, input required" width="720"> **After: answering an elicitation from Studio** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-drawer-answer-form.png" alt="After: answering an elicitation from Studio" width="720"> **After: answered** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-drawer-answered.png" alt="After: answered" width="720"> **After: drawer, completed** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-drawer-completed.png" alt="After: drawer, completed" width="720"> **After: drawer, failed** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-drawer-failed.png" alt="After: drawer, failed" width="720"> **After: cancelled from Studio** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-drawer-cancelled-from-studio.png" alt="After: cancelled from Studio" width="720"> **After: chat chip while the task runs** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-client-slow-report-running.png" alt="After: chat chip while the task runs" width="720"> **After: chat chip when it completes** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-client-slow-report-completed.png" alt="After: chat chip when it completes" width="720"> **After: chat chip for a failed task** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-client-expiring-failed.png" alt="After: chat chip for a failed task" width="720"> <details><summary>Tablet (768px) and phone (390px)</summary> <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tools-768.png" alt="tools-768" width="720"> <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tasks-768.png" alt="tasks-768" width="720"> <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tools-390.png" alt="tools-390" width="720"> <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/pr7/pr7-after-server-tasks-390.png" alt="tasks-390" width="720"> </details> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 Studio can now show tasks that run through MCP servers and their status. Users with the right access can answer task requests or cancel tasks. Chat tool calls can also show task progress. ## Summary - Added MCP task listing and lookup in Studio, with status, surface, and client filters, pagination, and lookup by MCP task ID. - Added task details with status, timestamps, results or errors, and supported input requests. Users with `mcp:write` can answer requests or cancel tasks. - Required `mcp:read` for listing and lookup. Resource-scoped sessions cannot inspect tasks. Custom task stores need the `MCPTaskStoreAdmin` interface to support listing. - Added task capability metadata to MCP server responses and task-mode metadata to the tools list. - Added task progress updates and a chat chip that shows task status and elapsed time, with a button to copy the MCP task ID. For deferred tool calls, the chip polls the background-task endpoint for status updates. - Added MCP task methods to `MastraClient` and experimental task types and inspector hooks in core. ## Validation The PR description reports tests for task stores, server routes, client requests, and Studio behavior. It also reports lint checks and typechecks for several packages. The `@mastra/server` typecheck reports an existing `@mastra/agent-builder` resolution error. The PR description reports manual checks for task answering, cancellation, and deferred-task completion. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
ea26a4b1cc |
feat(mcp): serve workflows and agents as MCP tasks (#28619)
Lets an `MCPServer` serve its workflows (`run_<workflow>`) and agents (`ask_<agent>`) as MCP tasks (SEP-2663, experimental), with the same modes as tools. Before this, `tasks.workflows` and `tasks.agents` threw "not supported yet", and those tools could only answer synchronously. Stacked on #28521 (← #28420 ← #28340). It also carries the core stack #28425 → #28507 → #28590 until those merge. `@mastra/mcp` only, no core changes. ```ts const server = new MCPServer({ id: 'reports', name: 'Reports', version: '1.0.0', workflows: { nightly }, agents: { researcher }, tasks: { workflows: { nightly: 'always' }, agents: { researcher: { mode: 'auto', syncWindowMs: 1000 } }, }, }); ``` **Workflows.** A workflow task follows a single run. The run starts once, under the `tools/call` that creates the task, with a fresh `runId` that is never the task id. After that, a task attempt never starts a run. It can only: - re-attach by polling `getWorkflowRunById`, - resume on a `tasks/update`, where core's `suspended → running` claim allows one resume per suspension (if the claim is lost, the attempt follows whoever resumed the run instead), - or cancel the run. When a step suspends, the task moves to `input_required` with a form built from the step's `resumeSchema` (nested workflows are walked too). If the schema can't be shown as a form, the task stays `working` and follows a resume made from Studio or the API. If a server dies mid-run, core's boot sweep (`recovery.workflows: 'auto'`) continues the run on the next instance, and the task re-attaches to it there. A server that shuts down gracefully, or loses the task's lease to another worker, only stops following the run: it never cancels it. An answer to a suspension that was already resumed elsewhere (Studio, the API) is dropped: the task checks the step and its `suspendedAt` before resuming, and on a refused resume, then follows the run and asks again. A run that ends `failed`, `tripwire` or `canceled` completes the task with `isError`. A task ends `failed` only on infra problems: a lost run, TTL expiry, or a store error. **Cancelling.** Both task stores get an optional, fire-and-forget `onCancel(context)` hook, called on `tasks/cancel` and on TTL expiry, even while no attempt runs (a task waiting for input). MCPServer uses it to cancel the run: a run executing in this process is stopped here, a run waiting is cancelled in storage, and a run executing on another instance is left to that instance (writing `canceled` under it would only be overwritten). Core aborts that instance's attempt once its row reads cancelled (#28523); the background store then re-reads the row and, if it was cancelled or expired, calls `onCancel` there too, so the run stops where it executes. Aborting an attempt for any other reason (shutdown, lost lease) never cancels the run. With a custom `tasks.store`, the docs say how to cancel the run from the exported `WorkflowTaskContext`. **Agents.** Agent tasks reuse the tool-task path: `abortSignal` cancels the run, a throw ends the task as `isError`, and `recover` applies. If an agent pauses for tool approval, the task completes with an `isError` message for now. Agent approval inside tasks is a follow-up. **Config.** `tasks.default` now also covers workflows and agents that aren't listed. `tasks.required` takes the names clients call, such as `run_nightly`. Unknown keys still throw at construction. **Tracing.** Each workflow or agent task is one trace, like a tool task. Attempts are `task attempt run_<key> #n` / `ask_<key> #n` spans under the `tools/call` root. A workflow run starts under attempt #1 (or under the root in `'auto'`), and each run resumed after `tasks/update` sits under the attempt that resumed it, on whichever instance answers. An agent's `agent run` sits under its attempt. A run that Mastra's workflow recovery restarts after a crash starts a trace of its own: that's by design, since durable workflows and agents cover tracing across a crash. The task's attempt that follows the restarted run stays in the task's trace. **Behaviour difference to note.** A synchronous `run_` call (mode `'off'`, or a client without the extension) still answers a failed run without `isError`. In task mode, and in `'auto'` when the run finishes inside the window, a failed run answers with `isError`, per S9. **The run id lives in the row's `args.context`, not `metadata`.** `workFor` reads `args.context`, so the run id sits there with the rest of the work's context instead of in `metadata`. **Known limitations** - Same step suspending again in a loop: if a resume from outside MCP lands between the task's check and its own `resume()`, a stale answer can resume the step's *next* suspension. Closing that window needs core `resume({ expectedSuspendedAt })`. Different steps are safe: core refuses the stale step and the task follows the run. - A suspension that can't be shown as a form, or a run another instance executes, keeps the task polling once a second and holding a background-task slot. **Testing** - `pnpm --filter ./packages/mcp test:server` 3× clean: 421 passed. `tsc`, oxlint and oxfmt clean. - New `server-tasks-workflows.test.ts` (32 tests, in-memory and background store), using real `MCPServer` over HTTP and real workflows, plus an agent on a mock model. It covers: - auto fast and slow - suspend → update → complete, with the side-effect step running once - decline - cancel while working and while waiting for input - failed - unrepresentable schema - another principal - config errors - agent slow, cancel, error and pause - Additions to `server-tasks-background.test.ts` (libsql file, two instances): - answer through B for a run that A started - two instances taking the same answer at once - a run resumed outside MCP first - cancelling a waiting run from the other instance - a server shutting down mid-step, and one losing its lease to another worker: the run carries on and the task completes - tracing: one trace per task across `tasks/update` on a peer, a shutdown re-attach, and a crash restart (the following attempt is in the task trace; the restarted run has its own) - a child server SIGKILLed mid-step, after which a new instance runs `restartAllActiveWorkflowRuns()`. The task completes on one run, and the steps run `fetch, crunch, crunch`. - Mutation-checked. The matching tests fail when I: - start a run in `work` instead of re-attaching (the steps then show 4 entries), - drop the claim-lost fallback, - drop the `onCancel` hook (3 cancel tests fail). - Manual check in the showcase playground: `run_nightly` and `ask_researcher` driven from the client agent's Studio chat. The approve form went through `tasks/update`, server Studio showed one run per call, and cancelling while waiting for input cancelled the run. The `ask_<agent>` result is the whole `generate()` output as JSON (about 5k tokens for a short answer). That's also true of the synchronous tool today, so it isn't changed here, but it's worth a follow-up. ## Screenshots (tracing) **Before: `run_nightly` start is an Error, and `tasks/update` and each poll are separate traces** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/tracing/before-run_nightly-trace.png" alt="before" width="720"> **After: one trace with `tools/call` → attempt #1 (run) → `tasks/update` → attempt #2 (resumed run)** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/tracing/after-run_nightly-trace.png" alt="after" width="720"> **Before: `ask_researcher`'s agent run is its own root trace** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/tracing/before-ask_researcher-trace.png" alt="before agent" width="720"> **After: the agent run sits under its task attempt** <img src="https://raw.githubusercontent.com/mastra-ai/mastra/14d862b62c1d2aecb0810d6480fe6af96cd9fe8c/tracing/after-ask_researcher-trace.png" alt="after agent" width="720"> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 This change lets MCP clients start and manage workflow and agent tasks, as well as ordinary tool tasks. Clients can check task progress, provide input when a workflow pauses in a supported way, and cancel supported tasks. ## Summary - Adds experimental task support for workflow tools named `run_<workflow>` and agent tools named `ask_<agent>`. - Extends task configuration so defaults and required-task checks can include workflows and agents. - Starts one workflow run per workflow task. Later task attempts track, resume, or cancel that run. - In `auto` mode, a workflow run that finishes within `syncWindowMs` returns synchronously. Otherwise, it continues as a task. - Requests input only for workflow suspensions with a client-fillable `resumeSchema`. Other suspensions remain in progress. - Adds workflow recovery and cancellation support, including cancellation of associated workflow runs when tasks are cancelled or expire. - Runs agent tasks through the tool-task path. Agent tasks that pause for tool approval return an error result. - Adds optional `onCancel(context)` hooks to the in-memory and background task stores. - Adds workflow and agent task tests, tracing coverage, reference documentation, and a changeset. ## Validation The PR description reports three successful runs of `pnpm --filter ./packages/mcp test:server`, with 421 passing tests per run. It also reports clean TypeScript, oxlint, and oxfmt checks, plus manual checks in the showcase playground. These results were not independently verified. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
f548c12cfb |
feat(mcp): keep MCP tool tasks in Mastra background-task storage (#28521)
Closes #28337. > **Stacked:** base is `daniel/mcp-tasks-3a-server-tools` (#28420). Until they merge, this diff also contains the core commits from the stack **3b (#28425) → 3b2 (#28507) → 3b3 (#28590)**. To see only this PR's changes, use the commits listed below (the latest core merge is ` |
||
|
|
e80dd64c83 |
fix(mcp): accept any MCP task createdAt in MCPClient (#28899)
## Summary Follow-up to #28343 (MCP Tasks client), addressing two CodeRabbit threads that came in after it merged. **Valid ISO 8601 `createdAt` no longer fails the call.** #28343 rejected any task whose `createdAt` `Date.parse` can't read. That includes valid ISO 8601 basic format such as `20261029T120000Z`, so a tool call against a server using it failed outright. The schema now accepts any string. When `createdAt` doesn't parse, `waitForTask` counts the TTL from when it started waiting. That keeps the TTL backstop working and stops an unreadable timestamp from turning the outage limit into `NaN`, which used to make the wait poll forever. **Disconnect test checks every request.** The "does not reconnect after disconnect" test counted only `initialize`, but a reconnect can go through `server/discover` instead. It now asserts no request of any kind reaches the server after the call ends. ## Test plan - `wait.test.ts`: new "counts the TTL from when it first saw the task when createdAt does not parse". Without the fix the vitest worker hangs in an endless poll loop and crashes. - `schemas.test.ts`: accepts `20261029T120000Z`; failed before the fix. - `tasks.test.ts` disconnect test: reverting the #28343 disconnect fix in `client.ts` makes it time out. - `pnpm --filter ./packages/mcp test:client` 557 passed (x2); `test:server` 251 passed; `tsc --noEmit` clean; oxlint/prettier clean; Vale (CI config) 0 errors on `mcp-client.mdx`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 This change lets the MCP client accept task timestamps that JavaScript cannot parse. If it cannot parse a timestamp, the client starts the task’s time limit when it begins waiting, so it can still stop waiting when the limit expires. ## Changes - The task schema accepts any string for `createdAt`, including `20261029T120000Z`. - `waitForTask` uses `createdAt` to calculate the TTL. If parsing fails, it uses the time waiting began. - Polling waits stop at the TTL deadline. The client polls at the deadline before reporting expiration. - The TTL caps the wait between polls. It does not end a poll or other operation that is already in progress. - The disconnect test checks for any request after the pending call fails, not only `initialize` requests. - The documentation explains the TTL fallback when the client cannot parse `createdAt`. ## Validation The PR description reports 557 client tests passed twice, 251 server tests passed, and clean type-checking, lint, formatting, and documentation checks. These checks were not independently run. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
e30d29bb8f |
feat(mcp): MCPServer serves MCP Tasks for tools (#28420)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
76f4110887 |
feat(mcp): MCPClient can wait for MCP Tasks from remote servers (#28343)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
096e246ad7 |
feat(mcp): internal wire layer and task store for MCP Tasks (#28340)
Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
f6cd11f348 |
chore(deps): lock file maintenance (#28672)
This PR contains the following updates: | Update | Change | |---|---| | lockFileMaintenance | All locks refreshed | --- > [!WARNING] > Some dependencies could not be looked up. Check the [Dependency Dashboard](../issues/9505) for more information. 🔧 This Pull Request updates lock files to use the latest dependency versions. --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - "before 6am on wednesday" - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://redirect.github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xOTAuMCIsInVwZGF0ZWRJblZlciI6IjQ0LjE5MC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJhdXRvbWF0aW9uIl19--> --------- Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
07c1bf2362 |
chore(deps): update dependency @ai-sdk/provider-utils@>=3.0.0 <3.0.38 to v3.0.42 (#28773) | ||
|
|
f2ad3844f3 |
chore(deps): update opentelemetry (#28581)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: mastra-platform[bot] <284800079+mastra-platform[bot]@users.noreply.github.com> |
||
|
|
6deb7c0a1e |
chore(security): Vanta 2026-10-28 - qs 6.16.1, @modelcontextprotocol/node 2.1.1 floors (#28716)
Refs mastra-ai/platform#2931 Vanta remediation pass for 2026-10-28. It follows #28325, which has merged. ## 2026-10-28 update Today's live Vanta export added 3 advisory IDs on `mastra-ai/mastra` (GitHub/Dependabot). This PR fixes the two that have a published fix and leaves deepmerge, which has none. | Package | From → To | Finding | Where | How | |---|---|---|---|---| | qs | 6.16.0 → 6.16.1 | CVE-2026-110816 / GHSA-6pq8-jhm2-2vcw (Medium ×4) | root `pnpm-lock.yaml`, 9 `e2e-tests/*` lockfiles, `scripts/gh-issue-triage/package-lock.json` | Raised the existing floors `qs@>=6.7.0 <6.16.0: 6.16.0` → `<6.16.1: 6.16.1` and `'qs@<6.7.0': 6.16.0` → `6.16.1`. Raised the npm override in gh-issue-triage. | | @modelcontextprotocol/node | 2.0.0 → 2.1.1 | GHSA-f897-62hf-6gxq (High ×2; HTTP transports had no body-size or batch-length limit) | root `pnpm-lock.yaml` (published `@mastra/mcp` 1.18.0, used as `mcp-legacy`), `scripts/gh-issue-triage/package-lock.json` | New pnpm override `'@modelcontextprotocol/node@>=2.0.0 <2.1.0': 2.1.1` and a new npm override in gh-issue-triage. I used 2.1.1 rather than 2.1.2 because 2.1.2 needs a `@modelcontextprotocol/server` peer of `^2.4.0`, while `@mastra/mcp` 1.18 resolves server 2.3.1. `packages/mcp` itself already uses node 2.1.2. | - Both versions are older than the 1-day `minimumReleaseAge`: qs 6.16.1 was published 10-14 and node 2.1.1 on 10-02. I did not use qs 6.16.2 (10-27), which is too new. - No floors or overrides were removed; existing ones were only raised. - `pnpm install --frozen-lockfile --lockfile-only` passes at the root. Each nested e2e workspace was regenerated with `pnpm install --lockfile-only`. - Added the empty changeset `.changeset/vanta-2026-10-28-security-floors.md`. No published package changes. - After this change, osv-scanner over all 33 lockfiles reports only the documented leftovers: - zod 3.25.76 (zod v3 compat line on purpose) - ai 4.3.19 / `@ai-sdk/provider-utils` 2.2.8 (vendored v4 line) - `@azure/msal-node` 5.6.0 / 6.0.1 (fix 7.1.0 needs majors in identity and teams) - `@opentelemetry/core` 1.30.1 (needs pubsub 6) - extract-zip 2.0.1 (no patched release) - deepmerge 4.3.1 (CVE-2026-93753 / GHSA-gcqx-w48m-w2h4; no patched release, 4.3.1 is the latest) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## ELI5 This PR updates dependency rules and package versions to use newer releases, including security fixes for `qs` and `@modelcontextprotocol/node`. It also updates AI SDK dependencies and does not include published package changes. ## Summary - Raise the `qs` override target to `6.16.1` in the root and e2e workspaces and in `scripts/gh-issue-triage`. - Add an `@modelcontextprotocol/node` override at `2.1.1` in the root workspace and `scripts/gh-issue-triage`. - Update AI SDK dependency versions across package manifests and add a changeset describing the provider-utils update. - Add an empty changeset for the security-only dependency updates. <!-- end of auto-generated comment: release notes by coderabbit.ai --> ## Update 2026-10-28 (afternoon) - Merged origin/main (clean). - Bumped the AI SDK v5 compat line from @ai-sdk/provider-utils 3.0.41 to 3.0.42 (patch, published 2026-10-21; it blocks `.internal` hostnames in download URL validation and encodes provider-returned IDs in request paths). This addresses the Aikido /mastra Highs AIKIDO-2026-10990 and AIKIDO-2026-10981: - ai 5.0.277 → 5.0.282, @ai-sdk/gateway 2.0.168 → 2.0.173 (vendored ai_v5) - anthropic 2.0.109 → 2.0.110, google 2.0.103 → 2.0.106, groq 2.0.58 → 2.0.59, openai 2.0.135 → 2.0.137, openai-compatible 1.0.58 → 1.0.59, xai 2.0.99 → 2.0.100 - Nested lockfiles updated: memory/integration-tests and playground/e2e/kitchen-sink. - No new overrides. Changeset: `vanta-2026-10-28-ai-sdk-v5-provider-utils.md`. |
||
|
|
29747ebd1d |
chore(deps): update better-auth monorepo to v1.7.13 (#28538)
This PR contains the following updates: | Package | Type | Update | Change | Pending | |---|---|---|---|---| | [@better-auth/drizzle-adapter@<1.7.7](https://www.better-auth.com/docs/adapters/drizzle) ([source](https://redirect.github.com/better-auth/better-auth/tree/HEAD/packages/drizzle-adapter)) | pnpm-workspace.overrides | patch | [`1.7.7` → `1.7.13`](https://renovatebot.com/diffs/npm/@better-auth%2fdrizzle-adapter@<1.7.7/1.7.7/1.7.13) | `1.7.14` | | [better-auth](https://better-auth.com) ([source](https://redirect.github.com/better-auth/better-auth/tree/HEAD/packages/better-auth)) | pnpm-workspace.overrides | patch | [`^1.7.7` → `^1.7.13`](https://renovatebot.com/diffs/npm/better-auth/1.7.7/1.7.13) | `1.7.14` | | [better-auth](https://better-auth.com) ([source](https://redirect.github.com/better-auth/better-auth/tree/HEAD/packages/better-auth)) | dependencies | patch | [`^1.7.12` → `^1.7.13`](https://renovatebot.com/diffs/npm/better-auth/1.7.12/1.7.13) | `1.7.14` | --- > [!WARNING] > Some dependencies could not be looked up. Check the [Dependency Dashboard](../issues/9505) for more information. --- ### Release Notes <details> <summary>better-auth/better-auth (@​better-auth/drizzle-adapter@<1.7.7)</summary> ### [`v1.7.13`](https://redirect.github.com/better-auth/better-auth/blob/HEAD/packages/drizzle-adapter/CHANGELOG.md#1713) [Compare Source](https://redirect.github.com/better-auth/better-auth/compare/v1.7.12...v1.7.13) ### [`v1.7.12`](https://redirect.github.com/better-auth/better-auth/blob/HEAD/packages/drizzle-adapter/CHANGELOG.md#1712) [Compare Source](https://redirect.github.com/better-auth/better-auth/compare/v1.7.11...v1.7.12) ### [`v1.7.11`](https://redirect.github.com/better-auth/better-auth/blob/HEAD/packages/drizzle-adapter/CHANGELOG.md#1711) [Compare Source](https://redirect.github.com/better-auth/better-auth/compare/v1.7.10...v1.7.11) ### [`v1.7.10`](https://redirect.github.com/better-auth/better-auth/blob/HEAD/packages/drizzle-adapter/CHANGELOG.md#1710) [Compare Source](https://redirect.github.com/better-auth/better-auth/compare/v1.7.9...v1.7.10) ### [`v1.7.9`](https://redirect.github.com/better-auth/better-auth/blob/HEAD/packages/drizzle-adapter/CHANGELOG.md#179) [Compare Source](https://redirect.github.com/better-auth/better-auth/compare/v1.7.8...v1.7.9) ### [`v1.7.8`](https://redirect.github.com/better-auth/better-auth/blob/HEAD/packages/drizzle-adapter/CHANGELOG.md#178) [Compare Source](https://redirect.github.com/better-auth/better-auth/compare/v1.7.7...v1.7.8) ##### Patch Changes - [#​11512](https://redirect.github.com/better-auth/better-auth/pull/11512) [`4175b34`]( |