Providers

Mastra

Markdown

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

npm install @composio/mastra

You can specify the provider in the constructor.

import { Composio } from "@composio/core";
import { MastraProvider } from "@composio/mastra";
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";

const composio = new Composio({
  provider: new MastraProvider(),
});

Usage

The tools are passed to the agent as a parameter.

const userId = "john doe";

const tools = await composio.tools.get(
  userId,
  {
    toolkits: ["SUPABASE"],
  }
);

const agent = new Agent({
  id: "supabase-agent",
  name: "Supabase Agent",
  instructions: "You think therefore you are.",
  model: openai("gpt-4.1"),
  tools: tools,
});

const { text } = await agent.generate([
  { role: "user", content: "Tell me about my Supabase project" },
]);

console.log("\n🤖 Agent Response:\n");
console.log(text);

Usage: Direct MCP Servers

You can also use Composio MCP servers directly with Mastra's MCPClient.

Composio MCP servers only support Streamable HTTP transport.

import { MCPClient } from "@mastra/mcp";
import { openai } from "@ai-sdk/openai";
import { Agent } from "@mastra/core/agent";
import { Composio } from "@composio/core";

// Initialize Composio
const composio = new Composio();

// Create MCP server with GitHub, Linear, and Notion tools
const server = await composio.mcp.create(
  "dev-automation-server",
  {
    toolkits: [
      { toolkit: "github", authConfigId: "ac_github_id" },
      { toolkit: "linear", authConfigId: "ac_linear_id" },
      { toolkit: "notion", authConfigId: "ac_notion_id" }
    ],
    allowedTools: [
      "GITHUB_LIST_ISSUES", "GITHUB_CREATE_ISSUE",
      "LINEAR_CREATE_ISSUE", "LINEAR_UPDATE_ISSUE",
      "NOTION_CREATE_PAGE", "NOTION_UPDATE_PAGE"
    ]
  }
);

// Generate MCP instance for user
const instance = await server.generate("user@example.com");

// Create MCP client with Composio server
export const mcpClient = new MCPClient({
  id: "composio-mcp-client",
  servers: {
    composio: { url: new URL(instance.url) },
  }
});

// Create a development workflow agent
export const devAgent = new Agent({
  id: "dev-assistant",
  name: "Dev Assistant",
  description: "AI assistant for development workflow automation",
  instructions: "Help manage GitHub repos, Linear issues, and Notion documentation.",
  model: openai("gpt-4-turbo"),
  tools: await mcpClient.getTools()
});

// Example: Automate development workflow
(async () => {
  const response = await devAgent.generate(
    "Review open GitHub issues, create Linear tasks for bugs labeled 'priority', and update the Notion roadmap page"
  );
  console.log(response.text);
})();