Telegram Lead Analysis MCP
A read-only MCP server that exposes Telegram lead conversations to Claude for sales analysis, enabling lead summary, intent, stage, and follow-up insights.
README
Telegram Lead Analysis MCP
A read-only MCP server that exposes a team's Telegram lead conversations to Claude for sales analysis — lead summary, intent, stage, objections, next/missed follow-ups, hot/warm/cold, action items.
The server does no reasoning and calls no LLM. It returns clean, structured message data; the connected Claude client does the thinking.
Status
- Data source today: a Telegram Desktop JSON export (frozen snapshot).
- Data source later: a live Telethon connection (same interface, no tool
changes). The
TelethonLeadDataSourcestub is already in place.
Guarantees
- Read-only by construction. There is no send/edit/delete code path anywhere.
- Whitelist enforced at the data layer (
datasource/base.py), not just in the tools — a tool physically cannot return a non-whitelisted chat. - Every tool call is logged with the chat it touched to
logs/access.log. - No credentials in code. The live source reads
TELEGRAM_API_ID,TELEGRAM_API_HASH,TELEGRAM_SESSIONfrom the environment only.
Project layout
server.py MCP server + tool definitions
datasource/
base.py LeadDataSource interface (whitelist + text normalize)
json_source.py JSONLeadDataSource (active)
telethon_source.py TelethonLeadDataSource (stub for live access)
config/whitelist.json JSON list of in-scope lead chat names
data/leads_export.json the export (sample fixture ships; replace with real)
logs/access.log access log (created at runtime)
requirements.txt
Go live with Edrian's account (copy-paste runbook)
You have his api_id, api_hash, and session string. Do this once:
1. Paste the 3 values into .env (open the .env file in the project root):
TELEGRAM_API_ID=1234567
TELEGRAM_API_HASH=abc123...
TELEGRAM_SESSION=1Aa...
2. List his chats so you can pick the leads:
.\.venv\Scripts\python.exe list_all_chats.py
3. Put the lead chat names into config/whitelist.json (exactly as printed), e.g.:
["Acme Corp", "Beta Logistics"]
4. Test it end-to-end against the live account:
.\.venv\Scripts\python.exe -c "import server; print(server.list_chats())"
That's it — the server auto-detects the credentials and uses the live account
(LEADS_SOURCE=auto). To go back to the sample export for testing, set
LEADS_SOURCE=json in .env. The session string lives only in .env (which is
gitignored) — never in code.
Setup
Requires Python 3.10+.
# from the project root
python -m venv .venv
# Windows PowerShell: .venv\Scripts\Activate.ps1
# macOS/Linux: source .venv/bin/activate
pip install -r requirements.txt
1. Provide the data
Replace data/leads_export.json with the slimmed lead-chat export (lead
chats only — not a full account dump). The loader accepts the standard Telegram
Desktop shapes: {"chats": {"list": [...]}}, a top-level list, or a single-chat
{"name", "messages"} object.
A sample fixture ships in the repo so you can run the server immediately.
2. Set the whitelist
Edit config/whitelist.json — a JSON array of the exact chat names that are
leads. Anything not listed is invisible to every tool.
["Acme Corp — Jordan", "Beta Logistics — Priya"]
Tip: run list_chats after pointing the loader at the full export to see the
names, then narrow the whitelist to the real leads.
Tools
| Tool | Status | What it does |
|---|---|---|
list_chats |
✅ | Whitelisted chats: name, message count, last message date. |
get_chat_messages(chat_name, limit=100, since_date=None) |
✅ | Cleaned message history for one whitelisted chat. |
analyze_lead_conversation(chat_name) |
✅ | Full thread as ordered {sender, timestamp, text} for the client to analyze. |
search_chats |
🚧 stub | Keyword search across whitelisted chats. |
extract_followups |
🚧 stub | Promised/missed follow-ups. |
summarize_conversation |
🚧 stub | Server-side summary (deferred). |
create_task_or_note |
🚧 stub | Task/note creation (write path, inert). |
Run / smoke test
# Verify the data layer and tools without an MCP client:
python smoke_test.py
To run the MCP server directly (it speaks stdio and waits for a client):
python server.py
Deploy to Railway (remote URL connector)
For connecting Claude to a hosted URL instead of running locally. The server
auto-switches to HTTP transport when a PORT env var is present (Railway
sets it), so no code change is needed.
1. Push this repo to GitHub (done) and create a Railway project from the repo.
2. Set environment variables in Railway (Settings → Variables) — these
replace the local .env, which is never committed:
| Variable | Value |
|---|---|
TELEGRAM_API_ID |
Edrian's api_id |
TELEGRAM_API_HASH |
Edrian's api_hash |
TELEGRAM_SESSION |
the session string |
LEADS_WHITELIST_JSON |
(optional) inline JSON array of lead chat names; overrides the committed config/whitelist.json so client names need not live in git |
TELEGRAM_FETCH_LIMIT |
(optional) default 500 |
Railway provides PORT automatically — don't set it.
3. Deploy. Railway builds via Nixpacks (requirements.txt) and runs
python server.py (see Procfile / railway.json). The MCP endpoint is:
https://<your-app>.up.railway.app/mcp
4. Connect Claude (claude.ai → Settings → Connectors → Add custom connector)
to that /mcp URL.
⚠️ Security: this endpoint exposes the account's lead chats to anyone who can reach the URL — it has no built-in auth. Keep the URL private, and prefer putting an auth layer (or Railway private networking) in front of it before sharing. The session string is full account access; treat the deployment as sensitive.
Register with Claude Desktop
Add this to your Claude Desktop config
(%APPDATA%\Claude\claude_desktop_config.json on Windows,
~/Library/Application Support/Claude/claude_desktop_config.json on macOS).
Use absolute paths.
{
"mcpServers": {
"telegram-lead-analysis": {
"command": "d:\\ZeroPenny\\Telegram MCP\\.venv\\Scripts\\python.exe",
"args": ["d:\\ZeroPenny\\Telegram MCP\\server.py"]
}
}
}
Restart Claude Desktop, then ask it to "list my Telegram lead chats" or "analyze the Acme Corp lead".
Switching to live Telegram (later)
- Implement the
_raw_*hooks indatasource/telethon_source.py. - In
server.py, swap the one line inbuild_data_source()fromJSONLeadDataSource(...)toTelethonLeadDataSource(whitelist). - Set
TELEGRAM_API_ID,TELEGRAM_API_HASH,TELEGRAM_SESSIONin the environment (e.g. via the Claude Desktop config"env"block). No tool definitions change.
A note on the export Edrian sent
The export received was the entire account (672 chats, contacts, stories, phone number) — far more than the lead chats and a privacy over-share. Treat it as a throwaway test fixture only. For the real build we need just the specific lead chats plus the session credentials. Tell Edrian he over-shared.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。