登入開始免費試用
easyCoexistence 官方 API

為 CrewAI 團隊加入 Instagram、TikTok 與 WhatsApp 工具

CrewAI 團隊在每個代理的 mcps 清單中加入一個 MCPServerHTTP,指向 https://easycoexistence.com/api/mcp,並在其 Authorization 標頭中附上 easyCoexistence OAuth 存取權杖,即可把 Instagram、TikTok、WhatsApp 及更多渠道作為工具使用。CrewAI 的 MCP 客戶端只會傳送標頭,不會執行登入,因此團隊在每次 kickoff 時更新權杖;自訂工具則可改用金鑰呼叫貼文 API。

headers

MCPServerHTTP 的可選 HTTP 標頭字典,CrewAI 的文件顯示用於攜帶 Authorization 的 Bearer 權杖。

create_static_tool_filter

CrewAI 對 MCP 伺服器工具的允許清單與封鎖清單,由 crewai.mcp.filters 匯入。

30 seconds

CrewAI 對 MCP 連接的預設等候時間;無法連接的伺服器會記錄為警告,代理仍保留其他工具。

1 hour

easyCoexistence MCP 存取權杖的有效時間;更新權杖(有效 60 天)可換取一組新權杖。

90 days

easyCoexistence 貼文 API 可提前排程的時間,最短 1 分鐘起,排入佇列時會複製媒體。

CrewAI 代理如何載入 easyCoexistence 工具?

透過 mcps 欄位,每個代理設定一個 MCPServerHTTP。它以 Streamable HTTP 連接,這是 CrewAI 此類別的預設值,並傳送你提供的標頭,此處為攜帶 easyCoexistence 存取權杖的 Authorization 標頭。使用 create_static_tool_filter 建立的靜態工具篩選器,可讓每個代理只獲得其任務所需的工具;cache_tools_list 則會在首次連接後保留清單。CrewAI 會在需要時才連接;若伺服器無法連接,它會記錄警告,並讓代理繼續使用其他工具,因此首次執行時請查看記錄。存取權杖來自下一節的輔助函式。

A two-agent crew, each with its own slice of the tools
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>"})

團隊的存取權杖從哪裡來?

來自一次瀏覽器登入,之後每次 kickoff 時更新。easyCoexistence 的 MCP 伺服器只接受 OAuth 權杖:動態用戶端註冊、搭配 PKCE 的授權碼,存取權杖有效一小時,更新權杖有效 60 天。在有瀏覽器的機器上執行一次 MCP Python SDK 的 OAuthClientProvider,並儲存它回傳的註冊資料與權杖;以下輔助函式使用 SDK 的 1.x 版本,即 CrewAI 所安裝的版本。每次 kickoff 前,fresh_token 會以已儲存的更新權杖向 easyCoexistence 的權杖端點換取新的一組權杖並儲存,因此每 60 天內至少執行一次的團隊便不再需要瀏覽器。請將已儲存的檔案放在機密儲存空間,不要放進儲存庫。

easycoexistence_token.py: sign in once, refresh per kickoff
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())

團隊如何在沒有 MCP 伺服器的情況下發佈?

使用自訂工具呼叫 easyCoexistence 的貼文 API,適合由排程器啟動、無人值守的團隊。在控制台建立合作夥伴 API 金鑰,金鑰以 ec_live_ 開頭;以下工具會將文字、媒體連結、類型與 publish_at 以 POST /api/v1/channels/:id/posts 送出。easyCoexistence 會在貼文排入佇列時複製媒體,若當時連結回傳的是網頁或格式不符,便會拒絕;到時間後再發佈貼文。Idempotency-Key 標頭可防止重試的呼叫把同一貼文排入佇列兩次。同一把金鑰也可透過 GET /api/v1/channels/:id?credentials=1 讀取最新的網絡權杖。

A CrewAI tool that queues a post through the posts API
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 refused

哪個代理應持有哪些工具?

以能完成任務的最少數量為原則,因為代理可呼叫其持有的任何工具。規劃並發佈一週內容的團隊,應將工作分配給不同代理,使閱讀、撰寫與發佈分屬不同代理,且只有其中一個能讓內容正式上線。完全不要給撰稿代理任何 easyCoexistence 工具:它只根據分析員的發現與簡報工作,其文案會以任務輸出形式交給排程器。發佈工具接受 scheduled_at,因此排程器會按指定時間排入貼文,而非執行當下就發出;list_scheduled_posts 則讓它確認等候中的內容。LinkedIn 貼文不納入團隊:代理會按要求起草每則貼文,例如在 Claude 或 ChatGPT 中,再由人工批准後才發出。

