@overpod/mcp-telegram 1.28.0 → 1.28.1
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/README.md +1 -1
- package/dist/master.js +5 -0
- package/dist/telegram-client.d.ts +6 -2
- package/dist/telegram-client.js +32 -12
- package/dist/tools/auth.js +26 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -316,7 +316,7 @@ All tools are auto-discoverable via MCP — your AI client will see the full lis
|
|
|
316
316
|
|
|
317
317
|
| Category | Tools |
|
|
318
318
|
|----------|-------|
|
|
319
|
-
| **Auth** | `telegram-status`, `telegram-login` |
|
|
319
|
+
| **Auth** | `telegram-status`, `telegram-login`, `telegram-logout` |
|
|
320
320
|
| **Messaging** | `telegram-send-message`, `telegram-edit-message`, `telegram-delete-message`, `telegram-forward-message`, `telegram-send-scheduled`, `telegram-send-typing`, `telegram-translate-message`, `telegram-get-message-link` |
|
|
321
321
|
| **Scheduled** | `telegram-get-scheduled`, `telegram-delete-scheduled` |
|
|
322
322
|
| **Reading** | `telegram-list-chats`, `telegram-read-messages`, `telegram-search-messages`, `telegram-search-global`, `telegram-search-chats`, `telegram-get-unread`, `telegram-mark-as-read`, `telegram-get-replies`, `telegram-get-unread-mentions`, `telegram-get-unread-reactions`, `telegram-get-saved-dialogs` |
|
package/dist/master.js
CHANGED
|
@@ -81,6 +81,11 @@ async function handleToolRequest(socket, req, mcpServer) {
|
|
|
81
81
|
response.error = `Unknown tool: ${req.tool}`;
|
|
82
82
|
}
|
|
83
83
|
else {
|
|
84
|
+
// telegram-logout must cancel an in-progress QR login instead of queueing behind it
|
|
85
|
+
// for up to 5 minutes. Aborting releases the globalLock held by handleLoginStart.
|
|
86
|
+
if (req.tool === "telegram-logout" && activeLogin) {
|
|
87
|
+
activeLogin.abort.abort();
|
|
88
|
+
}
|
|
84
89
|
const unlock = await globalLock.acquire();
|
|
85
90
|
try {
|
|
86
91
|
response.result = await tool.handler(req.args ?? {}, {});
|
|
@@ -16,6 +16,7 @@ export declare class TelegramService {
|
|
|
16
16
|
private entityCache;
|
|
17
17
|
lastError: string;
|
|
18
18
|
get sessionDir(): string;
|
|
19
|
+
hasLocalSession(): boolean;
|
|
19
20
|
getClient(): TelegramClient | null;
|
|
20
21
|
constructor(apiId: number, apiHash: string, options?: {
|
|
21
22
|
sessionPath?: string;
|
|
@@ -33,8 +34,11 @@ export declare class TelegramService {
|
|
|
33
34
|
ensureConnected(): Promise<boolean>;
|
|
34
35
|
disconnect(): Promise<void>;
|
|
35
36
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
37
|
+
* Terminates the session on Telegram servers, destroys the client, and clears
|
|
38
|
+
* local session (in-memory + file). Returns true only when server-side revoke
|
|
39
|
+
* confirmed. False means server revoke could not be confirmed — local wipe
|
|
40
|
+
* was still attempted. Throws if local file removal failed so callers can
|
|
41
|
+
* surface the partial state instead of silently misreporting success.
|
|
38
42
|
*/
|
|
39
43
|
logOut(): Promise<boolean>;
|
|
40
44
|
isConnected(): boolean;
|
package/dist/telegram-client.js
CHANGED
|
@@ -60,6 +60,9 @@ export class TelegramService {
|
|
|
60
60
|
get sessionDir() {
|
|
61
61
|
return dirname(this.sessionPath);
|
|
62
62
|
}
|
|
63
|
+
hasLocalSession() {
|
|
64
|
+
return existsSync(this.sessionPath);
|
|
65
|
+
}
|
|
63
66
|
// ─── Session & Auth ────────────────────────────────────────────────────────
|
|
64
67
|
getClient() {
|
|
65
68
|
return this.client;
|
|
@@ -195,25 +198,42 @@ export class TelegramService {
|
|
|
195
198
|
}
|
|
196
199
|
}
|
|
197
200
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
201
|
+
* Terminates the session on Telegram servers, destroys the client, and clears
|
|
202
|
+
* local session (in-memory + file). Returns true only when server-side revoke
|
|
203
|
+
* confirmed. False means server revoke could not be confirmed — local wipe
|
|
204
|
+
* was still attempted. Throws if local file removal failed so callers can
|
|
205
|
+
* surface the partial state instead of silently misreporting success.
|
|
200
206
|
*/
|
|
201
207
|
async logOut() {
|
|
202
|
-
|
|
208
|
+
const wipeLocalOrThrow = async () => {
|
|
209
|
+
await this.clearSession();
|
|
210
|
+
if (existsSync(this.sessionPath)) {
|
|
211
|
+
throw new Error(`Local session file still present after clearSession: ${this.sessionPath}`);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
if (!this.client || !this.connected) {
|
|
215
|
+
if (existsSync(this.sessionPath))
|
|
216
|
+
await wipeLocalOrThrow();
|
|
203
217
|
return false;
|
|
218
|
+
}
|
|
219
|
+
const client = this.client;
|
|
220
|
+
let revoked = false;
|
|
204
221
|
try {
|
|
205
|
-
await
|
|
206
|
-
|
|
207
|
-
this.connected = false;
|
|
208
|
-
this.sessionString = "";
|
|
209
|
-
this.client = null;
|
|
210
|
-
return true;
|
|
222
|
+
await client.invoke(new Api.auth.LogOut());
|
|
223
|
+
revoked = true;
|
|
211
224
|
}
|
|
212
225
|
catch (error) {
|
|
213
|
-
console.error("[telegram]
|
|
214
|
-
|
|
215
|
-
|
|
226
|
+
console.error("[telegram] auth.LogOut failed:", error);
|
|
227
|
+
}
|
|
228
|
+
// destroy() failure must NOT mask a successful server revoke — log and continue.
|
|
229
|
+
try {
|
|
230
|
+
await client.destroy();
|
|
231
|
+
}
|
|
232
|
+
catch (err) {
|
|
233
|
+
console.error("[telegram] client.destroy failed during logOut:", err);
|
|
216
234
|
}
|
|
235
|
+
await wipeLocalOrThrow();
|
|
236
|
+
return revoked;
|
|
217
237
|
}
|
|
218
238
|
isConnected() {
|
|
219
239
|
return this.connected;
|
package/dist/tools/auth.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { writeFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { fail, ok, READ_ONLY, WRITE } from "./shared.js";
|
|
3
|
+
import { DESTRUCTIVE, fail, ok, READ_ONLY, WRITE } from "./shared.js";
|
|
4
4
|
export function registerAuthTools(server, telegram) {
|
|
5
5
|
server.registerTool("telegram-status", { description: "Check Telegram connection status", annotations: READ_ONLY }, async () => {
|
|
6
6
|
if (await telegram.ensureConnected()) {
|
|
@@ -65,4 +65,29 @@ export function registerAuthTools(server, telegram) {
|
|
|
65
65
|
],
|
|
66
66
|
};
|
|
67
67
|
});
|
|
68
|
+
server.registerTool("telegram-logout", {
|
|
69
|
+
description: "Log out from Telegram completely. Revokes the session on Telegram servers (removes it from Settings → Devices), deletes the local session file, and disconnects. After this you must run telegram-login to re-authenticate.",
|
|
70
|
+
annotations: DESTRUCTIVE,
|
|
71
|
+
}, async () => {
|
|
72
|
+
const wasConnected = await telegram.ensureConnected();
|
|
73
|
+
if (!wasConnected && !telegram.hasLocalSession()) {
|
|
74
|
+
return fail(new Error("Not logged in. Nothing to log out from."));
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const revoked = await telegram.logOut();
|
|
78
|
+
if (!wasConnected) {
|
|
79
|
+
return ok("Local session removed (was already disconnected). Server-side revoke was not performed.");
|
|
80
|
+
}
|
|
81
|
+
if (revoked) {
|
|
82
|
+
return ok("Logged out. Session revoked on Telegram servers and removed locally.");
|
|
83
|
+
}
|
|
84
|
+
return fail(new Error("Local session removed, but server-side revoke could not be confirmed. Open 'Settings → Devices' in Telegram and terminate the session manually if it is still listed."));
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
// Local file removal failed (read-only FS, permission denied, etc.).
|
|
88
|
+
// Never claim local cleanup succeeded when the file may still be on disk.
|
|
89
|
+
return fail(new Error(`Failed to remove local session file: ${err instanceof Error ? err.message : String(err)}. ` +
|
|
90
|
+
`Delete it manually (check telegram-status for the path).`));
|
|
91
|
+
}
|
|
92
|
+
});
|
|
68
93
|
}
|
package/package.json
CHANGED