Skip to content

feat(mcp): add Telegram Bot API server#2

Open
kaebmoo wants to merge 11 commits into
thClaws:mainfrom
kaebmoo:main
Open

feat(mcp): add Telegram Bot API server#2
kaebmoo wants to merge 11 commits into
thClaws:mainfrom
kaebmoo:main

Conversation

@kaebmoo
Copy link
Copy Markdown

@kaebmoo kaebmoo commented May 7, 2026

Summary

Adds a Telegram MCP server under mcp/telegram-mcp so thClaws agents can send messages, photos, documents, and read recent bot updates through the Telegram Bot API.

Scope

This is an MCP tool surface for agent-initiated Telegram communication. It is intentionally not a Telegram UI bridge for thClaws.

Included tools:

  • telegram_send_message
  • telegram_send_photo
  • telegram_send_document
  • telegram_get_updates

Security

  • Reads bot token from TELEGRAM_BOT_TOKEN
  • Requires TELEGRAM_ALLOWED_CHAT_IDS
  • Requires TELEGRAM_ALLOWED_FILE_ROOTS for file uploads
  • Rejects URL uploads
  • Uses size guards for Telegram upload limits
  • Opens files with O_NOFOLLOW where supported
  • SSE binds to 127.0.0.1 by default
  • README documents privacy and UI-bridge limitations

Documentation

The README covers:

  • local install
  • thClaws .thclaws/mcp.json setup
  • stdio vs SSE transport and ports
  • manual smoke tests without thClaws
  • scope and limitations
  • future work for reply tools or a Telegram UI bridge

Testing

  • PYTHONPATH=mcp/telegram-mcp/src python3 -m pytest mcp/telegram-mcp/tests
  • manual tools/list stdio smoke test
  • manual telegram_send_message stdio smoke test

Notes

This PR does not modify thClaws core. A full Telegram chat UI would require a separate bridge or core transport design and is documented as future work.

kaebmoo added 11 commits May 7, 2026 10:12
branch `feat/telegram-mcp`

ปรับหลัก ๆ:
- Telegram HTTP 400/403 จะ parse JSON body ก่อน `raise_for_status()` แล้ว surface `description` เช่น `chat not found`
- SSE default bind จาก `0.0.0.0` เป็น `127.0.0.1`, override ได้ด้วย `MCP_HOST`
- เพิ่ม `TELEGRAM_ALLOWED_FILE_ROOTS` สำหรับ sandbox ไฟล์ upload
- เพิ่ม size guard: photo 10 MB, document 50 MB
- `_telegram_result` คืน raw result แล้ว caller จัดการเอง
- validate `parse_mode` และข้อความเกิน 4096 chars
- `getUpdates` 409 webhook conflict จะบอก hint เรื่อง `deleteWebhook`
- รองรับ update kinds เพิ่ม: `my_chat_member`, `chat_member`, `chat_join_request`
- README เพิ่ม config/security notes และปรับ install command ไม่ hardcode upstream path ที่ยังไม่มีไฟล์ก่อน PR merge

เพิ่ม tests จาก 10 เป็น 19 ตัว และผ่านทั้งหมด:

```bash
PYTHONPATH=mcp/telegram-mcp/src python3 -m pytest mcp/telegram-mcp/tests
# 19 passed
```

ไฟล์ที่แก้:
- [server.py](/Users/seal/Documents/GitHub/thclaws-marketplace/mcp/telegram-mcp/src/telegram_mcp/server.py)
- [test_server.py](/Users/seal/Documents/GitHub/thclaws-marketplace/mcp/telegram-mcp/tests/test_server.py)
- [README.md](/Users/seal/Documents/GitHub/thclaws-marketplace/mcp/telegram-mcp/README.md)
@kaebmoo kaebmoo requested a review from mozeal as a code owner May 7, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant