Composio mastra provider gettools failed
Trying to instantiate mastra with composio teams tools facing this error.
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
import retrievalInstructions from "../../prompts/retrieval-instructions";
import { Composio } from '@composio/core';
import { MastraProvider } from '@composio/mastra';
export const retrievalAgent = new Agent({
name: "Retrieval",
id: "retrieval-agent",
description:
"The Retrieval agent retrieves information from the database using semantic layer context.",
instructions: retrievalInstructions,
model: openai("gpt-4.1-mini"),
tools: async ({ runtimeContext }) => {
const composio = new Composio({
provider: new MastraProvider(),
});
// retrieve userId and activeAccount from the runtimeContext
const userId = runtimeContext.get<'userId', string>('userId');
const activeAccount = runtimeContext.get<
'activeAccount',
Awaited<ReturnType<typeof composio.connectedAccounts.list>>['items'][number]
>('activeAccount');
// return empty set of tools if activeAccount isn't present
if (!activeAccount) return {};
// fetch composio tools and dynamically use them in the agent
const composioTools = await composio.tools.get(userId, {
toolkits: [activeAccount.toolkit.slug],
});
return composioTools;
},
});
ERROR
Error getting serialized tool {
toolId: 'MICROSOFT_TEAMS_TEAMS_GET_MESSAGE',
error: TypeError: Cannot read properties of undefined (reading 'def')
at JSONSchemaGenerator.process (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/node_modules/zod/v4/core/to-json-schema.js:15:33)
at Module.toJSONSchema (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/node_modules/zod/v4/core/to-json-schema.js:811:9)
at zodToJsonSchema (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/node_modules/@mastra/schema-compat/dist/chunk-GWTUXMDD.js:8:17)
at file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:32802:44
at Array.reduce (<anonymous>)
at getSerializedAgentTools (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:32787:38)
at formatAgent (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:32981:38)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async getAgentByIdHandler (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:37580:18)
at async dispatch (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:5576:17)
}
Error getting serialized tool {
toolId: 'MICROSOFT_TEAMS_TEAMS_LIST',
error: TypeError: Cannot read properties of undefined (reading 'def')
at JSONSchemaGenerator.process (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/node_modules/zod/v4/core/to-json-schema.js:15:33)
at Module.toJSONSchema (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/node_modules/zod/v4/core/to-json-schema.js:811:9)
at zodToJsonSchema (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/node_modules/@mastra/schema-compat/dist/chunk-GWTUXMDD.js:8:17)
at file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:32802:44
at Array.reduce (<anonymous>)
at getSerializedAgentTools (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:32787:38)
at formatAgent (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:32981:38)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async getAgentByIdHandler (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:37580:18)
at async dispatch (file:///Users/samjoshuva/Documents/Projects/deepspot/deepspot-query-executor/.mastra/output/index.mjs:5576:17)
}
Hi @samjoshuva, thanks for sharing the details. Will check and get back
@samjoshuva We weren't able to reproduce the issue, could you please share the version of packages you're using & the reproducible steps (looks like you're using some platform)?
Seeing the same running Mastra 0.21.x. I believe the Composio Mastra provider is pinned to Mastra 0.16.x - could there be compatibility issues given all the changes to AI SDK 5 and Zod 4 lately in Mastra?
I think this problem would be solved by https://github.com/ComposioHQ/composio/pull/2066
Same problem, also i think iFound the problem, https://github.com/ComposioHQ/composio/blob/next/ts/packages/providers/mastra/src/index.ts#L96 These 2 lines of code, I removed the jsonSchemaToZodSchema calls (just return parameters without jsonSchemaToZodSchema) and it work with zod 4.
Bottom line problem is at @composio/mastra latest provider
I just downgraded to zod 3 it worked. Should be updating package to zod 4.
Should be fixed in our latest release. Lookout for the following versions:
@composio/[email protected]
@composio/[email protected]
I updated to these and same problem....
I updated to these and same problem....
Hi @yairyairyair, I was able to reproduce this problem with an older version of Composio, but not with the latest available. Can you please share a self-contained repository with the steps needed to reproduce the issue you're facing? Thanks.
Still seeing this with composio/core and composio/mastra v0.2.3 (and mastra v0.23.3)
Correct, updated to latest for both v0.2.3 and it still does not work and is with same error.
@jkomyno just try to use latest of everything. composio + mastra + @composio/mastra provider + zod 4 + vercel ai sdk 5. ANY example code that calls that tool will give error, meaning tool.execute or something like that
Same problem, also i think iFound the problem, https://github.com/ComposioHQ/composio/blob/next/ts/packages/providers/mastra/src/index.ts#L96 These 2 lines of code, I removed the jsonSchemaToZodSchema calls (just return parameters without jsonSchemaToZodSchema) and it work with zod 4.
Bottom line problem is at @composio/mastra latest provider
this fixed it for me as well
Bump same with these. On the latest of everything
@nsoliven can you share a bit more info around the package versions, LLM models and libraries you are using?
Environment
- @mastra/[email protected]
- @mastra/[email protected]
- @composio/[email protected]
- @composio/[email protected]
- [email protected]
- @ai-sdk/[email protected] (LLM provider)
- Model: google/gemini-2.5-flash-preview-09-2025
- Node: 20.x (Docker base image: node:20-alpine)
my temp workaround:
I implemented a local shim provider by copying the Mastra provider from @composio/mastra and removing the two jsonSchemaToZodSchema conversions before returning tool parameters (i.e., return the raw JSON Schema). With that change, tool serialization and execution work under Zod v4. I can share the minimal patch if helpful.
@nsoliven can you share a bit more info around the package versions, LLM models and libraries you are using?
@haxzie or @jkomyno any update on this? would love to get this fix in as it's blocking us from using composio. Appreciate the support 🙏