Blog

Announcing MCP Server Support in Mastra

We're excited to announce MCP Server support in Mastra, available now in our latest stable tagged release (0.9.0).

Now you can convert your Mastra tools into MCP-compatible servers, and share your tools with any MCP client.

If you already have an agent in Mastra, create an MCP server in five lines of code.

If you don't, you can write the tools in Typescript, then create your MCP server in five lines of code.

Creating an MCP Server

Here's how to get started:

// stdio.ts
#!/usr/bin/env node

import { MCPServer } from "@mastra/mcp";
import {
  myFirstTool,
  mySecondTool,
  // ... more tools
} from './tools';

const server = new MCPServer({
  name: "my-mcp-server",
  version: "1.0.0",
  tools: { 
    myFirstTool,
    mySecondTool,
    // ... more tools
  },
});

server.startStdio().catch((error) => {
  console.error("Error running MCP server:", error);
  process.exit(1);
});

Publishing and Using Your MCP Server

See the Deploying an MCPServer example in the examples section of the docs for a full workflow:

  1. Building your MCP server with Mastra tools
  2. Publishing it as an NPM package
  3. Using it from different MCP clients

This example provides step-by-step instructions and best practices for deployment. Note that since Mastra already lets you create an MCP client, you can now bundle your MCP server with your Mastra agent.

Kudos

Thanks to Alana Goyal for spending a lot of her weekend on Slack with Shane helping us debug subtle differences in how different MCP clients implement the protocol.

What's next

Some follow-up work we're working on:

  • Hosted your MCP servers without NPM publishing in Mastra Cloud
  • Enhanced compatibility across all MCP clients
  • Better debugging tools for MCP server development
  • Improved SSE (Server-Sent Events) support

We're excited to see what you'll build! MCP on 🚀

Share

Stay up to date