OpenAI Agents SDK Social Media: Posta MCP + Function Tools

Hand an OpenAI Agents SDK agent the Posta MCP server and let it post to eight social networks. Native MCP support; function-tool fallback for the REST API when you want a deterministic single-call shape.

Why Posta + OpenAI Agents SDK?

Native MCP support
The Agents SDK has first-class MCP — MCPServerStdio auto-exposes the Posta tools to your agent.
Handoff-friendly
Attach the Posta MCP server to the agent that receives the handoff — a "social publisher" agent that the router agent reaches for.
Function tools when you want determinism
When you'd rather not let the model pick between five Posta tools, wrap one REST call with @function_tool.
Closed-loop via webhooks
HMAC callbacks fire on publish/fail. Wire them into a follow-up agent run to handle replies or branch a campaign.

Path 1 — Posta MCP via MCPServerStdio (recommended)

The Agents SDK loads MCP servers natively. Point it at the Posta server and the agent introspects every tool it needs.

pip install openai-agents

# agent.py
import os, asyncio
from agents import Agent, Runner
from agents.mcp import MCPServerStdio

async def main():
    async with MCPServerStdio(
        params={
            "command": "npx",
            "args": ["-y", "posta-mcp"],
            "env": {"POSTA_API_TOKEN": os.environ["POSTA_API_TOKEN"]},
        }
    ) as posta_mcp:
        agent = Agent(
            name="Social Publisher",
            instructions="Draft and schedule social posts. Match each platform's voice.",
            mcp_servers=[posta_mcp],
        )
        result = await Runner.run(agent, input=(
            "Draft a LinkedIn post and a Bluesky post about our v2 launch "
            "and schedule both for tomorrow 9am CET."
        ))
        print(result.final_output)

asyncio.run(main())

Path 2 — Wrap the REST API with @function_tool

Useful when you want a single typed call exposed to the agent — no MCP transport, no tool discovery.

import os, requests
from agents import Agent, Runner, function_tool

POSTA = "https://api.getposta.app"
HEADERS = {"Authorization": f"Bearer {os.environ['POSTA_API_TOKEN']}"}

@function_tool
def schedule_post(
    caption: str,
    social_account_ids: list[int],
    scheduled_at: str,
    media_ids: list[str] | None = None,
) -> str:
    """Create a Posta draft on the given accounts and schedule it.
    scheduled_at is ISO 8601. media_ids are Posta media IDs."""
    # Step 1 — create the draft
    r = requests.post(
        f"{POSTA}/v1/posts", headers=HEADERS, timeout=30,
        json={
            "caption": caption,
            "socialAccountIds": social_account_ids,
            **({"mediaIds": media_ids} if media_ids else {}),
        },
    )
    r.raise_for_status()
    post_id = r.json()["id"]
    # Step 2 — schedule it
    r = requests.post(
        f"{POSTA}/v1/posts/{post_id}/schedule", headers=HEADERS, timeout=30,
        json={"scheduledAt": scheduled_at},
    )
    r.raise_for_status()
    return f"Scheduled post {post_id} for {scheduled_at}"

agent = Agent(
    name="Social Publisher",
    instructions="Schedule social posts.",
    tools=[schedule_post],
)

Common patterns

Router → Publisher handoff
A router agent triages the request and hands off to a Publisher agent that owns the Posta MCP server.
Per-platform specialist agents
A LinkedIn specialist with a long-form voice, a Bluesky specialist with a short-form voice — each holding Posta as a tool.
Sessions for multi-turn campaigns
Use the Agents SDK Session feature to keep context across multiple posting turns — "now schedule the day-2 post."
Webhook → follow-up run
A small webhook receiver kicks off a new Agents Run when Posta fires "post.published" — to reply, branch, or notify.

Frequently asked questions

How do I let an OpenAI Agents SDK agent post to social media?
Add the Posta MCP server via MCPServerStdio (recommended) or wrap the REST API with @function_tool. Code for both above.
Does it work with handoffs?
Yes. Attach Posta to the agent receiving the handoff — a "Publisher" agent the router hands off to.
Can I use the Responses API instead?
Yes — register a function tool that wraps the Posta REST API. The Agents SDK is ergonomic sugar; the underlying tool-calling contract is the same.
What about the Assistants API?
Assistants doesn't speak MCP natively. Wrap Posta REST as an Assistants tool, or use the newer Agents SDK / Responses API.

Wire Posta into your next OpenAI Agents Run

14-day free trial. MCP server, Claude Code skill, and n8n node are free and open source.