# prgebish/mcp-telegram architecture

> Architecture diagram of the GitHub repository prgebish/mcp-telegram, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prgebish/mcp-telegram
- Repository: https://github.com/prgebish/mcp-telegram

## Overview

mcp-telegram is an MCP server that lets an AI assistant read and manage a real Telegram account through the User API. The main workflow is stdio MCP requests routed to registered tools, which resolve typed peer references, enforce per-chat permissions, and perform Telegram operations; configuration, lazy peer resolution, session handling, and RPC rate limiting support that workflow. The README documents the full tool set, while several tool implementations were not excerpted, so their internal call details are not inferred.

Main entry points: [`internal/tools/tools.go`](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/tools.go) (MCP tool registry), [`cmd/mcp-telegram/main.go`](https://github.com/prgebish/mcp-telegram/blob/main/cmd/mcp-telegram/main.go) (CLI and server), [`internal/acl/acl.go`](https://github.com/prgebish/mcp-telegram/blob/main/internal/acl/acl.go) (Permission checker), [`internal/telegram/client.go`](https://github.com/prgebish/mcp-telegram/blob/main/internal/telegram/client.go) (Telegram client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["MCP entry"]
  node_main["CLI and server<br/>[main.go]"]
  node_tool_registry["MCP tool registry<br/>[tools.go]"]
end

subgraph group_access["Access and setup"]
  node_config["Configuration<br/>[config.go]"]
  node_acl["Permission checker<br/>[acl.go]"]
  node_limiter["RPC rate limiter<br/>[ratelimit.go]"]
end

subgraph group_telegram["Telegram connection"]
  node_peer_resolution["Lazy peer resolution<br/>[peers.go]"]
  node_client["Telegram client<br/>[client.go]"]
end

subgraph group_operations["Telegram tools"]
  node_me["Account info<br/>[me.go]"]
  node_dialogs["Dialog listing<br/>[dialogs.go]"]
  node_history["Message history and media<br/>[history.go]"]
  node_search["Message search<br/>[search.go]"]
  node_send["Send text and files<br/>[send.go]"]
  node_forward["Forward messages<br/>[forward.go]"]
  node_draft["Save drafts<br/>[draft.go]"]
  node_mark_read["Mark read<br/>[markread.go]"]
end

node_assistant(("AI assistant"))
node_telegram_api{{"Telegram User API"}}

node_assistant -->|"starts stdio"| node_main
node_main -->|"loads settings"| node_config
node_main -->|"builds checker"| node_acl
node_main -->|"creates limiter"| node_limiter
node_main -->|"starts client"| node_client
node_main -->|"registers tools"| node_tool_registry
node_tool_registry -->|"registers"| node_me
node_tool_registry -->|"registers"| node_dialogs
node_tool_registry -->|"registers"| node_history
node_tool_registry -->|"registers"| node_search
node_tool_registry -->|"registers"| node_send
node_tool_registry -->|"registers"| node_forward
node_tool_registry -->|"registers"| node_draft
node_tool_registry -->|"registers"| node_mark_read
node_client -->|"installs middleware"| node_limiter
node_client -->|"connects"| node_telegram_api
node_tool_registry -->|"resolves peers"| node_peer_resolution
node_peer_resolution -->|"builds identity"| node_acl
node_dialogs -->|"checks permissions"| node_acl
node_history -->|"checks read access"| node_acl
node_search -->|"checks read access"| node_acl
node_send -->|"checks send access"| node_acl
node_history -->|"fetches history"| node_telegram_api
node_search -->|"searches messages"| node_telegram_api
node_send -->|"sends messages"| node_telegram_api
node_me -->|"reads account"| node_telegram_api
node_dialogs -->|"lists dialogs"| node_telegram_api
node_forward -->|"forwards messages"| node_telegram_api
node_draft -->|"saves draft"| node_telegram_api
node_mark_read -->|"marks read"| node_telegram_api

click node_main "https://github.com/prgebish/mcp-telegram/blob/main/cmd/mcp-telegram/main.go"
click node_config "https://github.com/prgebish/mcp-telegram/blob/main/internal/config/config.go"
click node_acl "https://github.com/prgebish/mcp-telegram/blob/main/internal/acl/acl.go"
click node_limiter "https://github.com/prgebish/mcp-telegram/blob/main/internal/ratelimit/ratelimit.go"
click node_peer_resolution "https://github.com/prgebish/mcp-telegram/blob/main/internal/telegram/peers.go"
click node_client "https://github.com/prgebish/mcp-telegram/blob/main/internal/telegram/client.go"
click node_tool_registry "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/tools.go"
click node_me "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/me.go"
click node_dialogs "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/dialogs.go"
click node_history "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/history.go"
click node_search "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/search.go"
click node_send "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/send.go"
click node_forward "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/forward.go"
click node_draft "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/draft.go"
click node_mark_read "https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/markread.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_tool_registry,node_telegram_api toneBlue
class node_config,node_acl,node_limiter toneAmber
class node_peer_resolution,node_client toneMint
class node_me,node_dialogs,node_history,node_search,node_send,node_forward,node_draft,node_mark_read toneRose
class node_assistant toneIndigo
```

## Components

### MCP entry

- [CLI and server](https://github.com/prgebish/mcp-telegram/blob/main/cmd/mcp-telegram/main.go): `cmd/mcp-telegram/main.go`
- [MCP tool registry](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/tools.go): `internal/tools/tools.go`

### Access and setup

- [Configuration](https://github.com/prgebish/mcp-telegram/blob/main/internal/config/config.go): `internal/config/config.go`
- [Permission checker](https://github.com/prgebish/mcp-telegram/blob/main/internal/acl/acl.go): `internal/acl/acl.go`
- [RPC rate limiter](https://github.com/prgebish/mcp-telegram/blob/main/internal/ratelimit/ratelimit.go): `internal/ratelimit/ratelimit.go`

### Telegram connection

- [Lazy peer resolution](https://github.com/prgebish/mcp-telegram/blob/main/internal/telegram/peers.go): `internal/telegram/peers.go`
- [Telegram client](https://github.com/prgebish/mcp-telegram/blob/main/internal/telegram/client.go): `internal/telegram/client.go`

### Telegram tools

- [Account info](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/me.go): `internal/tools/me.go`
- [Dialog listing](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/dialogs.go): `internal/tools/dialogs.go`
- [Message history and media](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/history.go): `internal/tools/history.go`
- [Message search](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/search.go): `internal/tools/search.go`
- [Send text and files](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/send.go): `internal/tools/send.go`
- [Forward messages](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/forward.go): `internal/tools/forward.go`
- [Save drafts](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/draft.go): `internal/tools/draft.go`
- [Mark read](https://github.com/prgebish/mcp-telegram/blob/main/internal/tools/markread.go): `internal/tools/markread.go`

### Other components

- **AI assistant**
- **Telegram User API**

## Connections

- AI assistant → CLI and server: starts stdio (evidence: `README.md`)
- CLI and server → Configuration: loads settings (evidence: `cmd/mcp-telegram/main.go`)
- CLI and server → Permission checker: builds checker (evidence: `cmd/mcp-telegram/main.go`)
- CLI and server → RPC rate limiter: creates limiter (evidence: `cmd/mcp-telegram/main.go`)
- CLI and server → Telegram client: starts client (evidence: `cmd/mcp-telegram/main.go`)
- CLI and server → MCP tool registry: registers tools (evidence: `cmd/mcp-telegram/main.go`)
- MCP tool registry → Account info: registers (evidence: `internal/tools/tools.go`)
- MCP tool registry → Dialog listing: registers (evidence: `internal/tools/tools.go`)
- MCP tool registry → Message history and media: registers (evidence: `internal/tools/tools.go`)
- MCP tool registry → Message search: registers (evidence: `internal/tools/tools.go`)
- MCP tool registry → Send text and files: registers (evidence: `internal/tools/tools.go`)
- MCP tool registry → Forward messages: registers (evidence: `internal/tools/tools.go`)
- MCP tool registry → Save drafts: registers (evidence: `internal/tools/tools.go`)
- MCP tool registry → Mark read: registers (evidence: `internal/tools/tools.go`)
- Telegram client → RPC rate limiter: installs middleware (evidence: `internal/telegram/client.go`)
- Telegram client → Telegram User API: connects (evidence: `internal/telegram/client.go`)
- MCP tool registry → Lazy peer resolution: resolves peers
- Lazy peer resolution → Permission checker: builds identity (evidence: `internal/telegram/peers.go`)
- Dialog listing → Permission checker: checks permissions (evidence: `internal/tools/dialogs.go`)
- Message history and media → Permission checker: checks read access (evidence: `README.md`)
- Message search → Permission checker: checks read access (evidence: `internal/tools/search.go`)
- Send text and files → Permission checker: checks send access (evidence: `internal/tools/send.go`)
- Message history and media → Telegram User API: fetches history (evidence: `README.md`)
- Message search → Telegram User API: searches messages (evidence: `internal/tools/search.go`)
- Send text and files → Telegram User API: sends messages (evidence: `internal/tools/send.go`)
- Account info → Telegram User API: reads account (evidence: `README.md`)
- Dialog listing → Telegram User API: lists dialogs (evidence: `README.md`)
- Forward messages → Telegram User API: forwards messages (evidence: `README.md`)
- Save drafts → Telegram User API: saves draft (evidence: `README.md`)
- Mark read → Telegram User API: marks read (evidence: `README.md`)
