Prompt
Chain: load our new preprint's abstract, write a plain-language Mastodon post for a general science audience with the key finding and the arXiv link, then call draft_post for mastodon. Add #OpenScience at the end. How to do it
- Mint a Mastodon agent key In https://app.socialhandoff.com, open Connections, connect your Mastodon account, then create an agent key scoped to Mastodon with draft permission only. Copy the key when it is shown; only its hash is stored.
- Install the MCP adapter Add langchain-mcp-adapters and create a MultiServerMCPClient with a streamable_http connection to https://app.socialhandoff.com/mcp and a bearer header.
- Load tools into the agent Call get_tools() and pass them to your agent. Keep the key scoped to Mastodon and draft so the model only sees what it needs.
- Run the pipeline Feed the chain its source material, let it call draft_post for Mastodon, and read the returned post id. Or skip MCP and POST to /v1/posts from a plain tool.
Example draft
New preprint from our lab: small language models fine-tuned on 2,000 labeled examples matched larger models on classifying bird calls, at a fraction of the compute. The data and code are open. arxiv.org/abs/2609.01234 #OpenScience #MachineLearning
Gotchas
- Publishing uses idempotency keys, so a retried request after a timeout does not produce a duplicate toot.
- Alt text is expected on the fediverse, and many people filter posts without it. The missing alt text guardrail flags drafts before they reach you.
- Read your instance rules on automated posting. Many ask that bot-driven accounts tick the automated account box in profile settings.
- The adapter loads every tool the key allows. Scope the key to Mastodon and draft permission so the model cannot reach analytics or scheduling tools you did not plan for.
- Character limit: 500 characters on a default Mastodon server. Each instance can raise it, so check yours.
- Links: Every URL counts as 23 characters, however long it is.
- Media per post: Up to 4 attachments on a default server.
- File sizes: Images up to 16 MB and video up to about 99 MB on a default install. Instances can set their own limits.
Frequently asked questions
Do I have to use MCP with LangChain?
No. You can wrap POST /v1/posts in a plain LangChain tool, or use the TypeScript SDK. MCP saves you writing tool schemas.
Can a LangChain agent post to more than one Mastodon account?
Yes. Connect each account, scope the key to Mastodon, and pass accountIds to target one or several. Each target is approved and published separately.
Can I post to several fediverse accounts at once?
Yes. Connect each Mastodon account, and a single draft can target several. Each target is published and retried on its own.