instagram-analytics-mcp
Enables natural-language querying of Instagram reel performance across accounts, computing completion rates that the Instagram API does not provide.
README
Instagram Analytics MCP
An MCP server that answers questions about Instagram reel performance in plain language, across multiple accounts.
The point is not that it wraps an API. It is that the number that actually predicts reach does not exist in the Instagram API, so the server computes it.
"How did my last 10 reels do?"
"What worked best this month?"
"Which of my accounts is working?"
The problem this solves
Instagram's Graph API returns views, reach, saves, shares and average watch time.
It does not return completion rate -- the share of the video people actually watch. On a real account measured over ~700 reels, completion is what separates a reel that dies from one that travels:
| Completion | Typical outcome |
|---|---|
| under 15% | dies, a few hundred views |
| 25%+ | reliably reaches thousands |
| ~39% | went viral (161K) |
Views are the outcome. Completion is the cause, and it is readable within hours of posting rather than days.
Computing it needs avg_watch_time / duration. Duration is not in the API either. So the
server probes each video's media_url with ffprobe to measure it.
That is the whole reason this exists. Two hops the API will not do for you, plus a threshold judgement the API has no opinion about.
Tools
| Tool | Answers |
|---|---|
list_accounts() |
"Which accounts are set up?" |
recent_reels(account, limit) |
"How did my recent posts do?" |
top_reels(account, days, scan) |
"What actually worked?" -- ranked by completion, not views |
compare_accounts(days, scan) |
"Which account is working?" -- median completion per account |
Every reel comes back with date, completion, a verdict label, duration, views, reach, saves,
shares, the caption's first line as the hook, and a permalink.
Works with one account or several. account is optional and defaults to the first one you
configured.
Requirements
- An Instagram Professional account (Business or Creator). Personal accounts cannot use the Instagram API at all
- Python 3.10+
ffprobe(brew install ffmpeg) -- without it there is no duration, so no completion rate
Setup
git clone https://github.com/sskghub/instagram-analytics-mcp
cd instagram-analytics-mcp
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
cp .env.example .env
Then get a token. SETUP.md is the full walkthrough, about 15 minutes for the first account: create a Meta app, add Instagram, generate a token.
Once a token is in .env, this checks everything and tells you the account id to paste back in,
so you never have to hunt for it:
.venv/bin/python check_setup.py
[ OK ] mcp package installed
[ OK ] ffprobe found
[ OK ] main: token works, account @yourhandle
Then confirm it pulls real data, and that the MCP layer works end to end:
.venv/bin/python server.py --selftest
.venv/bin/python test_server.py
Register with Claude Code:
claude mcp add ig-analytics -- /absolute/path/.venv/bin/python /absolute/path/server.py
The server reads its own .env, so no credentials go in the MCP config file. That config
is committed; tokens are not.
Adding another account means adding two lines to .env. There is no code to edit -- accounts
are discovered from the variable names.
Token expiry
Instagram tokens last ~60 days. When one dies, everything downstream silently returns nothing.
refresh_tokens.py exchanges a still-valid token for a fresh 60-day one:
python refresh_tokens.py --if-older-than 7
Run it weekly. The constraint that shapes the design: an expired token cannot be refreshed. Meta will not renew a dead token, so refreshing early is the only strategy that works. Each refresh resets the full 60 days, so early refreshes cost nothing.
Scheduling notes, including the macOS trap where a launchd job silently cannot read your
files, are in SETUP.md.
It backs up .env before writing, rewrites duplicate keys, and alerts on failure.
Refreshing does not invalidate the old token, so several machines can each refresh their own
.env independently. Token values never need syncing between hosts.
Notes from building it
Things that cost real time, kept here because they are the parts that generalize.
sys.exit() is fine in a CLI and fatal in a server. The first version reused a function
from an existing command-line script. That function called sys.exit() when a token was
rejected, which would have killed the whole server process on the day a token expired. Tools
now raise ValueError; the SDK turns standard exceptions into readable results the model can
act on, and the server survives.
Errors should say what to do. A dead token returns the steps to regenerate it, not a stack trace. The model can relay that to a human who can actually fix it.
The docstring is the interface. It is how the model decides whether to call a tool at all, so each one says when to reach for it, not just what it returns.
Scheduled jobs can fail silently. On macOS a launchd timer for the refresh script failed
with Operation not permitted, because TCC blocks background agents from reading protected
directories. It reported as loaded and would have quietly never run. Forcing a run and reading
the log is the only way that surfaces.
Duplicate keys in .env are a real trap. A stale duplicate can shadow a freshly written
token depending on how the loader resolves them, so the writer rewrites every occurrence
rather than the first.
The API changed names. It is mcp.server.mcpserver.MCPServer; the older
mcp.server.fastmcp.FastMCP path was removed in mcp 2.x, along with other legacy modules.
Most examples online still show the old import and will not run.
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 模型以安全和受控的方式获取实时的网络信息。