@overpod/mcp-telegram 1.21.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.22.0] - 2026-04-01
11
+
12
+ ### Added
13
+ - `TelegramService.setTyping(chatId, action?)` — send typing indicators with 10 action types: `typing`, `cancel`, `record_video`, `upload_video`, `record_audio`, `upload_audio`, `upload_photo`, `upload_document`, `choose_sticker`, `game_play` (#17)
14
+ - `TelegramService.getMessageById(chatId, messageId)` — fetch a single message by ID, returns formatted message object or `null`. Uses GramJS `ids` filter for exact lookup (#17)
15
+
10
16
  ## [1.21.0] - 2026-04-01
11
17
 
12
18
  ### Added
@@ -87,6 +87,24 @@ export declare class TelegramService {
87
87
  blockUser(userId: string): Promise<void>;
88
88
  reportSpam(chatId: string): Promise<void>;
89
89
  markAsRead(chatId: string): Promise<void>;
90
+ private static TYPING_ACTIONS;
91
+ setTyping(chatId: string, action?: keyof typeof TelegramService.TYPING_ACTIONS): Promise<void>;
92
+ getMessageById(chatId: string, messageId: number): Promise<{
93
+ id: number;
94
+ text: string;
95
+ sender: string;
96
+ date: string;
97
+ media?: {
98
+ type: string;
99
+ fileName?: string;
100
+ size?: number;
101
+ };
102
+ reactions?: {
103
+ emoji: string;
104
+ count: number;
105
+ me: boolean;
106
+ }[];
107
+ } | null>;
90
108
  forwardMessage(fromChatId: string, toChatId: string, messageIds: number[]): Promise<void>;
91
109
  editMessage(chatId: string, messageId: number, newText: string): Promise<void>;
92
110
  deleteMessages(chatId: string, messageIds: number[]): Promise<void>;
@@ -307,4 +325,49 @@ export declare class TelegramService {
307
325
  title?: string;
308
326
  }): Promise<void>;
309
327
  removeAdmin(chatId: string, userId: string): Promise<void>;
328
+ unblockUser(userId: string): Promise<void>;
329
+ muteChat(chatId: string, muteUntil: number): Promise<void>;
330
+ exportInviteLink(chatId: string, options?: {
331
+ expireDate?: number;
332
+ usageLimit?: number;
333
+ requestNeeded?: boolean;
334
+ title?: string;
335
+ }): Promise<string>;
336
+ getInviteLinks(chatId: string, limit?: number, adminId?: string): Promise<Array<{
337
+ link: string;
338
+ title?: string;
339
+ expired: boolean;
340
+ revoked: boolean;
341
+ usageCount: number;
342
+ }>>;
343
+ revokeInviteLink(chatId: string, link: string): Promise<void>;
344
+ getChatFolders(): Promise<Array<{
345
+ id: number;
346
+ title: string;
347
+ emoticon?: string;
348
+ pinnedCount: number;
349
+ includeCount: number;
350
+ }>>;
351
+ setAutoDelete(chatId: string, period: number): Promise<void>;
352
+ getActiveSessions(): Promise<Array<{
353
+ hash: string;
354
+ device: string;
355
+ platform: string;
356
+ appName: string;
357
+ appVersion: string;
358
+ ip: string;
359
+ country: string;
360
+ dateActive: string;
361
+ current: boolean;
362
+ }>>;
363
+ terminateSession(hash: string): Promise<void>;
364
+ terminateAllOtherSessions(): Promise<void>;
365
+ private static PRIVACY_KEYS;
366
+ setPrivacy(setting: string, rule: "everyone" | "contacts" | "nobody", allowUsers?: string[], disallowUsers?: string[]): Promise<void>;
367
+ updateProfile(options: {
368
+ firstName?: string;
369
+ lastName?: string;
370
+ bio?: string;
371
+ }): Promise<void>;
372
+ updateUsername(username: string): Promise<void>;
310
373
  }
@@ -526,6 +526,45 @@ export class TelegramService {
526
526
  throw new Error(NOT_CONNECTED_ERROR);
527
527
  await this.client.markAsRead(chatId);
528
528
  }
529
+ static TYPING_ACTIONS = {
530
+ typing: () => new Api.SendMessageTypingAction(),
531
+ cancel: () => new Api.SendMessageCancelAction(),
532
+ record_video: () => new Api.SendMessageRecordVideoAction(),
533
+ upload_video: () => new Api.SendMessageUploadVideoAction({ progress: 0 }),
534
+ record_audio: () => new Api.SendMessageRecordAudioAction(),
535
+ upload_audio: () => new Api.SendMessageUploadAudioAction({ progress: 0 }),
536
+ upload_photo: () => new Api.SendMessageUploadPhotoAction({ progress: 0 }),
537
+ upload_document: () => new Api.SendMessageUploadDocumentAction({ progress: 0 }),
538
+ choose_sticker: () => new Api.SendMessageChooseStickerAction(),
539
+ game_play: () => new Api.SendMessageGamePlayAction(),
540
+ };
541
+ async setTyping(chatId, action = "typing") {
542
+ if (!this.client || !this.connected)
543
+ throw new Error(NOT_CONNECTED_ERROR);
544
+ const factory = TelegramService.TYPING_ACTIONS[action];
545
+ if (!factory)
546
+ throw new Error(`Unknown typing action: ${action}. Valid: ${Object.keys(TelegramService.TYPING_ACTIONS).join(", ")}`);
547
+ const resolved = await this.resolvePeer(chatId);
548
+ const peer = await this.client.getInputEntity(resolved);
549
+ await this.client.invoke(new Api.messages.SetTyping({ peer, action: factory() }));
550
+ }
551
+ async getMessageById(chatId, messageId) {
552
+ if (!this.client || !this.connected)
553
+ throw new Error(NOT_CONNECTED_ERROR);
554
+ const resolved = await this.resolvePeer(chatId);
555
+ const messages = await this.client.getMessages(resolved, { ids: [messageId] });
556
+ const m = messages[0];
557
+ if (!m || m.id !== messageId)
558
+ return null;
559
+ return {
560
+ id: m.id,
561
+ text: m.message ?? "",
562
+ sender: await this.resolveSenderName(m.senderId),
563
+ date: new Date((m.date ?? 0) * 1000).toISOString(),
564
+ media: this.extractMediaInfo(m.media),
565
+ reactions: this.extractReactions(m.reactions),
566
+ };
567
+ }
529
568
  async forwardMessage(fromChatId, toChatId, messageIds) {
530
569
  if (!this.client || !this.connected)
531
570
  throw new Error(NOT_CONNECTED_ERROR);
@@ -1598,4 +1637,199 @@ export class TelegramService {
1598
1637
  rank: "",
1599
1638
  }));
1600
1639
  }
1640
+ // ── New tools: feature parity ──────────────────────────────────────
1641
+ async unblockUser(userId) {
1642
+ if (!this.client || !this.connected)
1643
+ throw new Error(NOT_CONNECTED_ERROR);
1644
+ const entity = await this.client.getInputEntity(userId);
1645
+ await this.client.invoke(new Api.contacts.Unblock({ id: entity }));
1646
+ }
1647
+ async muteChat(chatId, muteUntil) {
1648
+ if (!this.client || !this.connected)
1649
+ throw new Error(NOT_CONNECTED_ERROR);
1650
+ const resolved = await this.resolvePeer(chatId);
1651
+ const peer = await this.client.getInputEntity(resolved);
1652
+ await this.client.invoke(new Api.account.UpdateNotifySettings({
1653
+ peer: new Api.InputNotifyPeer({ peer }),
1654
+ settings: new Api.InputPeerNotifySettings({ muteUntil }),
1655
+ }));
1656
+ }
1657
+ async exportInviteLink(chatId, options) {
1658
+ if (!this.client || !this.connected)
1659
+ throw new Error(NOT_CONNECTED_ERROR);
1660
+ const resolved = await this.resolvePeer(chatId);
1661
+ const peer = await this.client.getInputEntity(resolved);
1662
+ const result = await this.client.invoke(new Api.messages.ExportChatInvite({
1663
+ peer,
1664
+ expireDate: options?.expireDate,
1665
+ usageLimit: options?.usageLimit,
1666
+ requestNeeded: options?.requestNeeded,
1667
+ title: options?.title,
1668
+ }));
1669
+ if (result instanceof Api.ChatInviteExported) {
1670
+ return result.link;
1671
+ }
1672
+ throw new Error("Failed to export invite link");
1673
+ }
1674
+ async getInviteLinks(chatId, limit = 20, adminId) {
1675
+ if (!this.client || !this.connected)
1676
+ throw new Error(NOT_CONNECTED_ERROR);
1677
+ const resolved = await this.resolvePeer(chatId);
1678
+ const peer = await this.client.getInputEntity(resolved);
1679
+ const admin = adminId ? await this.client.getInputEntity(await this.resolvePeer(adminId)) : new Api.InputUserSelf();
1680
+ const result = await this.client.invoke(new Api.messages.GetExportedChatInvites({
1681
+ peer,
1682
+ adminId: admin,
1683
+ limit,
1684
+ }));
1685
+ return result.invites
1686
+ .filter((inv) => inv instanceof Api.ChatInviteExported)
1687
+ .map((inv) => {
1688
+ const expiredByDate = inv.expireDate ? inv.expireDate < Math.floor(Date.now() / 1000) : false;
1689
+ const expiredByUsage = inv.usageLimit !== undefined && inv.usage !== undefined ? inv.usage >= inv.usageLimit : false;
1690
+ return {
1691
+ link: inv.link,
1692
+ title: inv.title,
1693
+ expired: expiredByDate || expiredByUsage,
1694
+ revoked: inv.revoked ?? false,
1695
+ usageCount: inv.usage ?? 0,
1696
+ };
1697
+ });
1698
+ }
1699
+ async revokeInviteLink(chatId, link) {
1700
+ if (!this.client || !this.connected)
1701
+ throw new Error(NOT_CONNECTED_ERROR);
1702
+ const resolved = await this.resolvePeer(chatId);
1703
+ const peer = await this.client.getInputEntity(resolved);
1704
+ await this.client.invoke(new Api.messages.EditExportedChatInvite({
1705
+ peer,
1706
+ link,
1707
+ revoked: true,
1708
+ }));
1709
+ }
1710
+ async getChatFolders() {
1711
+ if (!this.client || !this.connected)
1712
+ throw new Error(NOT_CONNECTED_ERROR);
1713
+ const result = await this.client.invoke(new Api.messages.GetDialogFilters());
1714
+ const filters = "filters" in result ? result.filters : [];
1715
+ return filters
1716
+ .filter((f) => f instanceof Api.DialogFilter)
1717
+ .map((f) => ({
1718
+ id: f.id,
1719
+ title: typeof f.title === "string" ? f.title : f.title.text,
1720
+ emoticon: f.emoticon,
1721
+ pinnedCount: f.pinnedPeers?.length ?? 0,
1722
+ includeCount: f.includePeers?.length ?? 0,
1723
+ }));
1724
+ }
1725
+ async setAutoDelete(chatId, period) {
1726
+ if (!this.client || !this.connected)
1727
+ throw new Error(NOT_CONNECTED_ERROR);
1728
+ const resolved = await this.resolvePeer(chatId);
1729
+ const peer = await this.client.getInputEntity(resolved);
1730
+ await this.client.invoke(new Api.messages.SetHistoryTTL({ peer, period }));
1731
+ }
1732
+ async getActiveSessions() {
1733
+ if (!this.client || !this.connected)
1734
+ throw new Error(NOT_CONNECTED_ERROR);
1735
+ const result = await this.client.invoke(new Api.account.GetAuthorizations());
1736
+ return result.authorizations.map((a) => ({
1737
+ hash: a.hash.toString(),
1738
+ device: a.deviceModel,
1739
+ platform: a.platform,
1740
+ appName: a.appName,
1741
+ appVersion: a.appVersion,
1742
+ ip: a.ip,
1743
+ country: a.country,
1744
+ dateActive: new Date(a.dateActive * 1000).toISOString(),
1745
+ current: a.current ?? false,
1746
+ }));
1747
+ }
1748
+ async terminateSession(hash) {
1749
+ if (!this.client || !this.connected)
1750
+ throw new Error(NOT_CONNECTED_ERROR);
1751
+ await this.client.invoke(new Api.account.ResetAuthorization({ hash: bigInt(hash) }));
1752
+ }
1753
+ async terminateAllOtherSessions() {
1754
+ if (!this.client || !this.connected)
1755
+ throw new Error(NOT_CONNECTED_ERROR);
1756
+ await this.client.invoke(new Api.auth.ResetAuthorizations());
1757
+ }
1758
+ static PRIVACY_KEYS = {
1759
+ phone_number: () => new Api.InputPrivacyKeyPhoneNumber(),
1760
+ last_seen: () => new Api.InputPrivacyKeyStatusTimestamp(),
1761
+ profile_photo: () => new Api.InputPrivacyKeyProfilePhoto(),
1762
+ forwards: () => new Api.InputPrivacyKeyForwards(),
1763
+ calls: () => new Api.InputPrivacyKeyPhoneCall(),
1764
+ groups: () => new Api.InputPrivacyKeyChatInvite(),
1765
+ bio: () => new Api.InputPrivacyKeyAbout(),
1766
+ };
1767
+ async setPrivacy(setting, rule, allowUsers, disallowUsers) {
1768
+ if (!this.client || !this.connected)
1769
+ throw new Error(NOT_CONNECTED_ERROR);
1770
+ const keyFactory = TelegramService.PRIVACY_KEYS[setting];
1771
+ if (!keyFactory)
1772
+ throw new Error(`Unknown privacy setting: ${setting}. Valid: ${Object.keys(TelegramService.PRIVACY_KEYS).join(", ")}`);
1773
+ const rules = [];
1774
+ // Exceptions must come before the general rule so they are not shadowed
1775
+ if (disallowUsers?.length) {
1776
+ const users = [];
1777
+ const invalid = [];
1778
+ for (const u of disallowUsers) {
1779
+ const inputEntity = await this.client.getInputEntity(u);
1780
+ if (inputEntity instanceof Api.InputPeerUser) {
1781
+ users.push(new Api.InputUser({ userId: inputEntity.userId, accessHash: inputEntity.accessHash }));
1782
+ }
1783
+ else {
1784
+ invalid.push(u);
1785
+ }
1786
+ }
1787
+ if (invalid.length > 0) {
1788
+ throw new Error(`disallowUsers entries are not valid users: ${invalid.join(", ")}`);
1789
+ }
1790
+ if (users.length > 0) {
1791
+ rules.push(new Api.InputPrivacyValueDisallowUsers({ users }));
1792
+ }
1793
+ }
1794
+ if (allowUsers?.length) {
1795
+ const users = [];
1796
+ const invalid = [];
1797
+ for (const u of allowUsers) {
1798
+ const inputEntity = await this.client.getInputEntity(u);
1799
+ if (inputEntity instanceof Api.InputPeerUser) {
1800
+ users.push(new Api.InputUser({ userId: inputEntity.userId, accessHash: inputEntity.accessHash }));
1801
+ }
1802
+ else {
1803
+ invalid.push(u);
1804
+ }
1805
+ }
1806
+ if (invalid.length > 0) {
1807
+ throw new Error(`allowUsers entries are not valid users: ${invalid.join(", ")}`);
1808
+ }
1809
+ if (users.length > 0) {
1810
+ rules.push(new Api.InputPrivacyValueAllowUsers({ users }));
1811
+ }
1812
+ }
1813
+ if (rule === "everyone")
1814
+ rules.push(new Api.InputPrivacyValueAllowAll());
1815
+ else if (rule === "contacts")
1816
+ rules.push(new Api.InputPrivacyValueAllowContacts(), new Api.InputPrivacyValueDisallowAll());
1817
+ else
1818
+ rules.push(new Api.InputPrivacyValueDisallowAll());
1819
+ await this.client.invoke(new Api.account.SetPrivacy({ key: keyFactory(), rules }));
1820
+ }
1821
+ async updateProfile(options) {
1822
+ if (!this.client || !this.connected)
1823
+ throw new Error(NOT_CONNECTED_ERROR);
1824
+ await this.client.invoke(new Api.account.UpdateProfile({
1825
+ firstName: options.firstName,
1826
+ lastName: options.lastName,
1827
+ about: options.bio,
1828
+ }));
1829
+ }
1830
+ async updateUsername(username) {
1831
+ if (!this.client || !this.connected)
1832
+ throw new Error(NOT_CONNECTED_ERROR);
1833
+ await this.client.invoke(new Api.account.UpdateUsername({ username }));
1834
+ }
1601
1835
  }
@@ -0,0 +1,3 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { TelegramService } from "../telegram-client.js";
3
+ export declare function registerAccountTools(server: McpServer, telegram: TelegramService): void;
@@ -0,0 +1,280 @@
1
+ import { z } from "zod";
2
+ import { DESTRUCTIVE, fail, ok, READ_ONLY, requireConnection, sanitize, WRITE } from "./shared.js";
3
+ const MUTE_FOREVER_UNTIL = 2147483647; // max 32-bit signed int
4
+ export function registerAccountTools(server, telegram) {
5
+ server.registerTool("telegram-mute-chat", {
6
+ description: "Mute or unmute notifications for a Telegram chat. Set muted=true to mute (optionally with duration in seconds), muted=false to unmute",
7
+ inputSchema: {
8
+ chatId: z.string().describe("Chat ID or username"),
9
+ muted: z.boolean().describe("true to mute, false to unmute"),
10
+ duration: z
11
+ .number()
12
+ .int()
13
+ .positive()
14
+ .optional()
15
+ .describe("Mute duration in seconds (only when muted=true, must be > 0). Omit to mute forever"),
16
+ },
17
+ annotations: WRITE,
18
+ }, async ({ chatId, muted, duration }) => {
19
+ const err = await requireConnection(telegram);
20
+ if (err)
21
+ return fail(new Error(err));
22
+ try {
23
+ let muteUntil;
24
+ if (!muted) {
25
+ muteUntil = 0;
26
+ }
27
+ else if (duration !== undefined && duration > 0) {
28
+ const now = Math.floor(Date.now() / 1000);
29
+ muteUntil = Math.min(now + duration, MUTE_FOREVER_UNTIL);
30
+ }
31
+ else {
32
+ muteUntil = MUTE_FOREVER_UNTIL;
33
+ }
34
+ await telegram.muteChat(chatId, muteUntil);
35
+ const status = !muted
36
+ ? "unmuted"
37
+ : duration !== undefined && duration > 0
38
+ ? `muted for ${duration}s`
39
+ : "muted forever";
40
+ return ok(`Chat ${chatId} ${status}`);
41
+ }
42
+ catch (e) {
43
+ return fail(e);
44
+ }
45
+ });
46
+ server.registerTool("telegram-get-chat-folders", {
47
+ description: "Get list of your Telegram chat folders (filters) with their names and chat counts",
48
+ inputSchema: {},
49
+ annotations: READ_ONLY,
50
+ }, async () => {
51
+ const err = await requireConnection(telegram);
52
+ if (err)
53
+ return fail(new Error(err));
54
+ try {
55
+ const folders = await telegram.getChatFolders();
56
+ if (folders.length === 0)
57
+ return ok("No chat folders");
58
+ const text = folders
59
+ .map((f) => `[${f.id}] ${f.emoticon ? `${f.emoticon} ` : ""}${f.title} (${f.includeCount} chats, ${f.pinnedCount} pinned)`)
60
+ .join("\n");
61
+ return ok(sanitize(text));
62
+ }
63
+ catch (e) {
64
+ return fail(e);
65
+ }
66
+ });
67
+ server.registerTool("telegram-set-auto-delete", {
68
+ description: "Set auto-delete timer for messages in a chat. Common values: 86400 (1 day), 604800 (1 week), 2592000 (1 month). Use 0 to disable",
69
+ inputSchema: {
70
+ chatId: z.string().describe("Chat ID or username"),
71
+ period: z
72
+ .number()
73
+ .int()
74
+ .nonnegative()
75
+ .describe("Auto-delete period in seconds. 0 = disable. Common: 86400 (1d), 604800 (1w), 2592000 (1mo)"),
76
+ },
77
+ annotations: WRITE,
78
+ }, async ({ chatId, period }) => {
79
+ const err = await requireConnection(telegram);
80
+ if (err)
81
+ return fail(new Error(err));
82
+ try {
83
+ await telegram.setAutoDelete(chatId, period);
84
+ const status = period === 0 ? "disabled" : `set to ${period}s`;
85
+ return ok(`Auto-delete for ${chatId} ${status}`);
86
+ }
87
+ catch (e) {
88
+ return fail(e);
89
+ }
90
+ });
91
+ server.registerTool("telegram-get-sessions", {
92
+ description: "Get list of all active Telegram sessions (logged-in devices) with device info, IP, and last active time",
93
+ inputSchema: {},
94
+ annotations: READ_ONLY,
95
+ }, async () => {
96
+ const err = await requireConnection(telegram);
97
+ if (err)
98
+ return fail(new Error(err));
99
+ try {
100
+ const sessions = await telegram.getActiveSessions();
101
+ if (sessions.length === 0)
102
+ return ok("No active sessions");
103
+ const text = sessions
104
+ .map((s) => `${s.current ? "→ " : " "}${s.device} (${s.platform}) — ${s.appName} ${s.appVersion}\n IP: ${s.ip} (${s.country}) | Last active: ${s.dateActive}${s.current ? " [CURRENT]" : ""}\n Hash: ${s.hash}`)
105
+ .join("\n\n");
106
+ return ok(sanitize(text));
107
+ }
108
+ catch (e) {
109
+ return fail(e);
110
+ }
111
+ });
112
+ server.registerTool("telegram-terminate-session", {
113
+ description: "Terminate a specific Telegram session by its hash, or explicitly terminate all other sessions by setting terminateAllOther=true",
114
+ inputSchema: {
115
+ sessionId: z
116
+ .string()
117
+ .optional()
118
+ .describe("Session hash to terminate (numeric string from get-sessions). Required when terminateAllOther is not set")
119
+ .refine((v) => v === undefined || /^\d+$/.test(v), { message: "sessionId must be a numeric string" }),
120
+ terminateAllOther: z
121
+ .boolean()
122
+ .optional()
123
+ .describe("Set to true to terminate all other sessions (excludes current). Cannot be combined with sessionId"),
124
+ },
125
+ annotations: DESTRUCTIVE,
126
+ }, async ({ sessionId, terminateAllOther }) => {
127
+ const err = await requireConnection(telegram);
128
+ if (err)
129
+ return fail(new Error(err));
130
+ try {
131
+ if (terminateAllOther) {
132
+ if (sessionId) {
133
+ return fail(new Error("Provide either sessionId or terminateAllOther=true, not both"));
134
+ }
135
+ await telegram.terminateAllOtherSessions();
136
+ return ok("All other sessions terminated");
137
+ }
138
+ if (!sessionId) {
139
+ return fail(new Error("Provide sessionId to terminate a specific session, or set terminateAllOther=true"));
140
+ }
141
+ await telegram.terminateSession(sessionId);
142
+ return ok(`Session ${sessionId} terminated`);
143
+ }
144
+ catch (e) {
145
+ return fail(e);
146
+ }
147
+ });
148
+ server.registerTool("telegram-set-privacy", {
149
+ description: "Configure privacy settings for your Telegram account. Controls who can see your phone number, last seen, profile photo, etc.",
150
+ inputSchema: {
151
+ setting: z
152
+ .enum(["phone_number", "last_seen", "profile_photo", "forwards", "calls", "groups", "bio"])
153
+ .describe("Privacy setting to change"),
154
+ rule: z.enum(["everyone", "contacts", "nobody"]).describe("Who can see/access this"),
155
+ allowUsers: z.array(z.string()).optional().describe("User IDs/usernames to always allow (exceptions)"),
156
+ disallowUsers: z.array(z.string()).optional().describe("User IDs/usernames to always disallow (exceptions)"),
157
+ },
158
+ annotations: WRITE,
159
+ }, async ({ setting, rule, allowUsers, disallowUsers }) => {
160
+ const err = await requireConnection(telegram);
161
+ if (err)
162
+ return fail(new Error(err));
163
+ try {
164
+ await telegram.setPrivacy(setting, rule, allowUsers, disallowUsers);
165
+ return ok(`Privacy: ${setting} set to "${rule}"`);
166
+ }
167
+ catch (e) {
168
+ return fail(e);
169
+ }
170
+ });
171
+ server.registerTool("telegram-update-profile", {
172
+ description: "Update your Telegram profile — first name, last name, bio, or username",
173
+ inputSchema: {
174
+ firstName: z.string().optional().describe("New first name"),
175
+ lastName: z.string().optional().describe("New last name"),
176
+ bio: z.string().optional().describe("New bio/about text (max 70 chars, 300 for Premium)"),
177
+ username: z.string().optional().describe("New username (without @)"),
178
+ },
179
+ annotations: WRITE,
180
+ }, async ({ firstName, lastName, bio, username }) => {
181
+ const err = await requireConnection(telegram);
182
+ if (err)
183
+ return fail(new Error(err));
184
+ try {
185
+ const updates = [];
186
+ if (firstName !== undefined || lastName !== undefined || bio !== undefined) {
187
+ await telegram.updateProfile({ firstName, lastName, bio });
188
+ if (firstName !== undefined)
189
+ updates.push(`firstName: ${firstName}`);
190
+ if (lastName !== undefined)
191
+ updates.push(`lastName: ${lastName}`);
192
+ if (bio !== undefined)
193
+ updates.push(`bio: ${bio}`);
194
+ }
195
+ if (username !== undefined) {
196
+ const normalizedUsername = username.replace(/^@/, "");
197
+ await telegram.updateUsername(normalizedUsername);
198
+ updates.push(`username: @${normalizedUsername}`);
199
+ }
200
+ return ok(updates.length ? `Profile updated: ${updates.join(", ")}` : "No changes specified");
201
+ }
202
+ catch (e) {
203
+ return fail(e);
204
+ }
205
+ });
206
+ server.registerTool("telegram-create-invite-link", {
207
+ description: "Create a new invite link for a group or channel",
208
+ inputSchema: {
209
+ chatId: z.string().describe("Chat ID or username"),
210
+ expireDate: z.number().optional().describe("Link expiration as Unix timestamp"),
211
+ memberLimit: z.number().optional().describe("Max number of users who can join via this link"),
212
+ requestApproval: z.boolean().optional().describe("Require admin approval to join"),
213
+ title: z.string().optional().describe("Label for the invite link (only visible to admins)"),
214
+ },
215
+ annotations: WRITE,
216
+ }, async ({ chatId, expireDate, memberLimit, requestApproval, title }) => {
217
+ const err = await requireConnection(telegram);
218
+ if (err)
219
+ return fail(new Error(err));
220
+ try {
221
+ const link = await telegram.exportInviteLink(chatId, {
222
+ expireDate,
223
+ usageLimit: memberLimit,
224
+ requestNeeded: requestApproval,
225
+ title,
226
+ });
227
+ return ok(`Invite link created: ${link}`);
228
+ }
229
+ catch (e) {
230
+ return fail(e);
231
+ }
232
+ });
233
+ server.registerTool("telegram-get-invite-links", {
234
+ description: "Get list of invite links for a group or channel. By default returns links created by the current account; pass adminId to query another admin's links",
235
+ inputSchema: {
236
+ chatId: z.string().describe("Chat ID or username"),
237
+ limit: z.number().default(20).describe("Max links to return"),
238
+ adminId: z
239
+ .string()
240
+ .optional()
241
+ .describe("Admin user ID or username to list links for (default: current account)"),
242
+ },
243
+ annotations: READ_ONLY,
244
+ }, async ({ chatId, limit, adminId }) => {
245
+ const err = await requireConnection(telegram);
246
+ if (err)
247
+ return fail(new Error(err));
248
+ try {
249
+ const links = await telegram.getInviteLinks(chatId, limit, adminId);
250
+ if (links.length === 0)
251
+ return ok("No invite links");
252
+ const text = links
253
+ .map((l) => `${l.link}${l.title ? ` (${l.title})` : ""} — ${l.usageCount} uses${l.expired ? " [EXPIRED]" : ""}${l.revoked ? " [REVOKED]" : ""}`)
254
+ .join("\n");
255
+ return ok(sanitize(text));
256
+ }
257
+ catch (e) {
258
+ return fail(e);
259
+ }
260
+ });
261
+ server.registerTool("telegram-revoke-invite-link", {
262
+ description: "Revoke an invite link for a group or channel",
263
+ inputSchema: {
264
+ chatId: z.string().describe("Chat ID or username"),
265
+ link: z.string().describe("The invite link to revoke"),
266
+ },
267
+ annotations: DESTRUCTIVE,
268
+ }, async ({ chatId, link }) => {
269
+ const err = await requireConnection(telegram);
270
+ if (err)
271
+ return fail(new Error(err));
272
+ try {
273
+ await telegram.revokeInviteLink(chatId, link);
274
+ return ok(`Invite link revoked: ${link}`);
275
+ }
276
+ catch (e) {
277
+ return fail(e);
278
+ }
279
+ });
280
+ }
@@ -116,6 +116,22 @@ export function registerContactTools(server, telegram) {
116
116
  return fail(e);
117
117
  }
118
118
  });
119
+ server.registerTool("telegram-unblock-user", {
120
+ description: "Unblock a previously blocked Telegram user",
121
+ inputSchema: { userId: z.string().describe("User ID or username to unblock") },
122
+ annotations: WRITE,
123
+ }, async ({ userId }) => {
124
+ const err = await requireConnection(telegram);
125
+ if (err)
126
+ return fail(new Error(err));
127
+ try {
128
+ await telegram.unblockUser(userId);
129
+ return ok(`User unblocked: ${userId}`);
130
+ }
131
+ catch (e) {
132
+ return fail(e);
133
+ }
134
+ });
119
135
  server.registerTool("telegram-report-spam", {
120
136
  description: "Report a chat as spam to Telegram",
121
137
  inputSchema: { chatId: z.string().describe("Chat ID or username to report") },
@@ -1,3 +1,4 @@
1
+ import { registerAccountTools } from "./account.js";
1
2
  import { registerAuthTools } from "./auth.js";
2
3
  import { registerChatTools } from "./chats.js";
3
4
  import { registerContactTools } from "./contacts.js";
@@ -13,4 +14,5 @@ export function registerTools(server, telegram) {
13
14
  registerContactTools(server, telegram);
14
15
  registerReactionTools(server, telegram);
15
16
  registerExtraTools(server, telegram);
17
+ registerAccountTools(server, telegram);
16
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@overpod/mcp-telegram",
3
- "version": "1.21.0",
3
+ "version": "1.23.0",
4
4
  "description": "MCP server for Telegram userbot — messages, media, reactions, polls & more. Built on GramJS/MTProto.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -52,14 +52,14 @@
52
52
  "url": "https://github.com/overpod/mcp-telegram/issues"
53
53
  },
54
54
  "dependencies": {
55
- "@modelcontextprotocol/sdk": "^1.28.0",
55
+ "@modelcontextprotocol/sdk": "^1.29.0",
56
56
  "dotenv": "^17.3.1",
57
57
  "qrcode": "^1.5.4",
58
58
  "telegram": "^2.26.22",
59
59
  "zod": "^4.3.6"
60
60
  },
61
61
  "devDependencies": {
62
- "@biomejs/biome": "^2.4.9",
62
+ "@biomejs/biome": "^2.4.10",
63
63
  "@types/node": "^25.5.0",
64
64
  "@types/qrcode": "^1.5.6",
65
65
  "tsx": "^4.21.0",