Mastra is the opinionated TypeScript framework for agents — RAG, observability, and Model Context Protocol support all built in rather than bolted on. What sets its MCP story apart is that it works both directions: MCPClient lets a Mastra agent consume any server's tools, and MCPServer turns your own agents and workflows into an MCP server that Cursor, Windsurf, or Claude Desktop can call. Here's each half.
Consuming tools with MCPClient
MCPClient connects to one or many MCP servers and hands their tools, resources, and prompts to an agent — it also handles elicitation requests, so servers that need a human-in-the-loop confirmation work correctly. Each server is configured with a command for a local npx package or a url for a remote HTTP endpoint:
import { MCPClient } from "@mastra/mcp";
const mcp = new MCPClient({
servers: {
github: { url: new URL("https://api.githubcopilot.com/mcp/") },
filesystem: {
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/abs/path"],
},
},
});
Then call .listTools() in the agent's tools parameter. Mastra loads the definitions from every configured server and makes them available to the model, exactly as if you had written the tools yourself. Point it at GitHub, Firecrawl, or Supabase and the agent gains those capabilities with no glue code.
Exposing your work with MCPServer
The reverse is where Mastra is unusual. MCPServer publishes your existing Mastra tools, agents, and workflows as a Model Context Protocol server so any MCP client can drive them. Each agent is automatically converted into a tool named ask_<agentId>, and each workflow becomes run_<workflowKey> with the workflow's input schema becoming the tool's input schema. It supports both stdio for local use and SSE over HTTP for remote clients — meaning a workflow you built for your own app becomes a tool that Claude Desktop or Cursor can invoke, no rewrite required.
Why both directions matter
Most frameworks only consume MCP. Being a server too means Mastra sits cleanly in a mesh: your agent uses upstream servers for capabilities, and simultaneously offers its own higher-level workflows downstream to other agents. That's the composition pattern behind multi-agent orchestration — small servers wired into larger ones — and it's how a team turns internal automation into reusable tooling. When you publish, follow publish your MCP server to the registry.
Where to go next
Compare Mastra's approach with other native clients: LangGraph for graph orchestration, the Vercel AI SDK for a lighter TypeScript path, and CrewAI for role-based crews. Choose a transport with Streamable HTTP vs SSE vs stdio, keep third-party servers vetted with MCP security best practices, and grab a starting stack from the frontend React loadout.