LangChain Social Media: Post from a LangChain Agent
Wire Posta into a LangChain agent in minutes. Use the Posta MCP server through langchain-mcp-adapters, or wrap the REST API as a LangChain Tool. Post to eight social networks from any LangChain workflow.
Why Posta + LangChain?
Typed tools for LangChain agents
The Posta MCP server exposes
createPost, schedulePost, listAccounts as introspectable tools — LangChain's agent loop picks the right call automatically.No social API plumbing
Skip the per-platform OAuth, rate limit, and media-format handling. Posta does it once for every supported network.
Closed-loop with webhooks
HMAC-signed callbacks fire on publish/fail. Wire them into a LangGraph node and your agent reacts to platform feedback.
Works in Python and JS
LangChain Python and LangChain JavaScript both interoperate with the MCP server. Posta-as-tool ships once, runs everywhere.
Path 1 — Posta MCP via langchain-mcp-adapters (recommended)
The langchain-mcp-adapters package converts MCP servers into LangChain tools. Load the Posta server once and every Posta capability is available to your agent.
pip install langchain-anthropic langchain-mcp-adapters langgraph
# agent.py
import os
from langchain_anthropic import ChatAnthropic
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
async def main():
client = MultiServerMCPClient({
"posta": {
"command": "npx",
"args": ["-y", "posta-mcp"],
"env": {"POSTA_API_TOKEN": os.environ["POSTA_API_TOKEN"]},
"transport": "stdio",
}
})
tools = await client.get_tools()
agent = create_react_agent(ChatAnthropic(model="claude-sonnet-4-6"), tools)
result = await agent.ainvoke({"messages": [
("user", "Draft and schedule a LinkedIn post about our new release for tomorrow 9am CET.")
]})
print(result)Path 2 — Wrap the REST API as a LangChain Tool
For deterministic chain steps where you don't need the agent to choose between tools, the REST API is simpler. One Tool, one POST.
from langchain_core.tools import tool
import os, requests
POSTA = "https://api.getposta.app"
HEADERS = {"Authorization": f"Bearer {os.environ['POSTA_API_TOKEN']}"}
@tool
def schedule_post(
caption: str,
social_account_ids: list[int],
scheduled_at: str,
media_ids: list[str] | None = None,
) -> dict:
"""Create a draft on the given social accounts, then schedule it.
scheduled_at is an ISO 8601 timestamp. media_ids are Posta media IDs."""
# Step 1 — create 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 r.json()Common patterns
Research → Draft → Schedule chain
A LangChain SequentialChain pulls source material, drafts per-platform captions, and Posta schedules the result.
LangGraph closed-loop
A LangGraph state machine where one node calls Posta, another node listens for the webhook and decides the next state.
Multi-platform fan-out with branching
A router agent decides which subset of platforms get the post; each branch tunes the caption for that platform before calling Posta.
Retrieval-augmented posts
Pull context from a vector store, feed it to the LLM as part of the prompt, draft a post grounded in your knowledge base, and ship via Posta.
Frequently asked questions
How do I let a LangChain agent post to social media?
Either load the Posta MCP server with
langchain-mcp-adapters (recommended), or wrap the REST API as a LangChain Tool. Code for both above. Which Posta surface should I use?
MCP for interactive agents (chat-style, multi-step). REST for deterministic chain steps where you don't need the agent to pick between tools.
Does it work with LangGraph?
Yes — the MCP-adapter and Tool approaches both work inside LangGraph nodes.
Python or JavaScript?
Both. The MCP server is language-agnostic; examples here are Python.
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 →
Try Posta in your next LangChain agent
14-day free trial. MCP server, Claude Code skill, and n8n node are free and open source.