Mastra Provider

Mastra is a TypeScript native framework for building agents with tools and MCPs. It expects tools to be in the following format:

  • Inputs: What information the tool needs to run (defined with an inputSchema, often using Zod).
  • Outputs: The structure of the data the tool returns (defined with an outputSchema).
  • Execution Logic: The code that performs the tool’s action.
  • Description: Text that helps the agent understand what the tool does and when to use it.

More documentation here

The Mastra provider formats the Composio tools into this format along with the execution logic so that agents can call and execute the Composio tools.

Setup

TypeScript
1npm install @composio/mastra

You can specify the provider in the constructor.

TypeScript
1import { Composio } from "@composio/core";
2import { MastraProvider } from "@composio/mastra";
3import { Agent } from "@mastra/core/agent";
4import { openai } from "@ai-sdk/openai";
5
6const composio = new Composio({
7 provider: new MastraProvider(),
8});

Usage

The tools are passed to the agent as a parameter.

TypeScript
1const userId = "john doe";
2
3const tools = await composio.tools.get(
4 userId,
5 {
6 toolkits: ["SUPABASE"],
7 }
8);
9
10const agent = new Agent({
11 name: "Supabase Agent",
12 instructions: "You think therefore you are.",
13 model: openai("gpt-4.1"),
14 tools: tools,
15});
16
17const { text } = await agent.generate([
18 { role: "user", content: "Tell me about my Supabase project" },
19]);
20
21console.log("\n🤖 Agent Response:\n");
22console.log(text);