Give a CrewAI crew Instagram, TikTok and WhatsApp tools
A CrewAI crew gets Instagram, TikTok, WhatsApp and more channels as tools when each agent's mcps list holds an MCPServerHTTP for https://easycoexistence.com/api/mcp with an easyCoexistence OAuth access token in its Authorization header. CrewAI's MCP client sends headers rather than running a sign-in, so the crew refreshes the token at each kickoff, and custom tools can reach the posts API with a key instead.
MCPServerHTTP's optional dictionary of HTTP headers, which CrewAI's docs show carrying an Authorization bearer token.
CrewAI's allow and block lists for an MCP server's tools, imported from crewai.mcp.filters.
CrewAI's default wait for an MCP connection; a server it cannot reach is logged as a warning and the agent keeps its other tools.
How long an easyCoexistence MCP access token lasts; a refresh token, good for 60 days, brings a new pair.
How far ahead easyCoexistence's posts API schedules a post, from 1 minute, copying the media when it is queued.
How does a CrewAI agent load the easyCoexistence tools?
Through the mcps field, with one MCPServerHTTP per agent. It connects over Streamable HTTP, CrewAI's default for this class, and sends the headers you give it, here an Authorization header holding an easyCoexistence access token. A static tool filter, made with create_static_tool_filter, gives each agent only the tools its task needs, and cache_tools_list keeps the list after the first connection. CrewAI connects on demand and, if a server cannot be reached, logs a warning and lets the agent carry on with its other tools, so read the log on the first run. The access token comes from the helper in the next section.
from crewai import Agent, Crew, Task
from crewai.mcp import MCPServerHTTP
from crewai.mcp.filters import create_static_tool_filter
from easycoexistence_token import fresh_token
TOKEN = fresh_token() # one per kickoff: an access token lasts an hour
def easycoexistence(*tools: str) -> MCPServerHTTP:
return MCPServerHTTP(
url="https://easycoexistence.com/api/mcp",
headers={"Authorization": f"Bearer {TOKEN}"},
streamable=True,
cache_tools_list=True,
tool_filter=create_static_tool_filter(allowed_tool_names=list(tools)),
)
analyst = Agent(
role="Social analyst",
goal="Find which of last week's Instagram and TikTok posts reached the most people",
backstory="You read the numbers before anyone writes a caption.",
mcps=[easycoexistence("list_social_accounts", "list_social_posts", "get_social_insights")],
)
scheduler = Agent(
role="Scheduler",
goal="Queue next week's posts at the times the analyst recommends",
backstory="You post only what the brief approves, always with scheduled_at.",
mcps=[easycoexistence("list_social_accounts", "publish_instagram_post",
"publish_tiktok_post", "list_scheduled_posts")],
)
crew = Crew(
agents=[analyst, scheduler],
tasks=[
Task(description="Rank last week's posts by reach and views.",
expected_output="A ranked list with the best posting times", agent=analyst),
Task(description="Schedule the three posts in {brief} for next week.",
expected_output="The post_id of each queued post", agent=scheduler),
],
)
crew.kickoff(inputs={"brief": "<THE WEEK'S BRIEF>"})Where does the crew's access token come from?
From one browser sign-in, then a refresh at each kickoff. easyCoexistence's MCP server takes OAuth tokens only: dynamic client registration, an authorization code with PKCE, access tokens that last an hour and refresh tokens that last 60 days. Run the MCP Python SDK's OAuthClientProvider once, on a machine with a browser, and save the registration and tokens it returns; the helper below uses the SDK's 1.x line, which CrewAI installs. Before each kickoff, fresh_token trades the saved refresh token at easyCoexistence's token endpoint for a new pair and stores it, so a crew that runs at least once in 60 days never needs the browser again. Keep the saved file in a secret store, not in the repository.
import asyncio, json, webbrowser
from pathlib import Path
from urllib.parse import parse_qs, urlparse
import httpx
import requests
from pydantic import AnyUrl
from mcp import ClientSession
from mcp.client.auth import OAuthClientProvider
from mcp.client.streamable_http import streamable_http_client
from mcp.shared.auth import OAuthClientMetadata
URL = "https://easycoexistence.com/api/mcp"
SAVED = Path("easycoexistence-oauth.json") # a secret store in production
class SaveToFile: # the MCP SDK's TokenStorage, writing what the sign-in returns
def __init__(self):
self.saved = {}
async def get_tokens(self): return None
async def get_client_info(self): return None
async def set_tokens(self, tokens): self._put("tokens", tokens)
async def set_client_info(self, info): self._put("client", info)
def _put(self, key, model):
self.saved[key] = model.model_dump(mode="json")
SAVED.write_text(json.dumps(self.saved))
async def open_browser(url: str) -> None:
webbrowser.open(url)
async def code_from_redirect() -> tuple[str, str | None]:
q = parse_qs(urlparse(input("Address after sign-in: ")).query)
return q["code"][0], q.get("state", [None])[0]
async def sign_in_once() -> None:
oauth = OAuthClientProvider(
server_url=URL,
client_metadata=OAuthClientMetadata(
client_name="Acme crew", redirect_uris=[AnyUrl("http://localhost:3030/callback")], scope="mcp"),
storage=SaveToFile(), redirect_handler=open_browser, callback_handler=code_from_redirect,
)
async with httpx.AsyncClient(auth=oauth) as http:
async with streamable_http_client(URL, http_client=http) as (read, write, _):
async with ClientSession(read, write) as session:
await session.initialize() # completes the sign-in and saves the tokens
def fresh_token() -> str:
"""Trade the saved refresh token for a new pair and return the access token."""
saved = json.loads(SAVED.read_text())
r = requests.post("https://easycoexistence.com/api/oauth/token", data={
"grant_type": "refresh_token",
"refresh_token": saved["tokens"]["refresh_token"],
"client_id": saved["client"]["client_id"],
}, timeout=30)
r.raise_for_status()
saved["tokens"] = r.json() # a new refresh token comes with each refresh
SAVED.write_text(json.dumps(saved))
return saved["tokens"]["access_token"]
if __name__ == "__main__":
asyncio.run(sign_in_once())How can a crew publish without the MCP server?
With a custom tool that calls easyCoexistence's posts API, which suits a crew started by a scheduler with no one around. Create a Partner API key in the dashboard, which begins ec_live_, and the tool below sends POST /api/v1/channels/:id/posts with the text, the media link and type and publish_at. easyCoexistence copies the media when the post is queued, refuses a link that returns a web page or the wrong format at that moment, and publishes the post at its time; the Idempotency-Key header keeps a retried call from queueing it twice. The same key reads fresh network tokens from GET /api/v1/channels/:id?credentials=1.
import hashlib, os
import requests
from crewai.tools import tool
@tool("Schedule a social post")
def schedule_post(account_id: str, text: str, media_url: str, media_type: str, publish_at: str) -> str:
"""Queue one post on a connected Instagram, TikTok or Facebook account.
media_type is image or video; publish_at is ISO 8601 with a timezone, 1 minute to 90 days ahead."""
key = hashlib.sha256(f"{account_id}|{publish_at}|{media_url}".encode()).hexdigest()
r = requests.post(
f"https://easycoexistence.com/api/v1/channels/{account_id}/posts",
headers={"Authorization": f"Bearer {os.environ['EC_API_KEY']}", "Idempotency-Key": key},
json={"text": text, "media": [{"url": media_url, "type": media_type}], "publish_at": publish_at},
timeout=60,
)
return r.text # the queued post, or why it was refusedWhich agent in the crew should hold which tools?
The fewest that let it finish its task, because an agent can call any tool it holds. A crew that plans and posts a week of content splits the work so that reading, writing and publishing sit with different agents, and only one of them can put anything live. Hand the writer no easyCoexistence tools at all: it works from the analyst's findings and the brief, and its captions reach the scheduler as task output. The publishing tools take scheduled_at, so the scheduler queues posts for their times instead of posting the moment it runs, and list_scheduled_posts lets it confirm what is waiting. LinkedIn posts stay out of crews: an agent drafts each one on request, for example in Claude or ChatGPT, and a person approves it before it goes out.
What do the networks require of the crew's posts and replies?
The rules of each network's API, which belong in the agents' goals and backstories:
- Media: a public HTTPS link per file. Instagram takes JPEG images, TikTok photo posts take JPEG or WebP, and a Facebook Page post takes one photo or one video.
- Times: ISO 8601 with a timezone, such as 2026-11-20T09:00:00-03:00, from 1 minute to 90 days ahead.
- Comments: TikTok replies are public and need the video's ID as
post_id; an Instagram or Facebook comment can get one private reply within 7 days. - DMs: Instagram and Messenger take replies within 24 hours of the person's last message; WhatsApp's
send_messagekeeps to the same window, andsend_templatereaches anyone else. - Events: a comment or DM reaches the crew only through your own route, set with
set_social_webhook_destination, which can call crew.kickoff with the event.
Common mistakes
- Starting a crew with yesterday's token. An easyCoexistence access token expires an hour after it is issued, and CrewAI goes on without a server it cannot reach, with only a warning in the log; call fresh_token at each kickoff.
- Giving each agent the whole server. Without tool_filter, an analyst sees the publishing tools too; pass create_static_tool_filter with the names its task needs.
- Writing publish_at or scheduled_at without an offset. easyCoexistence refuses a time with no timezone, so end it in Z or an offset such as -03:00.
- Committing the saved sign-in file. Its refresh token gives whoever holds it the account's tools for up to 60 days, so keep it in a secret store.
easyCoexistence gives your CrewAI agents reach to customers on WhatsApp, Instagram, Facebook, TikTok, YouTube, LinkedIn and more channels, each through its official API: 35+ MCP tools for each agent's mcps list, a posts API that queues up to 90 days ahead, and signed events for comments and DMs, with every connection monitored 24/7. US$ 9 to US$ 0.75 per connection per month, falling as you add connections, with the first 3 days free.
easyCoexistence is a multichannel API and MCP server that connects AI agents such as Claude and ChatGPT to WhatsApp, Instagram, TikTok, Facebook and more. On WhatsApp it uses Coexistence: the business keeps using its number in the WhatsApp Business app while the AI works through Meta's official API.
Frequently asked questions
Does CrewAI's MCP client run the OAuth sign-in itself?
Its documentation shows headers, environment variables and query parameters for authentication, with no OAuth flow. So the crew sends a bearer token it already holds, which one sign-in with the MCP Python SDK provides.
Can a crew reply to comments on its own schedule?
Yes. A community manager agent with list_social_posts, list_social_comments and reply_to_comment can work through new comments on each run, which is also how YouTube and LinkedIn comments are read, since neither forwards events.
Can the crew send WhatsApp messages?
Yes, with list_numbers, send_message and send_template in an agent's tool filter. send_message replies to customers who wrote in the last 24 hours, and send_template sends an approved template to anyone else.
How much does easyCoexistence cost for a CrewAI crew?
US$ 9 to US$ 0.75 per connection per month, falling as you add connections, and the same on each network. The MCP server, the posts API and the forwarded events are included, with the first 3 days free.
Keep reading
Connect your first channel in two minutes.
No platform reviews to wait for. Connect WhatsApp, Instagram, TikTok or another channel, then ask your AI to post, reply or report, and watch it work.
- 3 days free
- Cancel any time
- Official APIs only
- Monitored 24/7
Verified on