You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(server): handle provider-defined tools in /tools API endpoint (#13507)
The `/tools`, `/tools/:toolId`, and `/agents/:agentId/tools/:toolId`
endpoints crash when an agent has provider-defined tools like
`google.tools.googleSearch()` or `openai.tools.webSearch()`.
These tools have a lazy `inputSchema` function that returns an AI SDK
Schema object (not a Zod schema). The handler was blindly calling
`zodToJsonSchema(tool.inputSchema)` on them, which blows up with:
```
TypeError: Cannot read properties of undefined (reading 'typeName')
```
The fix detects provider-defined tools (via `tool.type ===
'provider-defined' || tool.type === 'provider'`) and resolves their lazy
schema to extract the `jsonSchema` property directly, skipping
`zodToJsonSchema` entirely. This reuses the same detection pattern
already in `prepare-tools.ts`.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Fixed /tools API crash when using provider-defined tools from external
AI SDKs (e.g., Google, OpenAI).
* **New Features**
* Added provider-defined tool detection to ensure correct tool
serialization and listing.
* **Tests**
* Added coverage for provider-defined tool recognition and serialization
across handlers.
* **Chores**
* Released @mastra/server minor and @mastra/core patch; tightened peer
dependency to require @mastra/core ≥ 1.7.1.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Added `isProviderDefinedTool` helper to detect provider-defined AI SDK tools (e.g. `google.tools.googleSearch()`, `openai.tools.webSearch()`) for proper schema handling during serialization.
Fixed /tools API endpoint crashing with provider-defined tools (e.g. `google.tools.googleSearch()`, `openai.tools.webSearch()`). These tools have a lazy `inputSchema` that is not a Zod schema, which caused `zodToJsonSchema` to throw `"Cannot read properties of undefined (reading 'typeName')"`.
0 commit comments