Mastra Social Media: Posta MCP & Tools for Mastra Agents
Give a Mastra agent the Posta MCP server as a tool source and post to eight social networks from any TypeScript app, Mastra Workflow step, or Mastra Cloud deployment. Or wrap the REST API with createTool() and Zod.
Why Posta + Mastra?
First-class MCP client
Mastra ships an
MCPClient. Point it at the Posta server and every Posta tool drops into your Agent.Typed tools end-to-end
Mastra's
createTool() takes Zod input/output schemas. Define a Posta posting tool once; every Agent and Workflow that uses it gets the same type safety.Workflows compose Posta calls
A Mastra Workflow can chain steps: research, draft, schedule via Posta — branching, parallel, all typed.
Closed loop via webhooks
HMAC callbacks fire on publish/fail. Trigger a follow-up Workflow that reads engagement and decides the next post.
Path 1 — Posta MCP via Mastra MCPClient (recommended)
Mastra's MCP client loads any MCP server's tools and exposes them as a toolset on your Agent.
npm i @mastra/core @mastra/mcp @ai-sdk/anthropic
// src/mastra/index.ts
import { Mastra } from '@mastra/core/mastra'
import { Agent } from '@mastra/core/agent'
import { MCPClient } from '@mastra/mcp'
import { anthropic } from '@ai-sdk/anthropic'
const mcp = new MCPClient({
servers: {
posta: {
command: 'npx',
args: ['-y', 'posta-mcp'],
env: { POSTA_API_TOKEN: process.env.POSTA_API_TOKEN! },
},
},
})
const publisher = new Agent({
name: 'social-publisher',
instructions: "Draft and schedule social posts. Match each platform's voice.",
model: anthropic('claude-sonnet-4-6'),
tools: await mcp.getTools(),
})
export const mastra = new Mastra({ agents: { publisher } })
// later:
const res = await publisher.generate(
'Draft a LinkedIn post and a Bluesky post about our v2 launch and schedule both for tomorrow 9am CET.'
)
console.log(res.text)Path 2 — createTool() around the REST API
Use when you want one deterministic call exposed to the agent — no MCP transport, no tool discovery.
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'
const POSTA = 'https://api.getposta.app'
const headers = () => ({
'Authorization': `Bearer ${process.env.POSTA_API_TOKEN}`,
'Content-Type': 'application/json',
})
export const schedulePost = createTool({
id: 'schedule-post',
description: 'Create a Posta draft on the given social accounts and schedule it. scheduledAt is ISO 8601.',
inputSchema: z.object({
caption: z.string(),
socialAccountIds: z.array(z.number()),
scheduledAt: z.string(),
mediaIds: z.array(z.string()).optional(),
}),
outputSchema: z.object({ id: z.string(), scheduledAt: z.string() }),
execute: async ({ context }) => {
// Step 1 — create the draft
const createRes = await fetch(`${POSTA}/v1/posts`, {
method: 'POST',
headers: headers(),
body: JSON.stringify({
caption: context.caption,
socialAccountIds: context.socialAccountIds,
...(context.mediaIds?.length ? { mediaIds: context.mediaIds } : {}),
}),
})
if (!createRes.ok) throw new Error(`Posta create ${createRes.status}`)
const { id } = await createRes.json()
// Step 2 — schedule it
const scheduleRes = await fetch(`${POSTA}/v1/posts/${id}/schedule`, {
method: 'POST',
headers: headers(),
body: JSON.stringify({ scheduledAt: context.scheduledAt }),
})
if (!scheduleRes.ok) throw new Error(`Posta schedule ${scheduleRes.status}`)
return { id, scheduledAt: context.scheduledAt }
},
})Common patterns
Workflow: research → draft → schedule
Three Mastra Workflow steps, each typed, the last one calling Posta to schedule the per-platform captions.
Parallel platform fan-out
Workflow
.parallel() runs per-platform sub-workflows that draft and schedule independently.Agent network as a posting team
A LinkedIn specialist, a Bluesky specialist, a YouTube Shorts specialist — each an Agent with Posta tools — coordinated by an Agent Network.
Webhook-triggered Workflow run
An HTTP endpoint receives Posta webhooks, verifies HMAC, and kicks off a follow-up Workflow run.
Frequently asked questions
How do I let a Mastra agent post to social media?
Load the Posta MCP server via Mastra's
MCPClient (recommended), or wrap the REST API with createTool() and Zod. Code for both above. Does it work in Mastra Workflows?
Yes. A Workflow step can call the Agent or invoke a Posta-wrapping tool directly. Both compose with
.then(), .branch(), .parallel(). Mastra Cloud or self-hosted?
Either. REST wrapper runs anywhere fetch works; MCP stdio transport runs in any Node-capable Mastra deployment.
Will the agent learn the Posta tools without prompting?
Yes — that's the value of MCP. Tool definitions live in the server; Mastra introspects them at startup.
Explore more
Posta Home →Social Media Scheduler →Instagram Scheduler →TikTok Scheduler →Bluesky Scheduler →Threads Scheduler →Buffer Alternative →Hootsuite Alternative →Compare Schedulers →Social Media for AI Agents →API & Webhooks →Auto Post Social Media →Social Media Tools →CLI Social Media Posting →n8n Workflows →Blog →
Wire Posta into your next Mastra agent
14-day free trial. MCP server, Claude Code skill, and n8n node are free and open source.