Telegram send file
tg_send_fileSend files to a Telegram chat using a bot. Supports file URLs, captions, and message threading.
Instructions
Send general files via telegram bot
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | File URL | |
| chat_id | No | Telegram chat id, Default to get from environment variables | |
| caption | No | File caption, 0-1024 characters after entities parsing | |
| parse_mode | No | Mode for parsing entities in the caption. [text/MarkdownV2] | |
| reply_to_message_id | No | Identifier of the message that will be replied to |
Implementation Reference
- mcp_notify/tgbot.py:155-171 (handler)The tg_send_file async function that handles sending files via Telegram bot. It accepts url, chat_id, caption, parse_mode, and reply_to_message_id parameters, optionally converts caption using MarkdownV2, then calls bot.send_document() and returns the result as JSON.
async def tg_send_file( url: str = Field(description="File URL"), chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"), caption: str = Field("", description="File caption, 0-1024 characters after entities parsing"), parse_mode: str = Field("", description=f"Mode for parsing entities in the caption. [text/MarkdownV2]"), reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"), ): if parse_mode == TELEGRAM_MARKDOWN_V2: caption = telegramify_markdown.markdownify(caption) res = await bot.send_document( chat_id=chat_id or TELEGRAM_DEFAULT_CHAT, document=url, caption=caption or None, parse_mode=parse_mode if parse_mode in [TELEGRAM_MARKDOWN_V2] else None, reply_to_message_id=reply_to_message_id or None, ) return res.to_json() - mcp_notify/tgbot.py:151-154 (registration)The @mcp.tool() decorator registering tg_send_file as an MCP tool with title 'Telegram send file' and description 'Send general files via telegram bot'.
@mcp.tool( title="Telegram send file", description="Send general files via telegram bot", ) - mcp_notify/__init__.py:19-20 (registration)Registration of the tgbot module's tools (including tg_send_file) via tgbot.add_tools(mcp).
wework.add_tools(mcp) tgbot.add_tools(mcp) - mcp_notify/tgbot.py:16-21 (helper)The add_tools function that registers all Telegram tools on the FastMCP instance, including the bot initialization.
def add_tools(mcp: FastMCP, logger=None): bot = Bot( TELEGRAM_BOT_TOKEN, base_url=f"{TELEGRAM_BASE_URL}/bot", base_file_url=f"{TELEGRAM_BASE_URL}/file/bot", ) if TELEGRAM_BOT_TOKEN else None - mcp_notify/tgbot.py:155-161 (schema)Pydantic Field definitions for tg_send_file parameters: url (str), chat_id (str), caption (str), parse_mode (str), reply_to_message_id (int).
async def tg_send_file( url: str = Field(description="File URL"), chat_id: str = Field("", description="Telegram chat id, Default to get from environment variables"), caption: str = Field("", description="File caption, 0-1024 characters after entities parsing"), parse_mode: str = Field("", description=f"Mode for parsing entities in the caption. [text/MarkdownV2]"), reply_to_message_id: int = Field(0, description="Identifier of the message that will be replied to"), ):