composio icon indicating copy to clipboard operation
composio copied to clipboard

Composio mastra provider gettools failed

Open samjoshuva opened this issue 2 months ago • 17 comments

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)
}
Image

samjoshuva avatar Oct 28 '25 07:10 samjoshuva

Hi @samjoshuva, thanks for sharing the details. Will check and get back

abhishekpatil4 avatar Oct 28 '25 09:10 abhishekpatil4

@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)?

abhishekpatil4 avatar Oct 28 '25 11:10 abhishekpatil4

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?

steffendsommer avatar Oct 29 '25 07:10 steffendsommer

I think this problem would be solved by https://github.com/ComposioHQ/composio/pull/2066

jkomyno avatar Oct 29 '25 11:10 jkomyno

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

yairyairyair avatar Oct 30 '25 16:10 yairyairyair

I just downgraded to zod 3 it worked. Should be updating package to zod 4.

samjoshuva avatar Oct 30 '25 16:10 samjoshuva

Should be fixed in our latest release. Lookout for the following versions:

@composio/[email protected]
@composio/[email protected]

haxzie avatar Oct 31 '25 05:10 haxzie

I updated to these and same problem....

yairyairyair avatar Oct 31 '25 17:10 yairyairyair

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.

jkomyno avatar Nov 04 '25 05:11 jkomyno

Still seeing this with composio/core and composio/mastra v0.2.3 (and mastra v0.23.3)

steffendsommer avatar Nov 04 '25 11:11 steffendsommer

Correct, updated to latest for both v0.2.3 and it still does not work and is with same error.

yairyairyair avatar Nov 04 '25 12:11 yairyairyair

@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

yairyairyair avatar Nov 04 '25 13:11 yairyairyair

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

a9a4k avatar Nov 04 '25 20:11 a9a4k

Bump same with these. On the latest of everything

nsoliven avatar Nov 09 '25 01:11 nsoliven

@nsoliven can you share a bit more info around the package versions, LLM models and libraries you are using?

haxzie avatar Nov 10 '25 08:11 haxzie

Environment

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?

nsoliven avatar Nov 11 '25 21:11 nsoliven

@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 🙏

steffendsommer avatar Nov 24 '25 13:11 steffendsommer