social-publisher
by ARMINSHIVES
README.md
# social-publisher
An MCP server that posts finished videos to your own YouTube, Instagram and TikTok accounts, and only after you approve them.
Part of [Manez](https://github.com/ARMINSHIVES), a set of tools for running AI agents under rules.
## What and why
I generate story videos with AI and wanted an agent to handle the posting without being able to post anything I hadn't seen. `social-publisher` uses the official platform APIs only. Approval locks the exact video file and caption by hash, so the agent can't swap content after the fact. Daily caps, spacing between posts and quiet hours are enforced in code, an AI-content flag is always on, and every publish starts as a dry run.
## Headline results
- 72 tests pass in about 1 minute 49 seconds (Windows 11, Python 3.11.9). They use fake platforms and an in-memory keyring, so nothing is posted. You need `ffmpeg` on PATH.
- No performance numbers exist for this repo beyond the test run. Nothing here shows that the bandit's suggestions improve views.
## Features
- Tools for an MCP client: `list_accounts`, `prepare_post`, `approve_post`, `publish_post`, `schedule_post`, `cancel_post`, `get_post_status`, `fetch_stats`, `recommend_next`, `quota_status`.
- An approval gate. `approve_post` asks you through an MCP elicitation prompt, and fails closed if the client doesn't support elicitation. You can also approve from a terminal.
- A hash lock over the file and the caption. If either changes after approval, the post needs approving again.
- Caps per platform, minimum gaps between go-live times and quiet hours (default 00:00 to 07:00 local time). The code clamps the daily cap to each platform's ceiling: YouTube 100, Instagram 50, TikTok 5 pending inbox shares.
- AI-content flags always on. YouTube gets `containsSyntheticMedia`, Instagram gets `is_ai_generated`, and metadata that says `ai_generated: false` is overridden with a warning.
- Dry run by default on `publish_post`.
- A state machine around each platform call. If a platform may have acted when something failed, the post goes to `needs_check` and you resolve it by hand.
- A small bandit (discounted Beta-Bernoulli) that suggests the next hook, length, topic and time slot from 24 to 48 hour metrics.
- A scheduler worker for scheduled Instagram and TikTok posts. YouTube schedules natively with `publishAt`.
- OAuth tokens and app credentials are stored only in the OS keyring.
## Quick start
Python 3.11 or newer and `ffmpeg` (with `ffprobe`) on PATH. Only Windows was tested.
```
python -m venv .venv
.venv\Scripts\python -m pip install -r requirements.txt
.venv\Scripts\python -m pytest -q
```
Register a developer app on each platform you want. The repo ships no client IDs, and each platform's developer terms apply to you. Then store credentials and sign in:
```
.venv\Scripts\python -m social_publisher secret set GOOGLE_CLIENT_SECRETS
.venv\Scripts\python -m social_publisher auth youtube
.venv\Scripts\python -m social_publisher secret check
```
The same pattern works for `instagram` (`IG_APP_ID`, `IG_APP_SECRET`) and `tiktok` (`TIKTOK_CLIENT_KEY`, `TIKTOK_CLIENT_SECRET`). `auth instagram --paste` stores a long-lived token you generated in the Meta App Dashboard. Instagram also needs a temporary public bucket for the video (see Configuration), with `R2_ACCESS_KEY_ID` and `R2_SECRET_ACCESS_KEY` stored the same way.
Register the server with Claude Code, or with [mcp-hub](https://github.com/ARMINSHIVES/mcp-hub) as a stdio backend:
```
claude mcp add social-publisher -- <venv python> <repo>/serve.py
```
Run the scheduler worker if you schedule Instagram or TikTok posts:
```
.venv\Scripts\python -m social_publisher worker
```
CLI commands: `serve`, `worker`, `auth`, `secret set|check`, `approve POST_ID`, `resolve POST_ID posted [ID]`, `resolve POST_ID not-posted`, `list`.
## How it works
A video carries a metadata JSON next to it (`samples/sample_story.json` shows the format): title, description, tags, per-platform captions, the AI flag, asset licences and a decision log. `prepare_post` reads it, checks the file with ffprobe and queues the post. `approve_post` shows you the exact file, caption and account and records your yes. `publish_post` shows a dry run by default, and a call with `dry_run=false` posts for real. It re-checks both hashes first, and calling it twice never posts twice.
| Path | What it is |
|---|---|
| `social_publisher/server.py` | The FastMCP tools |
| `social_publisher/gate.py` | Queueing, the hash lock, caps, spacing, quiet hours, the approval text |
| `social_publisher/actions.py` | The post state machine, including `needs_check` |
| `social_publisher/youtube.py`, `instagram.py`, `tiktok.py` | Platform clients |
| `social_publisher/oauth.py`, `vault.py` | Loopback OAuth sign-in and keyring storage |
| `social_publisher/storage.py` | Temporary S3-compatible bucket for Instagram's `video_url` |
| `social_publisher/bandit.py` | The suggestion bandits |
| `social_publisher/worker.py` | APScheduler process for scheduled posts |
| `social_publisher/media.py`, `db.py`, `net.py`, `config.py` | ffprobe checks, SQLite queue, retries, settings |
| `serve.py` | Entry point for clients that start servers by file path |
## Configuration
`config.toml` holds no secrets. It sets `quiet_hours`, the `[caps.<platform>]` tables (`daily`, `min_gap_hours`), the YouTube category and chunk size, Instagram's Graph version and polling, the TikTok chunk size, the `[bucket]` for Instagram's temporary upload (any S3-compatible store: Cloudflare R2, S3, B2) and the `[bandit]` arms. `SOCIAL_PUBLISHER_STATE` moves the state folder (the SQLite queue) and `SOCIAL_PUBLISHER_CONFIG` points at another config file.
## Limits and known gaps
- Official APIs only, for your own accounts. There is no scraping and no multi-account tooling.
- TikTok goes through the inbox route. The video lands in your TikTok inbox as a draft, and you finish it in the app: add the caption, switch on the AI-generated label and tap Post. The inbox API can't send the caption or the AI flag, so the tool hands back the caption to paste and a reminder.
- Instagram needs a public URL for the video, which is why the temporary bucket exists.
- The Instagram Reels insight metric names in `config.toml` were not confirmed against the platform docs. If the API rejects one, the error lists the valid names.
- Only Windows was tested. The credential wording and the sign-in flow assume Windows Credential Manager.
- The tests use fake platforms, so they don't cover live posting. Dry-run first on your own accounts.
- Platform rules change. Check each platform's current developer terms before you rely on the caps.
## Licence
MIT, Armaan Francisco Shivpuri. Dependencies: fastmcp (Apache-2.0), httpx (BSD-3), google-api-python-client, google-auth-oauthlib and google-auth-httplib2 (Apache-2.0), keyring (MIT), APScheduler (MIT), boto3 (Apache-2.0). Tests use pytest (MIT), pytest-asyncio (Apache-2.0) and respx (BSD-3). ffmpeg is a system tool and is not bundled.
## Part of Manez
This is the publishing step of [Manez](https://github.com/ARMINSHIVES). The other parts are [mcp-hub](https://github.com/ARMINSHIVES/mcp-hub), [grounded-kb](https://github.com/ARMINSHIVES/grounded-kb) and [limit-aware-launcher](https://github.com/ARMINSHIVES/limit-aware-launcher).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues