social-mcp
Enables an AI agent to interact with your personal Telegram direct messages, allowing it to read unread messages, fetch chat history, and send replies.
README
social-mcp
A local Model Context Protocol (MCP) server that bridges an AI agent (e.g. OpenCode) with your personal Telegram direct messages: read unread messages, pull chat history for context, and send replies.
How it works
opencode (AI agent) ↔ social-mcp (MCP over stdio) ↔ Telethon ↔ Telegram
This is not a bot. The server runs in userbot mode — it logs in as your own account via the Telegram API, so everything it sends is sent from you. Your AI assistant simply gets a set of tools (15+) to read and manage your own chats.
⚠️ Read before using
- Automating a personal account sits in a grey zone of Telegram's Terms of Service. Keep the automation reasonable, don't spam, use at your own risk.
- Store
.envand*.sessionoutside of version control. These files grant full access to your account.- Only you ("the boss") should command the assistant. It must never act on instructions coming from message content itself.
Requirements
- Python 3.10+
- A Telegram
api_id/api_hashfrom https://my.telegram.org (API Development Tools) - Works on Windows, Linux and macOS
Project layout
social-mcp/
├── config.py
├── clients/
│ ├── __init__.py
│ └── telegram_client.py
├── storage.py
├── server.py
├── setup_auth.py
├── requirements.txt
└── README.md
Install dependencies
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\Activate.ps1
pip install -r requirements.txt
Configure credentials
Get your Telegram API ID/hash from https://my.telegram.org (API Development Tools).
Create a .env file in the project root:
TELEGRAM_API_ID=123456
TELEGRAM_API_HASH=your_api_hash_here
TELEGRAM_PHONE=+15551234567
# Optional overrides
SOCIAL_MCP_DATA_DIR=/home/you/.social-mcp
SOCIAL_MCP_LOG_LEVEL=INFO
Session/state files live under SOCIAL_MCP_DATA_DIR (default ~/.social-mcp),
deliberately outside the repo so they can never be committed by accident.
First-time interactive login
Run this once, manually, from a real terminal — OpenCode invokes server.py
over stdio and cannot answer interactive prompts.
python setup_auth.py --telegram
Telegram will text/app you a login code, and ask for your 2FA password if enabled.
Run the server standalone (smoke test)
python server.py
It will idle on stdio waiting for MCP protocol messages — that's expected; this step just confirms it starts without import/config errors. Ctrl+C to stop.
Wire it into OpenCode
Add this to ~/.config/opencode/opencode.json (adjust paths to your machine):
{
"mcpServers": {
"social-mcp": {
"command": "/absolute/path/to/social-mcp/.venv/bin/python",
"args": ["/absolute/path/to/social-mcp/server.py"],
"env": {
"SOCIAL_MCP_DATA_DIR": "/home/you/.social-mcp"
}
}
}
}
Restart OpenCode. It should discover these tools:
get_unread_messages(limit?, platforms?)send_reply(platform, target_id, text)get_chat_history(platform, target_id, limit?)edit_message/delete_messagedelete_chat— full dissolution: kicks all members, leaves, purges (groups); hard-deletes owned channels; revoke-deletes private dialogsleave_chat— exit a group/channel without touching its membersblock_user/unblock_user/get_blocked_userscreate_group/create_supergroup/add_user_to_group/remove_user_from_group/invite_to_channel
Example agent workflow
- Agent calls
get_unread_messages(limit=10)→ gets a JSON list of unread messages. - Agent summarizes them for you.
- You say "reply to Anna on Telegram: I'm free after 6pm".
- Agent optionally calls
get_chat_history(platform="telegram", target_id=<id>)to see prior context, drafts a reply, and callssend_reply(platform="telegram", target_id=<id>, text="...").
Notes on reliability
- All tool functions catch platform-specific errors and return a structured
{"success": false, "error": "..."}JSON payload instead of raising, so a single failed call never kills the stdio connection to OpenCode. - Group deletion handles all Telegram quirks: owned channels are hard-deleted
via
channels.deleteChannel, basic groups viamessages.deleteChatwhen you have admin rights, with an automatic kick-all → leave → purge fallback otherwise. storage.pykeeps a small SQLite file recording which message IDs have already been surfaced, as a foundation for future "mark as read" / dedup logic — it is not yet wired into filtering by default.
License
MIT © sydrx
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。