tg-agent
Server Configuration
Describes the environment variables required to run the server.
| Name | Required | Description | Default |
|---|---|---|---|
| TGA_PORT | No | The port the TG Agent service listens on (default 17865). The service listens on 127.0.0.1 only and requires an access token on every API and MCP request. | |
| TGA_DATA_DIR | No | Override where TG Agent stores its data. Running from a checkout (start.bat / start.sh), everything lives next to the code; installed packages use ~/.tg-agent. |
Instructions
Guidance the server publishes about itself, which clients place ahead of the tool catalog so the model reads it before choosing anything.
TG Agent gives you read-only access to the user's Telegram (channels, groups, chats) and fast file downloads. The user watches every call live in the TG Agent web console, grouped into workflows.
Rules:
At the start of EVERY new user request call tg_start_workflow(title=...) with a short title in the user's language. When the request is done call tg_finish_workflow(summary=...).
After tg_download, call tg_wait_tasks instead of polling tg_tasks in a loop.
This is the user's real account: avoid unnecessary requests. Prefer tg_search_files / tg_compare_chats on the local index; use tg_index_chat or tg_export for complete listings of large chats.
Check count and total size with tg_plan_download before big downloads. Batches above the user's limit wait for approval in the console; tell the user when that happens.
When descriptions and files live in different chats, use tg_match_posts / tg_file_context(intro_chat=...).
When unsure (several versions, ambiguous matches), ask the user with tg_ask_user instead of guessing.
For long listings pass format="compact" (and fields=[...]) to save context. tg_search_archive and tg_search_files search locally without Telegram requests. Write useful findings into tg_notes.
The service never sends messages and never joins chats.
Capabilities
Features and capabilities supported by this server
Protocol revision2025-11-25
| Capability | Details |
|---|---|
| tools | {
"listChanged": false
} |
| prompts | {
"listChanged": false
} |
Tools
Functions exposed to the LLM to take actions
| Name | Description |
|---|---|
| tg_start_workflowA | Call this FIRST for every new user request, before any other tg_* tool, with a short title describing the request (in the user's language). The user watches your calls grouped under this workflow in the TG Agent console. Starting a new workflow closes the previous one. |
| tg_finish_workflowA | Call this when you have finished the user's request, with a one-sentence summary of the outcome. |
| tg_list_accountsB | List configured Telegram accounts and their login status. |
| tg_list_dialogsC | List the channels, groups and private chats the account has joined (including private channels). |
| tg_resolve_chatA | Resolve a chat or link: id, title, about, member count, public or not, joined or not, latest message id. Also inspects invite links (t.me/+xxx) without joining. |
| tg_get_messagesA | Read a chat's history (newest first by default). Page with offset_id=next_offset_id. Supports date range, id range, keyword and media-only. |
| tg_search_messagesA | Keyword search in one chat (if chat is given) or across all joined chats. |
| tg_get_messageA | Full content and file details of one message (albums include their other items). Pass link (e.g. https://t.me/name/123) or chat + message_id. |
| tg_list_filesA | List files in a chat (metadata only: name, size, kind, date, link) with filters, plus count and total size. Scans up to 5000 messages per call; continue with next_offset_id. Files seen are also saved to the local index. For a complete list of a big chat use tg_index_chat or tg_export. |
| tg_exportA | Export a chat's complete file list (what=files) or message history (what=messages) to csv/json/jsonl/md in the background. Returns task_id and output_path; read the file when the task is done. |
| tg_downloadA | Queue files for download (parallel connections, resumable) and return task ids immediately. Three ways: 1) links=[message links]; 2) chat + message_ids; 3) chat + filters + limit (batch). Large batches above the user's limit wait for approval in the console (the result says requires_approval). Check size first with tg_list_files. |
| tg_plan_downloadA | Dry run of tg_download with the same arguments: how many files, total size, split-archive sets (and missing volumes), files already downloaded elsewhere, whether approval will be needed, and an estimated duration. Nothing is queued. Use it before large downloads. |
| tg_wait_tasksA | Wait until the given tasks finish (or need the user's approval), up to timeout_s, and return their final state. Sends progress notifications when the client supports them. Use this instead of polling tg_tasks. |
| tg_tasksB | Status, progress, speed and ETA of download/export/index tasks, overall stats, and batches waiting for approval. |
| tg_task_controlA | Pause, resume, retry, cancel or remove tasks by task_ids, or all=true for every applicable task. |
| tg_index_chatA | Scan a chat in the background and store all its file metadata in the local index (incremental: only new messages since the last scan unless full=true). Afterwards tg_search_files and tg_compare_chats work offline. |
| tg_index_statusA | List chats in the local index with file counts, total size and whether they are fully indexed. |
| tg_search_filesA | Search files across all indexed chats WITHOUT contacting Telegram: by words in name/caption, chats, kinds, extensions and size; sort by date, size or name. |
| tg_compare_chatsA | Compare the indexed files of two chats: what both have, what only one has. by=name (same file name), name_size (same name and size), stem (name without extension/punctuation) or file (identical Telegram file). |
| tg_watchB | Manage watches that automatically download new matching files from a chat. action=list|add|remove|pause|resume|check. Watches you add stay disabled until the user approves them in the console. |
| tg_search_archiveA | Full-text search over messages the service has already read or indexed (titles, versions, passwords, descriptions) WITHOUT contacting Telegram. Use tg_index_chat on a chat to archive all of its messages. |
| tg_file_contextA | Everything around one file message: its caption, neighbouring posts and album items, plus extracted passwords, versions, links and sizes. With intro_chat, also finds the matching description post in that chat. Use it before downloading or extracting archives. |
| tg_match_postsA | Pair description posts in intro_chat with files in files_chat (which must be indexed). Split archives are grouped. Returns, per post, the best matching files with a score, message ids and any passwords/versions found in the post. Typical use: one channel announces/describes, another hosts the downloads. |
| tg_ask_userA | Ask the user a question in the TG Agent console and wait for the answer (e.g. which of two versions to download). Give options when possible. Returns the answer, or answered=false after timeout_s. |
| tg_notesB | Shared, persistent notes about a chat for every agent and the user (naming patterns, where passwords are posted, which channel holds the files…). action=get|set|append|delete|list. tg_resolve_chat returns the note too. |
| tg_list_recipesC | Reusable workflows (built-in and saved by the user) with their parameters. |
| tg_run_recipeB | Run a recipe by name with parameters. It runs in the background as its own workflow and returns its workflow_id. |
| tg_extractA | Test or extract downloaded archives with 7-Zip (split sets start from their first volume). Pass finished download task_ids or paths inside the download folder, and the password if there is one (see tg_file_context). Runs as background tasks; use tg_wait_tasks. |
Prompts
Interactive templates invoked by user choice
| Name | Description |
|---|---|
| tg_intro_and_download | Find items in a channel of descriptions and download the matching files from another channel. |
| recipe_channel_inventory | Index every file of a chat into the local library and report counts and total size. |
| recipe_download_latest | Plan and download the newest files of a chat (split archives are completed automatically). |
| recipe_compare_chats | Index two chats and list what they share and what only one of them has. |
| recipe_match_intro_to_files | Read an intro channel, index the download channel, and pair each intro post with its files. |
Resources
Contextual data attached and managed by the client
| Name | Description |
|---|---|
No resources | |
TDQS
Scored across 28 tools
Most tools occupy a clearly distinct niche (live Telegram reads vs. offline index search vs. task control), and descriptions explicitly cross-reference each other. The main friction is the cluster of search/list tools: tg_search_messages, tg_search_archive, tg_search_files, tg_list_files, tg_list_dialogs and tg_get_messages require care to pick correctly, and tg_tasks vs. tg_wait_tasks vs. tg_task_control vs. tg_index_status overlap around background jobs.
All 28 tools share the tg_ prefix and snake_case, and the majority follow a verb_noun shape (tg_list_files, tg_resolve_chat, tg_plan_download). A few are noun-only or multi-action containers (tg_tasks, tg_notes, tg_watch), which is a minor but visible deviation.
28 tools is on the heavy side for a single server and exceeds the comfortable range, even though the surface genuinely spans indexing, search, downloads, extraction and workflow bookkeeping. Borderline: a few bookkeeping/sugar tools (tg_notes, tg_index_status, tg_compare_chats, recipes) could conceivably be folded in, making the set feel sprawling.
The core lifecycle is well covered: discover chats, index, search offline, get context, plan, download, wait, extract, plus workflow framing and user interaction. Gaps are peripheral rather than blocking — there is no way to add/login an account, and no tools for sending, uploading or forwarding messages into Telegram, so the surface is purely read/download oriented.