Analystlist_social_accounts, list_social_posts, get_social_insights, get_youtube_analytics
WriterNo easyCoexistence tools; drafts captions from the brief and the analyst's findings
Schedulerpublish_instagram_post, publish_tiktok_post, publish_facebook_post, list_scheduled_posts
Community managerlist_social_comments, reply_to_comment, hide_comment, send_social_dm

各網絡對團隊的貼文與回覆有何要求?

各網絡 API 的規則,應寫入代理的目標與背景設定:

  • 媒體:每個檔案需要一個公開的 HTTPS 連結。Instagram 接受 JPEG 圖片,TikTok 相片貼文接受 JPEG 或 WebP,Facebook 專頁貼文則接受一張相片或一段影片。
  • 時間:採用附時區的 ISO 8601 格式,例如 2026-11-20T09:00:00-03:00,可排程的範圍由 1 分鐘起至 90 天後。
  • 留言:TikTok 的回覆為公開,須以影片的 ID 作為 post_id;Instagram 或 Facebook 留言可在 7 天內私下回覆一次。
  • 私訊:Instagram 與 Messenger 須在對方最後一則訊息後 24 小時內回覆;WhatsApp 的 send_message 遵守相同時限,send_template 則可發送給其他任何人。
  • 事件:留言或私訊只會透過你自行設定的路由傳送給團隊,路由以 set_social_webhook_destination 設定,可在事件發生時呼叫 crew.kickoff。

常見錯誤

  • 用昨天的權杖啟動團隊。easyCoexistence 存取權杖在發出一小時後即失效,而 CrewAI 無法連上伺服器時仍會繼續運作,記錄中只會出現警告;請在每次 kickoff 時呼叫 fresh_token。
  • 讓每個代理獲得整個伺服器。沒有 tool_filter 的話,分析員也會看到發佈工具;請傳入 create_static_tool_filter,並列出其任務所需的名稱。
  • 寫入 publish_at 或 scheduled_at 時未附時區偏移。easyCoexistence 會拒絕沒有時區的時間,請以 Z 或 -03:00 之類的偏移結尾。
  • 把已儲存的登入檔案提交至儲存庫。其更新權杖會讓任何持有者在最長 60 天內取得該帳戶的工具,因此請存放於機密儲存空間。
使用 EasyCoexistence 完成這項設定

easyCoexistence 讓你的 CrewAI 代理觸及 WhatsApp、Instagram、Facebook、TikTok、YouTube、LinkedIn 等渠道的客戶,每個渠道均透過官方 API 運作:為每個代理的 mcps 清單提供 35 多個 MCP 工具;貼文 API 最多可提前 90 天排入佇列;留言與私訊的已簽署事件;並且每個連接全天候 24 小時監控。每個連接每月 US$ 9 至 US$ 0.75,連接越多越便宜,前 3 天免費。

常見問題

CrewAI 的 MCP 客戶端會自行執行 OAuth 登入嗎?

其文件顯示的是標頭、環境變數與查詢參數等驗證方式,沒有 OAuth 流程。因此團隊會傳送一個已持有的 Bearer 權杖,而這個權杖可透過 MCP Python SDK 的一次登入取得。

團隊能否依自己的排程回覆留言?

可以。具備 list_social_posts、list_social_comments 與 reply_to_comment 的社群經理代理,可在每次運行時逐一處理新留言;YouTube 與 LinkedIn 的留言也是這樣讀取,因為兩者都不轉送事件。

團隊能否發送 WhatsApp 訊息?

可以。在代理的工具篩選器中加入 list_numbers、send_message 與 send_template 即可。send_message 可回覆過去 24 小時內曾傳訊給你的客戶,send_template 則可發送已批准的範本給其他任何人。

easyCoexistence 為 CrewAI 團隊收費多少?

每個連接每月 US$ 9 至 US$ 0.75,連接越多越便宜,各網絡收費相同。MCP 伺服器、貼文 API 與轉送的事件均已包括在內,前 3 天免費。

繼續閱讀

兩分鐘內連接您的第一個頻道。

無需等待平台審核。連接 WhatsApp、Instagram、TikTok 或其他頻道,然後請您的 AI 發佈貼文、回覆訊息或匯報數據,並看着它運作。

  • 免費試用 3 天
  • 隨時取消
  • 只用官方 API
  • 24/7 監察

驗證日期