Using Composio With Mastra

Composio enables your Mastra agents to connect with many tools!

Goal: Star a repository on GitHub with a Mastra agent

Star A Repository on Github

In this example, we will use Mastra to star a repository on Github using Composio Tools

1

Create Mastra project

JavaScript
$npx create-mastra@latest

You can get the full Mastra installation instructions here

2

Install @mastra/mcp

JavaScript
$npm install @mastra/mcp@latest
3

Import Libraries & Setup MCPConfiguration

The SSE URL that’s generated for Cursor is compatible with Mastra - you can use it directly in your configuration

JavaScript
1import { MCPConfiguration } from "@mastra/mcp";
2import { Agent } from "@mastra/core/agent";
3import { openai } from "@ai-sdk/openai";
4
5const mcp = new MCPConfiguration({
6 servers: {
7 github: {
8 url: new URL("https://mcp.composio.dev/github/[private-url-path]"),
9 },
10 },
11});
4

Execute the Agent

JavaScript
1const mcp = new MCPConfiguration({
2 servers: {
3 github: {
4 url: new URL("https://mcp.composio.dev/github/[private-url-path]"),
5 },
6 },
7});
8
9const agent = new Agent({
10 name: "CLI Assistant",
11 instructions: "You help users star GitHub repositories",
12 model: openai("gpt-4o-mini"),
13 tools: await mcp.getTools(),
14});
15
16const stream = await agent.stream("Please star the repository 'composiohq/composio'");
17
18for await (const chunk of stream.textStream) {
19 process.stdout.write(chunk);
20}