# Mastra

Connect a Mastra agent to the OrcaRouter MCP server with MCPClient, so it can search the tool catalog and run what it finds.

|  |  |
| --- | --- |
| Kind | framework |
| Connects through | mcp |
| Docs | <https://mastra.ai/docs/tools-mcp/mcp-overview> |

## Install

1. Install the packages: `npm install @mastra/core @mastra/mcp @ai-sdk/openai`.
2. Set `ORCAROUTER_API_KEY` to an API key from your OrcaRouter console; Node.js 18 or later runs the MCP server through `npx`.
3. Register the server with `MCPClient` and give its tools (`listTools()`) to your agent.

## Code

### An agent with the OrcaRouter MCP server

```typescript
import { createOpenAI } from "@ai-sdk/openai";
import { Agent } from "@mastra/core/agent";
import { MCPClient } from "@mastra/mcp";

const mcp = new MCPClient({
  servers: {
    orcarouter: {
      command: "npx",
      args: ["-y", "@orcarouter/mcp"],
      env: { ORCAROUTER_API_KEY: process.env.ORCAROUTER_API_KEY ?? "" },
    },
  },
});

const orcarouter = createOpenAI({
  baseURL: "https://api.orcarouter.ai/v1",
  apiKey: process.env.ORCAROUTER_API_KEY,
});

export const researcher = new Agent({
  id: "researcher",
  name: "Researcher",
  instructions: "Find a tool in the OrcaRouter catalog for each question, then run it.",
  model: orcarouter.chat("openai/gpt-5-mini"),
  tools: await mcp.listTools(),
});
```

### Ask it something

```typescript
const answer = await researcher.generate("How many followers does @nasa have on TikTok?");
console.log(answer.text);
```

## Recipes

- [Track competitor TikTok accounts](https://www.orcarouter.ai/tools/recipes/track-competitor-tiktok-accounts.md): Pull each competitor's TikTok profile, find its latest videos and read what viewers say, in three tool calls an agent can repeat every week.
- [Monitor brand mentions on the web and TikTok](https://www.orcarouter.ai/tools/recipes/monitor-brand-mentions.md): Search the web and TikTok for your brand, then read the comments under the posts that mention it: a daily brand check an agent can run on its own.
- [Enrich a lead list](https://www.orcarouter.ai/tools/recipes/enrich-a-lead-list.md): Turn a list of company domains into firmographics, a contact's work email and a recent news hook, with one API key.

## Related integrations

- [Vercel AI SDK](https://www.orcarouter.ai/tools/integrations/vercel-ai-sdk.md): Turn OrcaRouter tools into AI SDK tools with jsonSchema() and let generateText call them over several steps.
- [Claude Code](https://www.orcarouter.ai/tools/integrations/claude-code.md): Add the OrcaRouter MCP server to Claude Code with one command; Claude can then search the tool catalog and run tools while it works.
- [LangChain](https://www.orcarouter.ai/tools/integrations/langchain.md): Load OrcaRouter tools as LangChain tools from the functions export and give them to any LangChain agent; each call runs the tool through OrcaRouter.

---

Markdown version of https://www.orcarouter.ai/tools/integrations/mastra
