Skip to content

feat: update mastra ai sdk#81

Merged
caiopizzol merged 13 commits into
mainfrom
caiopizzol/eng-3074-ai-sdk-upgrade-with-mastra
May 30, 2026
Merged

feat: update mastra ai sdk#81
caiopizzol merged 13 commits into
mainfrom
caiopizzol/eng-3074-ai-sdk-upgrade-with-mastra

Conversation

@caiopizzol

@caiopizzol caiopizzol commented Jan 26, 2026

Copy link
Copy Markdown
Collaborator

Added a proper test suite for the AI SDK v5 / Mastra upgrade. We had zero tests for the Mastra and MCP adapters, and the existing E2E tests require OpenAI credits to run.

Created 124 tests using Bun's test runner + MSW for HTTP mocking - no API calls needed, runs in ~600ms. Covers all three adapters: schema validation, tool structure, requestContext injection for Mastra, and MCPResponse format for the MCP server.

Run with bun test from sdk/. Unit tests in test/unit/, integration tests in test/integration/.

image

@linear

linear Bot commented Jan 26, 2026

Copy link
Copy Markdown

@caiopizzol caiopizzol requested a review from dionlow January 26, 2026 17:24
@caiopizzol caiopizzol self-assigned this Jan 26, 2026
@dionlow

dionlow commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Hey @caiopizzol, thanks for starting this! Can you resolve conflicts first before review? Also were able to test any of the tools through the mastra adapter; if so can you document it in the pr?

@laurenzlong laurenzlong removed their request for review January 29, 2026 19:53
@caiopizzol

Copy link
Copy Markdown
Collaborator Author

Hey @caiopizzol, thanks for starting this! Can you resolve conflicts first before review? Also were able to test any of the tools through the mastra adapter; if so can you document it in the pr?

Added tests + checked e2e exec @dionlow

GTG

- Add `types: ["node"]` to tsconfig to prevent auto-loading @types/bun
- Add `as any` to remaining inputSchema props in aisdk.ts to avoid
  deep generic instantiation with ai SDK v6's tool() function
- Add pnpm.overrides to force all packages to use zod v4, eliminating
  the duplicate zod v3 compat type tree that was doubling memory usage
- Remove @types/bun from sdk devDeps (only needed by Bun runtime, not tsc)
ToolExecutionContext.requestContext changed from Map<string, unknown>
to RequestContext<unknown> in v1.0. Remove explicit type annotations
and let TypeScript infer from createTool's generic.
…mports

Rollup exact string matching doesn't match subpath imports like
@mastra/core/tools or @modelcontextprotocol/sdk/server/index.js.
Use regex patterns to match all subpaths.
@dionlow

dionlow commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

looking now

Comment thread sdk/lib/adapters/aisdk.ts
Comment thread sdk/lib/adapters/mastra.ts Outdated
Comment thread sdk/lib/adapters/mastra.ts Outdated
Comment thread sdk/lib/adapters/mastra.ts Outdated

@dionlow dionlow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the update is pretty solid.

Two things to address

  1. providerWorkspaceRef is missing from the mastra startOAuth tool (sdk/lib/adapters/mastra.ts:255). A consumer using the mastra adapter can't trigger OAuth for providers that require a workspace ref (e.g., Salesforce subdomains) — it'll silently be ignored even though the schema accepts it.

  2. Integration tests for the mastra adapter only execute startOAuth — the other 7 tools only have structural checks (correct id, schema references), but would be good to add the one more execute test as well to validate that credentials from requestContext actually flow through to the API calls. The mock handlers in sdk/test/mocks/handlers.ts seem to support and aren't wired up in the mastra test file. (can be followup).

Comment thread examples/vercel-agent.ts Outdated
- fix .args to .input for AI SDK v6 tool calls in example
- add providerWorkspaceRef support to mastra startOAuth
- extract resolveCredentials helper for consistent fallback logic
- add comment explaining as any casts on inputSchema
Wire all 3 integration tests through setupMocks() and shared
handlers instead of defining inline handlers and lifecycle hooks.
Verify requestContext > env vars > input params credential resolution,
and test createRecord/sendRequest execute paths through MSW.
Comment thread sdk/lib/adapters/aisdk.ts
export const sendReadRequest = tool({
description: sendReadRequestToolDescription,
inputSchema: sendReadRequestInputSchema,
inputSchema: sendReadRequestInputSchema as any,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking / can be followup.

[sdk/lib/adapters/aisdk.ts:128,220,259] as any casts on inputSchema for checkConnection, sendRequest, and sendReadRequest suppress type checking between Zod v4 schemas and AI SDK v6's expected types.

If the schemas drift, runtime errors won't be caught at compile time.

suggestion: consider a typed adapter function (e.g. toAISDKSchema(schema)) that narrows the as any to a single location, or add a unit test that round-trips each cast schema through AI SDK's validation to catch drift early.

@dionlow dionlow left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look solid, added a minor suggestion as followup. Thanks Caio!

@caiopizzol caiopizzol merged commit 62503dc into main May 30, 2026
1 check passed
@caiopizzol caiopizzol deleted the caiopizzol/eng-3074-ai-sdk-upgrade-with-mastra branch May 30, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants