FBEM
An MCP server that enables AI agents to post Reels and Photos to Facebook by capturing and replaying the native web API through a Chrome extension.
README
FBEM — Facebook Extension Crawler + MCP
Crawl/snapshot Facebook's native composer web API and publish Reels / Photos through a Chrome extension — exposed to any agent as an MCP server.
FBEM drives the same internal web API a logged-in human uses on facebook.com (NOT the Graph API, which suppresses reach on API-published posts). It learns the exact upload shape by passively snapshotting the requests you make by hand, then replays that template with fresh media + fresh volatile tokens — so it is self-healing and needs no reverse-engineering when Facebook rotates its payload.
Any MCP-capable agent (Claude Code / Claude Desktop / Cursor / …) can plug in and
call post_reel, post_photos, switch_profile, get_identity, health, and
capture_status. Adding a new tool is one file — see CONTRIBUTING.md.
⚠️ Local tool, loopback-only. The bridge binds
127.0.0.1and is unauthenticated by design. It runs on your machine against your logged-in browser session. Never expose it to a network. Use it only on accounts you own and in line with Facebook's terms.
Architecture

any MCP agent (Claude Code / Desktop / Cursor / …)
│ stdio (MCP protocol)
▼
fbem-mcp ──HTTP(loopback :47102)──► fbem-bridge ──WS(:9224)──► Chrome extension
(FastMCP; (FastAPI + (crawler + replay,
tools/ = one file per tool) WS server) injected in-page)
│ runs inside
▼
facebook.com tab
(your live session)
fbem-bridge(persistent) holds the WebSocket to the extension, serves media over loopback, and stores captured templates. Run it once; leave it up.fbem-mcp(spawned by the agent) is a thin stdio layer that calls the bridge over HTTP. Because it's separate, every agent can spawn its own MCP process without fighting over the extension's WebSocket port.- Chrome extension has three jobs, all inside the page's own context:
- Crawler — monkeypatches
fetch/XHRto passively snapshot the genuine native upload requests when you post by hand. Never blocks or mutates them. - Tokens — scrapes fresh volatile tokens (
fb_dtsg,lsd,jazoest, …). - Replay — reproduces a captured template with new media + fresh tokens.
- Crawler — monkeypatches
How it works: capture-then-replay
Replay is template-driven and only activates after one real capture per kind.
- Start the bridge and load the extension; open a logged-in facebook.com tab.
- Post one item by hand (a Reel, a photo/album, a page switch).
- The crawler snapshots the real requests (the
rupload/photo upload + theComposerStoryCreateMutationpublish) and POSTs them to the bridge, which folds them intotemplate.json. - From then on, the matching MCP tool replays automatically — fresh video/photo, fresh tokens, same proven shape.
When Facebook rotates its payload and replay starts failing, just re-capture (repeat steps 2–3). No code change is ever required.
Quickstart
1. Install
git clone https://github.com/crisng95/fbem.git FBEM && cd FBEM
python3.11 -m venv .venv
.venv/bin/pip install -e .
2. Run the bridge (leave it running)
.venv/bin/fbem-bridge # HTTP :47102 + WS :9224, loopback only
3. Load the Chrome extension
chrome://extensions → enable Developer mode → Load unpacked → select the
extension/ directory. See extension/README.md. Keep a
logged-in www.facebook.com tab open — replay runs inside it.
4. Seed a template (one manual post)
With everything running, post one Reel (and one photo/album) by hand. Confirm:
curl -s http://127.0.0.1:47102/api/health | python3 -m json.tool
# look for: extension_connected: true, has_template: true, has_photo_template: true
Already have captured templates elsewhere? Point the bridge at that captures directory and skip re-snapshotting entirely:
FBEM_CAPTURES_DIR=/path/to/existing/captures fbem-bridge
5. Plug the MCP into your agent
Claude Code:
claude mcp add fbem -- /abs/path/to/FBEM/.venv/bin/fbem-mcp
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"fbem": { "command": "/abs/path/to/FBEM/.venv/bin/fbem-mcp" }
}
}
Any MCP client: run the command fbem-mcp, transport stdio.
The agent can now call the tools below. (The bridge from step 2 must stay running.)
MCP tools
| Tool | What it does |
|---|---|
post_reel |
Publish a Reel from a local .mp4. Args: video_path, caption, page_id?, scheduled_publish_time?. |
post_photos |
Publish a photo (1 file) or album (N files) from local .jpg/.png. Args: image_paths[], caption, page_id?, scheduled_publish_time?. |
switch_profile |
Switch the acting page/profile so later posts go out AS that page. Args: target_id. |
get_identity |
Read which page/profile the tab currently posts AS (read-only). |
health |
Bridge + extension health (connection, templates, tab TTL). |
capture_status |
Crawler/snapshot status: what's captured, what's ready to post, and exactly what to (re)snapshot if not. |
When do I need to (re)snapshot?
- First run / a kind never captured → yes: post that kind once by hand.
- Reel vs Photo vs Switch are separate templates → capturing a Reel does not enable photo posting; capture each kind once.
- Already captured and working → no. Templates persist in
FBEM_CAPTURES_DIR. - Facebook rotated its payload (replay errors like
story_create=null,no_template_captured, repeated 502s) → re-capture that one kind by hand.
Ask the agent to call capture_status any time — it reports exactly what's ready
and what to do.
Configuration
All optional; sensible loopback defaults. See .env.example.
| Env | Default | Purpose |
|---|---|---|
FBEM_HTTP_PORT |
47102 |
Bridge HTTP API port |
FBEM_WS_PORT |
9224 |
Extension WebSocket port |
FBEM_WS_HOST |
127.0.0.1 |
WS bind host (must be loopback) |
FBEM_HOME |
~/.fbem |
Base dir for state |
FBEM_CAPTURES_DIR |
$FBEM_HOME/captures |
Captured templates (contain live tokens) |
FBEM_MEDIA_DIR |
$FBEM_HOME/media |
Media served to the extension |
FBEM_BRIDGE_URL |
http://127.0.0.1:47102 |
Where the MCP reaches the bridge |
FBEM_TAB_TTL_S |
7200 |
Advanced: tab auto-reload window (seconds) that keeps tokens fresh |
FBEM_TAB_ACTIVE_WINDOW_S |
90 |
Advanced: how recently a capture must arrive to count the tab as "active" (seconds) |
FBEM_PUBLISH_OP_RE |
(built-in regex) | Advanced: override the regex matching the Reel publish mutation (set only if FB renames the op) |
Security
- Loopback-only & unauthenticated by design. Startup refuses a non-loopback
FBEM_WS_HOST. Never port-forward or proxy it. - Captures contain live FB tokens (
fb_dtsg,lsd, cookies).captures/is git-ignored — never commit it. TreatFBEM_CAPTURES_DIRas a secret. - No tokens in code. The callback secret is random per process; volatile FB tokens are scraped live from the page at replay time.
Project layout
fbem/
bridge/ persistent backend (FastAPI :47102 + extension WS :9224)
server.py · ws_server.py · bridge_client.py · capture_store.py · config.py · run.py
mcp/ the MCP server (any-agent pluggable)
server.py · registry.py · bridge_api.py
tools/ ONE FILE PER TOOL ← the contribution surface
_template.py · post_reel.py · post_photos.py · switch_profile.py
get_identity.py · health.py · capture_status.py
extension/ Chrome MV3 (crawler snapshot + replay)
docs/PROTOCOL.md the decoded native upload protocol
Contributing
Adding a tool is one file. Copy fbem/mcp/tools/_template.py, write a typed async
function, done — it's auto-discovered. See CONTRIBUTING.md.
License
MIT.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。