Repository navigation
chore(docs-mcp): Replace Mastra with the AI SDK - #2322
Merged
Merged
Conversation
Mastra was only used by the docs-mcp Worker, as a wrapper around the AI SDK it already depends on. Call generateText directly instead, which drops @mastra/core and its dependency tree from the Worker. The port keeps what Mastra 1.83 sent to OpenRouter and returned: - A local fallback model tries the primary model, the standard fallback, then Kimi on every step, and reports the model that answered. It retries retryable errors on every model but the last, at most twice per step, after 3 s or the provider's Retry-After (capped at 30 s), and backs off from 1 s on connection resets. It drops temperature for gpt-5.4. - The last step and the tailor synthesis pass send the tools with toolChoice none, and the synthesis history is the run's messages plus the instruction. - The features agent parses its JSON output with Mastra's rules. - Tool schemas, tool results, and tool input errors keep Mastra's format. Co-Authored-By: BYK <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
MathurAditya724
approved these changes
Nov 17, 2026
BYK
added a commit
that referenced
this pull request
Nov 17, 2026
…ry (#2352) `pnpm-lock.yaml` on `main` points to `@ai-sdk/[email protected]([email protected])`, but has no entry for it, so pnpm rejects the lockfile as broken. Two PRs merged one after the other, and each lockfile looked fine by itself: - #1754 bumped `@ai-sdk/anthropic` to `^3.0.137`. That made `@ai-sdk/anthropic` and `@ai-sdk/gateway` depend on `@ai-sdk/[email protected]`. That version was already in the lockfile because `@mastra/core` pulled it in. - #2322 removed `@mastra/core`. Its branch was cut before #1754, so its lockfile dropped `[email protected]` and `[email protected]`. Git merged the two lockfiles without a conflict, and `main` was left pointing at entries that no longer exist. This PR adds back the four missing entries: `packages` and `snapshots` for `@ai-sdk/[email protected]` and `@ai-sdk/[email protected]`. Nothing else in the lockfile changes, and Mastra stays out. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:local%3Aweb%3A720edeaf6006d91ce693aeda --> -- [View Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3A720edeaf6006d91ce693aeda) [[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A720edeaf6006d91ce693aeda/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <[email protected]>
7 tasks done
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Removes
@mastra/corefrom the privateapps/docs-mcpWorker. Mastra was only used there, as a wrapper around the AI SDK (ai5), which the Worker already depends on. The three agents now callgenerateTextdirectly. This drops 44 packages from the install and shrinks the Worker bundle from 14.8 MiB (2.74 MiB gzip) to 2.5 MiB (481 KiB gzip).This removes
@mastra/core, which #2318 bumped to clear the@modelcontextprotocol/serveradvisories. With Mastra gone, docs-mcp no longer pulls@modelcontextprotocol/serverin at all. The only copy left is the patched 2.4.0 that@sentry/mcp-coreand@sentry/mcp-cloudflaredepend on directly.The Worker's behavior stays the same as with Mastra 1.83.0 (what
mainruns now): same MCP tools, same/internal/docsAPI, same outputs, error messages, caching, span attributes, and metrics, and the same requests to OpenRouter. The exceptions are four deliberate differences, listed under Accepted differences.What changed
model-fallback.ts:createNativeModelFallbacks()now returns one AI SDK model instead of a Mastra model list. On every model call it tries the primary, thenFALLBACK_MODEL, thenKIMI_FALLBACK_MODEL, with the same retries Mastra 1.83 did (see below). It setsresponse.modelIdto the model that answered, sogetUsedModelIdand theagent.modelspan attribute keep working. When every model fails, it throws the last model's error. Like Mastra 1.83, it dropstemperatureforopenai/gpt-5.4, which Mastra's provider registry lists as not supporting it.generateTextwithstopWhen: stepCountIs(n)and the same model settings. The last step sends the tools withtoolChoice: "none". The tailor synthesis pass sends the run's response messages plus the instruction, with the tools andtoolChoice: "none", as Mastra 1.83 did.parseFeaturesOutput. It asks for the JSON schema response format on every step and only reads steps that have text, no tool calls, and no error. It throwsStructured output was truncated because the model finished with reason "length".for a step that was cut off. Otherwise it strips a<|message|>prefix or a```jsonfence, pulls the last JSON object out of surrounding prose, escapes raw control characters, repairs partial JSON, and throwsStructured output validation failed: - path: messageon a schema mismatch.tools.ts: the tools keep Mastra's wire format.minLengthmoves into the property description (constraints: minimum length 1), tool results are sent with sorted keys, and invalid tool input comes back to the model as Mastra's{ error, message, validationErrors }result. The comment about Mastra vendoring AI SDK schema types is gone.execaWorker stub and its wrangler alias, which only Mastra needed, and updated the README.Retry and fallback semantics
FALLBACK_MODEL→ Kimi, starting from the primary on every stepRetry-After/Retry-After-Msif longer, capped at 30 sECONNRESET, "socket hang up")maxRetries: 0)maxRetries: 0)Example: primary 503 three times, then the fallback 503 → primary, primary +3 s, primary +6 s, fallback, Kimi.
The old comment said Mastra retried each model 3 times through p-retry. In 1.83 the per-model
maxRetries: 0turns p-retry off, and the retries above come from Mastra's step-level retry instead. I replaced the comment.Accepted differences
BYK reviewed these four differences from Mastra 1.83.0 and accepted them as deliberate:
agent.tokens.*,agent.steps, and their metrics only differ in runs that retried.Errorinstead ofMastraError. The message is the same, but the Sentry issue type changes.[model-fallback] Error executing model …line is logged per failed attempt. The Worker doesn't send console logs to Sentry.via @BYK.
--
View Session [Sentry]