MCP (streamable HTTP) via langchain-mcp-adapters · Instagram

Build a LangChain agent that drafts Instagram posts for approval

A LangChain agent can research, write, and pick images, but Instagram adds two hard rules: every post needs media, and only professional accounts can publish. SocialHandoff handles the account side; your agent handles the content. Load the MCP tools with langchain-mcp-adapters, and have the agent call attach_media with each image URL, then draft_post with the ids in mediaIds. Every post then waits in the approval inbox for a person.

Prompt

You are a social editor for a travel blog. Given a new article, choose the best 3 photos from its image list, upload each with alt text, and create one Instagram carousel draft with a caption under 1,000 characters and 8 hashtags at most. Never schedule without images.

How to do it

  1. Connect Instagram and mint a key In https://app.socialhandoff.com, open Connections, connect an Instagram professional account (Business or Creator). Then create an agent key named LangChain scoped to Instagram with draft and schedule permission.
  2. Load the tools Connect with MultiServerMCPClient from langchain-mcp-adapters with transport streamable_http, pointing at https://app.socialhandoff.com/mcp and sending the key as a bearer header. The agent gets attach_media, draft_post, schedule_post, and preview_posts.
  3. Attach media The agent calls attach_media through the MCP adapter with a public url (or base64 data up to 8 MB) and alt text for the JPEG image, Reel, or carousel (up to 10 items). From plain code, POST https://app.socialhandoff.com/v1/media/import does the same. Pass the ids to draft_post in mediaIds.
  4. Run the agent Invoke the agent with the article and its image list. It uploads, then creates the draft, and you can call preview_posts to see the card.

Example draft

Three days on the Amalfi coast without a car.

Buses, ferries, and a lot of stairs got us from Sorrento to Positano and Amalfi. Swipe for the view from the Path of the Gods, the ferry we almost missed, and the lemon granita that made up for it.

Full route and costs in the new post, link in bio.

#amalficoast #italytravel #slowtravel #hiking #positano

[Carousel: 3 JPEG photos selected by the agent, alt text on each]

Gotchas

  • Only professional accounts (Business or Creator) can connect. A personal account is refused at connect time with instructions to switch.
  • Tell the agent in its instructions to call attach_media before draft_post for image and video networks. Otherwise it may produce text-only drafts that cannot be approved.
  • Instagram refuses text-only posts. A draft can be saved as text first, but approving or scheduling it is refused with a clear error until an image or video is attached.
Instagram
  • Account type: Professional accounts only (Business or Creator). Personal accounts cannot publish through the API.
  • Media: Every post needs an image or video. Text-only posts are not possible on Instagram.
  • Image files: JPEG only, up to 8 MB. Convert PNG or WebP before posting.
  • Reels: Video posts publish as Reels, from MP4 or MOV files.
Schedule Instagram posts and Reels your agents draft

Frequently asked questions

Can I post Reels?
Yes. Attach an MP4 or MOV video and it publishes as a Reel with your caption.
Can the LangChain agent approve its own posts?
No. approve_post only works with owner keys, and an agent key can never approve its own draft.
Does it work with a personal Instagram account?
No. Instagram only allows publishing through its API for professional accounts, Business or Creator. Switching is free in the Instagram app settings.

Let your agents post. Keep the final say.

Connect your first agent in minutes. Every draft waits in your inbox until you approve it.

14 days free. No card required.

The hosted version is opening soon

Leave your email and we will send one message when hosted accounts open, with your 14-day trial ready. Want it today? Self-host it free from the repo.

Start free trial