@tuannvm/telegram-mcp-server 0.0.2 → 0.2.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/README.md +49 -0
- package/dist/constants.d.ts +18 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +18 -0
- package/dist/constants.js.map +1 -0
- package/dist/errors.d.ts +22 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +29 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/server.d.ts +15 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +15 -0
- package/dist/server.js.map +1 -1
- package/dist/telegram/index.d.ts +71 -0
- package/dist/telegram/index.d.ts.map +1 -0
- package/dist/telegram/index.js +153 -0
- package/dist/telegram/index.js.map +1 -0
- package/dist/tools/check-replies.d.ts +8 -0
- package/dist/tools/check-replies.d.ts.map +1 -0
- package/dist/tools/check-replies.js +67 -0
- package/dist/tools/check-replies.js.map +1 -0
- package/dist/tools/definitions.d.ts +3 -0
- package/dist/tools/definitions.d.ts.map +1 -1
- package/dist/tools/definitions.js +57 -0
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/handlers.d.ts +13 -0
- package/dist/tools/handlers.d.ts.map +1 -1
- package/dist/tools/handlers.js +24 -7
- package/dist/tools/handlers.js.map +1 -1
- package/dist/tools/send-and-wait.d.ts +8 -0
- package/dist/tools/send-and-wait.d.ts.map +1 -0
- package/dist/tools/send-and-wait.js +75 -0
- package/dist/tools/send-and-wait.js.map +1 -0
- package/dist/types.d.ts +43 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +17 -2
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/dist/__tests__/server.test.d.ts +0 -2
- package/dist/__tests__/server.test.d.ts.map +0 -1
- package/dist/__tests__/server.test.js +0 -12
- package/dist/__tests__/server.test.js.map +0 -1
package/README.md
CHANGED
|
@@ -55,6 +55,8 @@ Send telegram status to check configuration
|
|
|
55
55
|
|------|-------------|
|
|
56
56
|
| `send_telegram` | Send Telegram notifications with HTML formatting |
|
|
57
57
|
| `telegram_status` | Check if Telegram credentials are configured |
|
|
58
|
+
| `send_and_wait` | Send message and optionally poll for replies with progress notifications |
|
|
59
|
+
| `check_replies` | Check for pending replies from Telegram (non-blocking) |
|
|
58
60
|
|
|
59
61
|
## Examples
|
|
60
62
|
|
|
@@ -89,6 +91,16 @@ Duration: 45s"
|
|
|
89
91
|
Send telegram status to verify configuration
|
|
90
92
|
```
|
|
91
93
|
|
|
94
|
+
**Send and wait for reply:**
|
|
95
|
+
```
|
|
96
|
+
Use send_and_wait to send "Deploy to production?" with waitForReply=true and timeout=300
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Check for replies:**
|
|
100
|
+
```
|
|
101
|
+
Use check_replies to see if user responded to pending messages
|
|
102
|
+
```
|
|
103
|
+
|
|
92
104
|
## Getting Your Chat ID
|
|
93
105
|
|
|
94
106
|
```bash
|
|
@@ -136,6 +148,43 @@ This works reliably across:
|
|
|
136
148
|
- Containerized environments
|
|
137
149
|
- CI/CD pipelines
|
|
138
150
|
|
|
151
|
+
## Bidirectional Communication
|
|
152
|
+
|
|
153
|
+
The server supports polling-based bidirectional communication with Telegram using the getUpdates API:
|
|
154
|
+
|
|
155
|
+
1. **send_and_wait**: Send a message and poll for replies with progress notifications
|
|
156
|
+
2. **check_replies**: Check for pending replies from Telegram (non-blocking)
|
|
157
|
+
|
|
158
|
+
### Documentation
|
|
159
|
+
|
|
160
|
+
- **[Bidirectional Communication Guide](docs/bidirectional-communication.md)** - How to use send_and_wait and check_replies
|
|
161
|
+
- **[Technical Architecture](docs/architecture.md)** - Implementation details and system design
|
|
162
|
+
- **[Usage Examples](docs/usage-examples.md)** - Practical workflows and examples
|
|
163
|
+
|
|
164
|
+
### State Storage
|
|
165
|
+
|
|
166
|
+
The server uses file-based offset tracking for Telegram's getUpdates API:
|
|
167
|
+
|
|
168
|
+
**Location:** `~/.telegram-mcp-state/offset.json`
|
|
169
|
+
|
|
170
|
+
**Format:**
|
|
171
|
+
```json
|
|
172
|
+
{
|
|
173
|
+
"offset": 123456
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
This stores the last processed `update_id + 1` to ensure no duplicate message processing across server restarts.
|
|
178
|
+
|
|
179
|
+
### How Polling Works
|
|
180
|
+
|
|
181
|
+
1. Server calls `getUpdates` API with the stored offset
|
|
182
|
+
2. Telegram returns all new messages/updates since that offset
|
|
183
|
+
3. Server updates the offset after processing each batch
|
|
184
|
+
4. For `send_and_wait`, the server polls continuously until a reply is received or timeout occurs
|
|
185
|
+
|
|
186
|
+
No external webhook is required - the server polls directly from Telegram.
|
|
187
|
+
|
|
139
188
|
## License
|
|
140
189
|
|
|
141
190
|
ISC
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time-related constants for the Telegram MCP server
|
|
3
|
+
*/
|
|
4
|
+
/** Default timeout for API requests in milliseconds */
|
|
5
|
+
export declare const DEFAULT_REQUEST_TIMEOUT_MS = 10000;
|
|
6
|
+
/** Default timeout for Telegram long polling in seconds */
|
|
7
|
+
export declare const DEFAULT_POLL_TIMEOUT_SECONDS = 10;
|
|
8
|
+
/** Maximum poll timeout allowed by Telegram API in seconds */
|
|
9
|
+
export declare const MAX_POLL_TIMEOUT_SECONDS = 10;
|
|
10
|
+
/** Milliseconds per second for time conversions */
|
|
11
|
+
export declare const MS_PER_SECOND = 1000;
|
|
12
|
+
/** Default timeout for waiting for replies in seconds */
|
|
13
|
+
export declare const DEFAULT_REPLY_TIMEOUT_SECONDS = 300;
|
|
14
|
+
/** Default poll interval for checking replies in seconds */
|
|
15
|
+
export declare const DEFAULT_REPLY_POLL_INTERVAL_SECONDS = 5;
|
|
16
|
+
/** Maximum length for error message preview */
|
|
17
|
+
export declare const MAX_ERROR_PREVIEW_LENGTH = 200;
|
|
18
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,uDAAuD;AACvD,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD,2DAA2D;AAC3D,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAE/C,8DAA8D;AAC9D,eAAO,MAAM,wBAAwB,KAAK,CAAC;AAE3C,mDAAmD;AACnD,eAAO,MAAM,aAAa,OAAO,CAAC;AAElC,yDAAyD;AACzD,eAAO,MAAM,6BAA6B,MAAM,CAAC;AAEjD,4DAA4D;AAC5D,eAAO,MAAM,mCAAmC,IAAI,CAAC;AAErD,+CAA+C;AAC/C,eAAO,MAAM,wBAAwB,MAAM,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Time-related constants for the Telegram MCP server
|
|
3
|
+
*/
|
|
4
|
+
/** Default timeout for API requests in milliseconds */
|
|
5
|
+
export const DEFAULT_REQUEST_TIMEOUT_MS = 10_000;
|
|
6
|
+
/** Default timeout for Telegram long polling in seconds */
|
|
7
|
+
export const DEFAULT_POLL_TIMEOUT_SECONDS = 10;
|
|
8
|
+
/** Maximum poll timeout allowed by Telegram API in seconds */
|
|
9
|
+
export const MAX_POLL_TIMEOUT_SECONDS = 10;
|
|
10
|
+
/** Milliseconds per second for time conversions */
|
|
11
|
+
export const MS_PER_SECOND = 1000;
|
|
12
|
+
/** Default timeout for waiting for replies in seconds */
|
|
13
|
+
export const DEFAULT_REPLY_TIMEOUT_SECONDS = 300;
|
|
14
|
+
/** Default poll interval for checking replies in seconds */
|
|
15
|
+
export const DEFAULT_REPLY_POLL_INTERVAL_SECONDS = 5;
|
|
16
|
+
/** Maximum length for error message preview */
|
|
17
|
+
export const MAX_ERROR_PREVIEW_LENGTH = 200;
|
|
18
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,uDAAuD;AACvD,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAEjD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAE/C,8DAA8D;AAC9D,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAE3C,mDAAmD;AACnD,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAElC,yDAAyD;AACzD,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAAG,CAAC;AAEjD,4DAA4D;AAC5D,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,CAAC;AAErD,+CAA+C;AAC/C,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,11 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when tool execution fails
|
|
3
|
+
*/
|
|
1
4
|
export declare class ToolExecutionError extends Error {
|
|
2
5
|
readonly toolName: string;
|
|
3
6
|
readonly cause?: unknown | undefined;
|
|
4
7
|
constructor(toolName: string, message: string, cause?: unknown | undefined);
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Error thrown when tool input validation fails
|
|
11
|
+
*/
|
|
6
12
|
export declare class ValidationError extends Error {
|
|
7
13
|
readonly toolName: string;
|
|
8
14
|
constructor(toolName: string, message: string);
|
|
9
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown when server configuration is invalid or missing
|
|
18
|
+
*/
|
|
19
|
+
export declare class ConfigurationError extends Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Error thrown when network request fails
|
|
24
|
+
*/
|
|
25
|
+
export declare class NetworkError extends Error {
|
|
26
|
+
readonly cause?: unknown | undefined;
|
|
27
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Format error for display in tool responses
|
|
31
|
+
*/
|
|
10
32
|
export declare function handleError(error: unknown, context: string): string;
|
|
11
33
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,kBAAmB,SAAQ,KAAK;aAEzB,QAAQ,EAAE,MAAM;aAEhB,KAAK,CAAC,EAAE,OAAO;gBAFf,QAAQ,EAAE,MAAM,EAChC,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,OAAO,YAAA;CAKlC;AAED,qBAAa,eAAgB,SAAQ,KAAK;aAEtB,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAChC,OAAO,EAAE,MAAM;CAKlB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKnE"}
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;aAEzB,QAAQ,EAAE,MAAM;aAEhB,KAAK,CAAC,EAAE,OAAO;gBAFf,QAAQ,EAAE,MAAM,EAChC,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,OAAO,YAAA;CAKlC;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAEtB,QAAQ,EAAE,MAAM;gBAAhB,QAAQ,EAAE,MAAM,EAChC,OAAO,EAAE,MAAM;CAKlB;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;aACQ,KAAK,CAAC,EAAE,OAAO;gBAAhD,OAAO,EAAE,MAAM,EAAkB,KAAK,CAAC,EAAE,OAAO,YAAA;CAI7D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAKnE"}
|
package/dist/errors.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when tool execution fails
|
|
3
|
+
*/
|
|
1
4
|
export class ToolExecutionError extends Error {
|
|
2
5
|
toolName;
|
|
3
6
|
cause;
|
|
@@ -8,6 +11,9 @@ export class ToolExecutionError extends Error {
|
|
|
8
11
|
this.name = 'ToolExecutionError';
|
|
9
12
|
}
|
|
10
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when tool input validation fails
|
|
16
|
+
*/
|
|
11
17
|
export class ValidationError extends Error {
|
|
12
18
|
toolName;
|
|
13
19
|
constructor(toolName, message) {
|
|
@@ -16,6 +22,29 @@ export class ValidationError extends Error {
|
|
|
16
22
|
this.name = 'ValidationError';
|
|
17
23
|
}
|
|
18
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when server configuration is invalid or missing
|
|
27
|
+
*/
|
|
28
|
+
export class ConfigurationError extends Error {
|
|
29
|
+
constructor(message) {
|
|
30
|
+
super(`Configuration error: ${message}`);
|
|
31
|
+
this.name = 'ConfigurationError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Error thrown when network request fails
|
|
36
|
+
*/
|
|
37
|
+
export class NetworkError extends Error {
|
|
38
|
+
cause;
|
|
39
|
+
constructor(message, cause) {
|
|
40
|
+
super(`Network error: ${message}`);
|
|
41
|
+
this.cause = cause;
|
|
42
|
+
this.name = 'NetworkError';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Format error for display in tool responses
|
|
47
|
+
*/
|
|
19
48
|
export function handleError(error, context) {
|
|
20
49
|
if (error instanceof Error) {
|
|
21
50
|
return `Error in ${context}: ${error.message}`;
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAEzB;IAEA;IAHlB,YACkB,QAAgB,EAChC,OAAe,EACC,KAAe;QAE/B,KAAK,CAAC,2BAA2B,QAAQ,MAAM,OAAO,EAAE,CAAC,CAAC;QAJ1C,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAEtB;IADlB,YACkB,QAAgB,EAChC,OAAe;QAEf,KAAK,CAAC,+BAA+B,QAAQ,MAAM,OAAO,EAAE,CAAC,CAAC;QAH9C,aAAQ,GAAR,QAAQ,CAAQ;QAIhC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,OAAe;IACzD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,YAAY,OAAO,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,YAAY,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACjD,CAAC"}
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAEzB;IAEA;IAHlB,YACkB,QAAgB,EAChC,OAAe,EACC,KAAe;QAE/B,KAAK,CAAC,2BAA2B,QAAQ,MAAM,OAAO,EAAE,CAAC,CAAC;QAJ1C,aAAQ,GAAR,QAAQ,CAAQ;QAEhB,UAAK,GAAL,KAAK,CAAU;QAG/B,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAEtB;IADlB,YACkB,QAAgB,EAChC,OAAe;QAEf,KAAK,CAAC,+BAA+B,QAAQ,MAAM,OAAO,EAAE,CAAC,CAAC;QAH9C,aAAQ,GAAR,QAAQ,CAAQ;QAIhC,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACQ;IAA7C,YAAY,OAAe,EAAkB,KAAe;QAC1D,KAAK,CAAC,kBAAkB,OAAO,EAAE,CAAC,CAAC;QADQ,UAAK,GAAL,KAAK,CAAU;QAE1D,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,OAAe;IACzD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,YAAY,OAAO,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;IACjD,CAAC;IACD,OAAO,YAAY,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AACjD,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,qBAAqB;IAC3B,OAAO,EAAE,OAAO;CACR,CAAC;AAEX,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,aAAa,CAAC,CAAC;QACpD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,aAAa,GAAG;IACpB,IAAI,EAAE,qBAAqB;IAC3B,OAAO,EAAE,OAAO;CACR,CAAC;AAEX;;GAEG;AACH,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,aAAa,CAAC,CAAC;QACpD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,yBAAyB,CAAC,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/server.d.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import { type ServerConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Telegram MCP Server - Implements Model Context Protocol for Telegram notifications
|
|
4
|
+
*/
|
|
2
5
|
export declare class TelegramMcpServer {
|
|
3
6
|
private readonly server;
|
|
4
7
|
private readonly config;
|
|
8
|
+
/**
|
|
9
|
+
* @param config - Server configuration with name and version
|
|
10
|
+
*/
|
|
5
11
|
constructor(config: ServerConfig);
|
|
12
|
+
/**
|
|
13
|
+
* Set up MCP request handlers for listing and calling tools
|
|
14
|
+
*/
|
|
6
15
|
private setupHandlers;
|
|
16
|
+
/**
|
|
17
|
+
* Type guard to check if a string is a valid tool name
|
|
18
|
+
*/
|
|
7
19
|
private isValidToolName;
|
|
20
|
+
/**
|
|
21
|
+
* Start the MCP server with stdio transport
|
|
22
|
+
*/
|
|
8
23
|
start(): Promise<void>;
|
|
9
24
|
}
|
|
10
25
|
//# sourceMappingURL=server.d.ts.map
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,YAAY,EAKlB,MAAM,YAAY,CAAC;AAKpB,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,KAAK,YAAY,EAKlB,MAAM,YAAY,CAAC;AAKpB;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IAEtC;;OAEG;gBACS,MAAM,EAAE,YAAY;IAiBhC;;OAEG;IACH,OAAO,CAAC,aAAa;IA4DrB;;OAEG;IACH,OAAO,CAAC,eAAe;IAIvB;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
|
package/dist/server.js
CHANGED
|
@@ -6,9 +6,15 @@ import { TOOLS, } from './types.js';
|
|
|
6
6
|
import { handleError } from './errors.js';
|
|
7
7
|
import { toolDefinitions } from './tools/definitions.js';
|
|
8
8
|
import { toolHandlers } from './tools/handlers.js';
|
|
9
|
+
/**
|
|
10
|
+
* Telegram MCP Server - Implements Model Context Protocol for Telegram notifications
|
|
11
|
+
*/
|
|
9
12
|
export class TelegramMcpServer {
|
|
10
13
|
server;
|
|
11
14
|
config;
|
|
15
|
+
/**
|
|
16
|
+
* @param config - Server configuration with name and version
|
|
17
|
+
*/
|
|
12
18
|
constructor(config) {
|
|
13
19
|
this.config = config;
|
|
14
20
|
this.server = new Server({
|
|
@@ -21,6 +27,9 @@ export class TelegramMcpServer {
|
|
|
21
27
|
});
|
|
22
28
|
this.setupHandlers();
|
|
23
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Set up MCP request handlers for listing and calling tools
|
|
32
|
+
*/
|
|
24
33
|
setupHandlers() {
|
|
25
34
|
// List tools handler
|
|
26
35
|
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
@@ -78,9 +87,15 @@ export class TelegramMcpServer {
|
|
|
78
87
|
}
|
|
79
88
|
});
|
|
80
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Type guard to check if a string is a valid tool name
|
|
92
|
+
*/
|
|
81
93
|
isValidToolName(name) {
|
|
82
94
|
return Object.values(TOOLS).includes(name);
|
|
83
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Start the MCP server with stdio transport
|
|
98
|
+
*/
|
|
84
99
|
async start() {
|
|
85
100
|
const transport = new StdioServerTransport();
|
|
86
101
|
await this.server.connect(transport);
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB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;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Telegram message data structure from Bot API
|
|
3
|
+
*/
|
|
4
|
+
export interface TelegramMessage {
|
|
5
|
+
message_id: number;
|
|
6
|
+
from: {
|
|
7
|
+
id: number;
|
|
8
|
+
first_name?: string;
|
|
9
|
+
username?: string;
|
|
10
|
+
};
|
|
11
|
+
chat: {
|
|
12
|
+
id: number;
|
|
13
|
+
type: string;
|
|
14
|
+
};
|
|
15
|
+
date: number;
|
|
16
|
+
text: string;
|
|
17
|
+
reply_to_message?: {
|
|
18
|
+
message_id: number;
|
|
19
|
+
from: {
|
|
20
|
+
id: number;
|
|
21
|
+
first_name?: string;
|
|
22
|
+
};
|
|
23
|
+
text: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Telegram update data structure from getUpdates API
|
|
28
|
+
*/
|
|
29
|
+
export interface TelegramUpdate {
|
|
30
|
+
update_id: number;
|
|
31
|
+
message?: TelegramMessage;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Result of sending a message to Telegram
|
|
35
|
+
*/
|
|
36
|
+
export interface SendMessageResult {
|
|
37
|
+
success: boolean;
|
|
38
|
+
messageId?: number;
|
|
39
|
+
error?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Send a message to Telegram via Bot API
|
|
43
|
+
*/
|
|
44
|
+
export declare function sendMessage(message: string): Promise<SendMessageResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Poll for updates from Telegram using long polling
|
|
47
|
+
*/
|
|
48
|
+
export declare function getUpdates(options?: {
|
|
49
|
+
timeout?: number;
|
|
50
|
+
offset?: number;
|
|
51
|
+
}): Promise<TelegramUpdate[]>;
|
|
52
|
+
/**
|
|
53
|
+
* Poll for a reply to a specific message with timeout
|
|
54
|
+
*/
|
|
55
|
+
export declare function waitForReply(sentMessageId: number, timeoutMs: number, pollIntervalMs: number, onProgress?: (message: string, progress: number, total: number) => Promise<void>): Promise<{
|
|
56
|
+
found: boolean;
|
|
57
|
+
reply?: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Get all pending replies from the latest updates
|
|
61
|
+
*/
|
|
62
|
+
export declare function getAllReplies(): Promise<Array<{
|
|
63
|
+
messageId: number;
|
|
64
|
+
replyText: string;
|
|
65
|
+
timestamp: number;
|
|
66
|
+
}>>;
|
|
67
|
+
/**
|
|
68
|
+
* Sleep for specified milliseconds
|
|
69
|
+
*/
|
|
70
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
71
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/telegram/index.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7D,IAAI,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,EAAE;QACjB,UAAU,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,UAAU,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC;QAC1C,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,eAAe,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAuCD;;GAEG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAsD7E;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAO,GAClD,OAAO,CAAC,cAAc,EAAE,CAAC,CAgC3B;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,UAAU,CAAC,EAAE,CACX,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,KACV,OAAO,CAAC,IAAI,CAAC,GACjB,OAAO,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAkC7C;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAC5C,KAAK,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CACnE,CAmBA;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import { homedir } from 'os';
|
|
4
|
+
import { DEFAULT_POLL_TIMEOUT_SECONDS, DEFAULT_REQUEST_TIMEOUT_MS, MAX_POLL_TIMEOUT_SECONDS, MS_PER_SECOND, } from '../constants.js';
|
|
5
|
+
import { ConfigurationError } from '../errors.js';
|
|
6
|
+
const STATE_DIR = join(homedir(), '.telegram-mcp-state');
|
|
7
|
+
const OFFSET_FILE = join(STATE_DIR, 'offset.json');
|
|
8
|
+
/**
|
|
9
|
+
* Get bot token and chat ID from environment variables
|
|
10
|
+
*/
|
|
11
|
+
function getBotConfig() {
|
|
12
|
+
const botToken = process.env.TELEGRAM_BOT_TOKEN;
|
|
13
|
+
const chatId = process.env.TELEGRAM_CHAT_ID;
|
|
14
|
+
if (!botToken || !chatId) {
|
|
15
|
+
throw new ConfigurationError('Missing TELEGRAM_BOT_TOKEN or TELEGRAM_CHAT_ID environment variable');
|
|
16
|
+
}
|
|
17
|
+
return { botToken, chatId };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Read the last processed update offset from state file
|
|
21
|
+
*/
|
|
22
|
+
async function getOffset() {
|
|
23
|
+
try {
|
|
24
|
+
const content = await fs.readFile(OFFSET_FILE, 'utf-8');
|
|
25
|
+
const data = JSON.parse(content);
|
|
26
|
+
return data.offset || 0;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Save the last processed update offset to state file
|
|
34
|
+
*/
|
|
35
|
+
async function setOffset(offset) {
|
|
36
|
+
await fs.mkdir(STATE_DIR, { recursive: true });
|
|
37
|
+
await fs.writeFile(OFFSET_FILE, JSON.stringify({ offset }, null, 2));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Send a message to Telegram via Bot API
|
|
41
|
+
*/
|
|
42
|
+
export async function sendMessage(message) {
|
|
43
|
+
const { botToken, chatId } = getBotConfig();
|
|
44
|
+
const controller = new AbortController();
|
|
45
|
+
const timeoutId = setTimeout(() => controller.abort(), DEFAULT_REQUEST_TIMEOUT_MS);
|
|
46
|
+
try {
|
|
47
|
+
const response = await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
headers: { 'Content-Type': 'application/json' },
|
|
50
|
+
body: JSON.stringify({
|
|
51
|
+
chat_id: chatId,
|
|
52
|
+
text: message,
|
|
53
|
+
parse_mode: 'HTML',
|
|
54
|
+
}),
|
|
55
|
+
signal: controller.signal,
|
|
56
|
+
});
|
|
57
|
+
clearTimeout(timeoutId);
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
return { success: false, error: `HTTP ${response.status}` };
|
|
60
|
+
}
|
|
61
|
+
const data = (await response.json());
|
|
62
|
+
if (data.ok) {
|
|
63
|
+
return { success: true, messageId: data.result?.message_id };
|
|
64
|
+
}
|
|
65
|
+
return { success: false, error: data.description };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
clearTimeout(timeoutId);
|
|
69
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
70
|
+
const timeoutSeconds = DEFAULT_REQUEST_TIMEOUT_MS / MS_PER_SECOND;
|
|
71
|
+
return { success: false, error: `Request timeout (${timeoutSeconds}s)` };
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
success: false,
|
|
75
|
+
error: error instanceof Error ? error.message : 'Network error',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Poll for updates from Telegram using long polling
|
|
81
|
+
*/
|
|
82
|
+
export async function getUpdates(options = {}) {
|
|
83
|
+
const { botToken } = getBotConfig();
|
|
84
|
+
const { timeout = DEFAULT_POLL_TIMEOUT_SECONDS, offset } = options;
|
|
85
|
+
const actualOffset = offset ?? (await getOffset());
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetch(`https://api.telegram.org/bot${botToken}/getUpdates?offset=${actualOffset}&timeout=${timeout}`);
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const data = (await response.json());
|
|
92
|
+
if (data.ok && data.result) {
|
|
93
|
+
const maxOffset = Math.max(...data.result.map((u) => u.update_id), 0);
|
|
94
|
+
if (maxOffset > 0) {
|
|
95
|
+
await setOffset(maxOffset + 1);
|
|
96
|
+
}
|
|
97
|
+
return data.result;
|
|
98
|
+
}
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Poll for a reply to a specific message with timeout
|
|
107
|
+
*/
|
|
108
|
+
export async function waitForReply(sentMessageId, timeoutMs, pollIntervalMs, onProgress) {
|
|
109
|
+
const startTime = Date.now();
|
|
110
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
111
|
+
const elapsed = Math.floor((Date.now() - startTime) / 1000);
|
|
112
|
+
const total = Math.floor(timeoutMs / 1000);
|
|
113
|
+
if (onProgress) {
|
|
114
|
+
await onProgress(`Waiting for reply... (${elapsed}s / ${total}s)`, elapsed, total);
|
|
115
|
+
}
|
|
116
|
+
const updates = await getUpdates({
|
|
117
|
+
timeout: Math.min(pollIntervalMs / MS_PER_SECOND, MAX_POLL_TIMEOUT_SECONDS),
|
|
118
|
+
});
|
|
119
|
+
for (const update of updates) {
|
|
120
|
+
if (update.message?.reply_to_message?.message_id === sentMessageId) {
|
|
121
|
+
return { found: true, reply: update.message.text };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (Date.now() - startTime < timeoutMs) {
|
|
125
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return { found: false };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get all pending replies from the latest updates
|
|
132
|
+
*/
|
|
133
|
+
export async function getAllReplies() {
|
|
134
|
+
const updates = await getUpdates();
|
|
135
|
+
const replies = [];
|
|
136
|
+
for (const update of updates) {
|
|
137
|
+
if (update.message?.reply_to_message) {
|
|
138
|
+
replies.push({
|
|
139
|
+
messageId: update.message.reply_to_message.message_id,
|
|
140
|
+
replyText: update.message.text,
|
|
141
|
+
timestamp: update.message.date * 1000,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return replies;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Sleep for specified milliseconds
|
|
149
|
+
*/
|
|
150
|
+
export async function sleep(ms) {
|
|
151
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/telegram/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAE7B,OAAO,EACL,4BAA4B,EAC5B,0BAA0B,EAC1B,wBAAwB,EACxB,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,qBAAqB,CAAC,CAAC;AACzD,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;AAmCnD;;GAEG;AACH,SAAS,YAAY;IACnB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAChD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;IAE5C,IAAI,CAAC,QAAQ,IAAI,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,IAAI,kBAAkB,CAC1B,qEAAqE,CACtE,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,SAAS;IACtB,IAAI,CAAC;QACH,MAAM,OAAO,GAA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,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,EAAU;IACpC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ToolResult, type ToolHandlerContext } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Handler for check_replies tool - check for pending replies from Telegram
|
|
4
|
+
*/
|
|
5
|
+
export declare class CheckRepliesToolHandler {
|
|
6
|
+
execute(args: unknown, _context: ToolHandlerContext): Promise<ToolResult>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=check-replies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-replies.d.ts","sourceRoot":"","sources":["../../src/tools/check-replies.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAC;AAKrB;;GAEG;AACH,qBAAa,uBAAuB;IAC5B,OAAO,CACX,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,CAAC;CAsEvB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { TOOLS, CheckRepliesToolSchema, } from '../types.js';
|
|
2
|
+
import { ToolExecutionError, ValidationError } from '../errors.js';
|
|
3
|
+
import { ZodError } from 'zod';
|
|
4
|
+
import { getAllReplies, getUpdates } from '../telegram/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Handler for check_replies tool - check for pending replies from Telegram
|
|
7
|
+
*/
|
|
8
|
+
export class CheckRepliesToolHandler {
|
|
9
|
+
async execute(args, _context) {
|
|
10
|
+
try {
|
|
11
|
+
const { messageId } = CheckRepliesToolSchema.parse(args ?? {});
|
|
12
|
+
if (messageId !== undefined) {
|
|
13
|
+
const updates = await getUpdates();
|
|
14
|
+
for (const update of updates) {
|
|
15
|
+
const msg = update.message;
|
|
16
|
+
if (msg?.reply_to_message?.message_id === messageId) {
|
|
17
|
+
return {
|
|
18
|
+
content: [
|
|
19
|
+
{
|
|
20
|
+
type: 'text',
|
|
21
|
+
text: `Reply for message ${messageId}:\n\n${msg.text}\n\nTimestamp: ${new Date(msg.date * 1000).toISOString()}`,
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text',
|
|
31
|
+
text: `No reply found for message ID ${messageId}`,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const replies = await getAllReplies();
|
|
37
|
+
if (replies.length === 0) {
|
|
38
|
+
return {
|
|
39
|
+
content: [
|
|
40
|
+
{
|
|
41
|
+
type: 'text',
|
|
42
|
+
text: 'No pending replies found',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const formatted = replies
|
|
48
|
+
.map((r) => `Message ${r.messageId}:\n${r.replyText}\nTimestamp: ${new Date(r.timestamp).toISOString()}\n`)
|
|
49
|
+
.join('\n');
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `Found ${replies.length} pending reply(ies):\n\n${formatted}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof ZodError) {
|
|
61
|
+
throw new ValidationError(TOOLS.CHECK_REPLIES, error.message);
|
|
62
|
+
}
|
|
63
|
+
throw new ToolExecutionError(TOOLS.CHECK_REPLIES, 'Failed to check replies', error instanceof Error ? error : new Error(String(error)));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=check-replies.js.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AAa,EAAE,CAAC;YAEtC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACzB,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,0BAA0B;yBACjC;qBACF;iBACF,CAAC;YACJ,CAAC;YAED,MAAM,SAAS,GAAG,OAAO;iBACtB,GAAG,CACF,CAAC,CAAC,EAAE,EAAE,CACJ,WAAW,CAAC,CAAC,SAAS,MAAM,CAAC,CAAC,SAAS,gBAAgB,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,IAAI,CACjG;iBACA,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,SAAS,OAAO,CAAC,MAAM,2BAA2B,SAAS,EAAE;qBACpE;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;gBAC9B,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YAChE,CAAC;YACD,MAAM,IAAI,kBAAkB,CAC1B,KAAK,CAAC,aAAa,EACnB,yBAAyB,EACzB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/tools/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzD,eAAO,MAAM,eAAe,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/tools/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAEzD;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,cAAc,EAqG3C,CAAC"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { TOOLS } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tool definitions for MCP server
|
|
4
|
+
*/
|
|
2
5
|
export const toolDefinitions = [
|
|
3
6
|
{
|
|
4
7
|
name: TOOLS.SEND_TELEGRAM,
|
|
@@ -41,5 +44,59 @@ export const toolDefinitions = [
|
|
|
41
44
|
openWorldHint: false,
|
|
42
45
|
},
|
|
43
46
|
},
|
|
47
|
+
{
|
|
48
|
+
name: TOOLS.SEND_AND_WAIT,
|
|
49
|
+
description: 'Send a Telegram message and optionally wait for a reply with polling. Use for interactive workflows requiring user input.',
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
message: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'The message to send to Telegram',
|
|
56
|
+
},
|
|
57
|
+
waitForReply: {
|
|
58
|
+
type: 'boolean',
|
|
59
|
+
description: 'Whether to poll for replies (default: false)',
|
|
60
|
+
},
|
|
61
|
+
timeout: {
|
|
62
|
+
type: 'number',
|
|
63
|
+
description: 'Maximum seconds to wait for reply (default: 300)',
|
|
64
|
+
},
|
|
65
|
+
pollInterval: {
|
|
66
|
+
type: 'number',
|
|
67
|
+
description: 'Seconds between polls (default: 5)',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ['message'],
|
|
71
|
+
},
|
|
72
|
+
annotations: {
|
|
73
|
+
title: 'Send and Wait',
|
|
74
|
+
readOnlyHint: true,
|
|
75
|
+
destructiveHint: false,
|
|
76
|
+
idempotentHint: false,
|
|
77
|
+
openWorldHint: true,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: TOOLS.CHECK_REPLIES,
|
|
82
|
+
description: 'Check for pending replies from Telegram (non-blocking). Returns all pending replies or a specific message reply.',
|
|
83
|
+
inputSchema: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
messageId: {
|
|
87
|
+
type: 'number',
|
|
88
|
+
description: 'Specific message ID to check, or return all pending',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
required: [],
|
|
92
|
+
},
|
|
93
|
+
annotations: {
|
|
94
|
+
title: 'Check Replies',
|
|
95
|
+
readOnlyHint: true,
|
|
96
|
+
destructiveHint: false,
|
|
97
|
+
idempotentHint: true,
|
|
98
|
+
openWorldHint: false,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
44
101
|
];
|
|
45
102
|
//# sourceMappingURL=definitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/tools/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAuB,MAAM,aAAa,CAAC;AAEzD,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C;QACE,IAAI,EAAE,KAAK,CAAC,aAAa;QACzB,WAAW,EACT,mGAAmG;QACrG,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,4EAA4E;iBAC/E;gBACD,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,sGAAsG;iBACzG;aACF;YACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;SACrB;QACD,WAAW,EAAE;YACX,KAAK,EAAE,eAAe;YACtB,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,IAAI;SACpB;KACF;IACD;QACE,IAAI,EAAE,KAAK,CAAC,eAAe;QAC3B,WAAW,EAAE,8CAA8C;QAC3D,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAE;SACb;QACD,WAAW,EAAE;YACX,KAAK,EAAE,iBAAiB;YACxB,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF;CACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/tools/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAuB,MAAM,aAAa,CAAC;AAEzD;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAqB;IAC/C;QACE,IAAI,EAAE,KAAK,CAAC,aAAa;QACzB,WAAW,EACT,mGAAmG;QACrG,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,4EAA4E;iBAC/E;gBACD,IAAI,EAAE;oBACJ,IAAI,EAAE,QAAQ;oBACd,WAAW,EACT,sGAAsG;iBACzG;aACF;YACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;SACrB;QACD,WAAW,EAAE;YACX,KAAK,EAAE,eAAe;YACtB,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,IAAI;SACpB;KACF;IACD;QACE,IAAI,EAAE,KAAK,CAAC,eAAe;QAC3B,WAAW,EAAE,8CAA8C;QAC3D,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,QAAQ,EAAE,EAAE;SACb;QACD,WAAW,EAAE;YACX,KAAK,EAAE,iBAAiB;YACxB,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF;IACD;QACE,IAAI,EAAE,KAAK,CAAC,aAAa;QACzB,WAAW,EACT,2HAA2H;QAC7H,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,iCAAiC;iBAC/C;gBACD,YAAY,EAAE;oBACZ,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,8CAA8C;iBAC5D;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,kDAAkD;iBAChE;gBACD,YAAY,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,oCAAoC;iBAClD;aACF;YACD,QAAQ,EAAE,CAAC,SAAS,CAAC;SACtB;QACD,WAAW,EAAE;YACX,KAAK,EAAE,eAAe;YACtB,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,KAAK;YACrB,aAAa,EAAE,IAAI;SACpB;KACF;IACD;QACE,IAAI,EAAE,KAAK,CAAC,aAAa;QACzB,WAAW,EACT,kHAAkH;QACpH,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAQ;oBACd,WAAW,EAAE,qDAAqD;iBACnE;aACF;YACD,QAAQ,EAAE,EAAE;SACb;QACD,WAAW,EAAE;YACX,KAAK,EAAE,eAAe;YACtB,YAAY,EAAE,IAAI;YAClB,eAAe,EAAE,KAAK;YACtB,cAAc,EAAE,IAAI;YACpB,aAAa,EAAE,KAAK;SACrB;KACF;CACF,CAAC"}
|
package/dist/tools/handlers.d.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import { type ToolResult, type ToolHandlerContext } from '../types.js';
|
|
2
|
+
import { SendAndWaitToolHandler } from './send-and-wait.js';
|
|
3
|
+
import { CheckRepliesToolHandler } from './check-replies.js';
|
|
4
|
+
/**
|
|
5
|
+
* Handler for send_telegram tool
|
|
6
|
+
*/
|
|
2
7
|
export declare class SendTelegramToolHandler {
|
|
3
8
|
execute(args: unknown, _context?: ToolHandlerContext): Promise<ToolResult>;
|
|
4
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Handler for telegram_status tool
|
|
12
|
+
*/
|
|
5
13
|
export declare class TelegramStatusToolHandler {
|
|
6
14
|
execute(args: unknown, _context?: ToolHandlerContext): Promise<ToolResult>;
|
|
7
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Registry of all tool handlers
|
|
18
|
+
*/
|
|
8
19
|
export declare const toolHandlers: {
|
|
9
20
|
readonly send_telegram: SendTelegramToolHandler;
|
|
10
21
|
readonly telegram_status: TelegramStatusToolHandler;
|
|
22
|
+
readonly send_and_wait: SendAndWaitToolHandler;
|
|
23
|
+
readonly check_replies: CheckRepliesToolHandler;
|
|
11
24
|
};
|
|
12
25
|
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/tools/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,kBAAkB,EAKxB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/tools/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,kBAAkB,EAKxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAmI7D;;GAEG;AACH,qBAAa,uBAAuB;IAC5B,OAAO,CACX,IAAI,EAAE,OAAO,EACb,QAAQ,GAAE,kBAAmC,GAC5C,OAAO,CAAC,UAAU,CAAC;CA6BvB;AAED;;GAEG;AACH,qBAAa,yBAAyB;IAC9B,OAAO,CACX,IAAI,EAAE,OAAO,EACb,QAAQ,GAAE,kBAAmC,GAC5C,OAAO,CAAC,UAAU,CAAC;CA4BvB;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;;;;;CAKf,CAAC"}
|
package/dist/tools/handlers.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { TOOLS, SendTelegramToolSchema, TelegramStatusToolSchema, } from '../types.js';
|
|
2
2
|
import { ToolExecutionError, ValidationError } from '../errors.js';
|
|
3
3
|
import { ZodError } from 'zod';
|
|
4
|
+
import { SendAndWaitToolHandler } from './send-and-wait.js';
|
|
5
|
+
import { CheckRepliesToolHandler } from './check-replies.js';
|
|
6
|
+
import { DEFAULT_REQUEST_TIMEOUT_MS, MAX_ERROR_PREVIEW_LENGTH, } from '../constants.js';
|
|
4
7
|
// Default no-op context for handlers that don't need progress
|
|
5
8
|
const defaultContext = {
|
|
6
9
|
sendProgress: async () => { },
|
|
@@ -17,7 +20,7 @@ function escapeHtml(text) {
|
|
|
17
20
|
return text.replace(/[&<>]/g, (char) => htmlEscapeMap[char]);
|
|
18
21
|
}
|
|
19
22
|
/**
|
|
20
|
-
* Get Telegram configuration
|
|
23
|
+
* Get Telegram configuration from environment variables
|
|
21
24
|
*/
|
|
22
25
|
function getTelegramConfig() {
|
|
23
26
|
return {
|
|
@@ -25,6 +28,9 @@ function getTelegramConfig() {
|
|
|
25
28
|
chatId: process.env.TELEGRAM_CHAT_ID,
|
|
26
29
|
};
|
|
27
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Send a Telegram message with HTML formatting
|
|
33
|
+
*/
|
|
28
34
|
async function sendTelegramMessage(header, body) {
|
|
29
35
|
const { botToken, chatId } = getTelegramConfig();
|
|
30
36
|
if (!botToken || !chatId) {
|
|
@@ -41,7 +47,7 @@ async function sendTelegramMessage(header, body) {
|
|
|
41
47
|
: escapedHeader;
|
|
42
48
|
// Setup timeout for fetch request
|
|
43
49
|
const controller = new AbortController();
|
|
44
|
-
const timeoutId = setTimeout(() => controller.abort(),
|
|
50
|
+
const timeoutId = setTimeout(() => controller.abort(), DEFAULT_REQUEST_TIMEOUT_MS);
|
|
45
51
|
try {
|
|
46
52
|
const response = await fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
|
|
47
53
|
method: 'POST',
|
|
@@ -69,7 +75,7 @@ async function sendTelegramMessage(header, body) {
|
|
|
69
75
|
const text = await response.text();
|
|
70
76
|
return {
|
|
71
77
|
success: false,
|
|
72
|
-
error: `Unexpected response type: ${contentType || 'unknown'}. Response: ${text.slice(0,
|
|
78
|
+
error: `Unexpected response type: ${contentType || 'unknown'}. Response: ${text.slice(0, MAX_ERROR_PREVIEW_LENGTH)}`,
|
|
73
79
|
};
|
|
74
80
|
}
|
|
75
81
|
const data = (await response.json());
|
|
@@ -85,9 +91,10 @@ async function sendTelegramMessage(header, body) {
|
|
|
85
91
|
clearTimeout(timeoutId);
|
|
86
92
|
// Handle timeout specifically
|
|
87
93
|
if (error instanceof Error && error.name === 'AbortError') {
|
|
94
|
+
const timeoutSeconds = DEFAULT_REQUEST_TIMEOUT_MS / 1000;
|
|
88
95
|
return {
|
|
89
96
|
success: false,
|
|
90
|
-
error:
|
|
97
|
+
error: `Request timeout (${timeoutSeconds}s)`,
|
|
91
98
|
};
|
|
92
99
|
}
|
|
93
100
|
return {
|
|
@@ -96,6 +103,9 @@ async function sendTelegramMessage(header, body) {
|
|
|
96
103
|
};
|
|
97
104
|
}
|
|
98
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* Handler for send_telegram tool
|
|
108
|
+
*/
|
|
99
109
|
export class SendTelegramToolHandler {
|
|
100
110
|
async execute(args, _context = defaultContext) {
|
|
101
111
|
try {
|
|
@@ -117,10 +127,13 @@ export class SendTelegramToolHandler {
|
|
|
117
127
|
if (error instanceof ZodError) {
|
|
118
128
|
throw new ValidationError(TOOLS.SEND_TELEGRAM, error.message);
|
|
119
129
|
}
|
|
120
|
-
throw new ToolExecutionError(TOOLS.SEND_TELEGRAM, 'Failed to send Telegram message', error);
|
|
130
|
+
throw new ToolExecutionError(TOOLS.SEND_TELEGRAM, 'Failed to send Telegram message', error instanceof Error ? error : new Error(String(error)));
|
|
121
131
|
}
|
|
122
132
|
}
|
|
123
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Handler for telegram_status tool
|
|
136
|
+
*/
|
|
124
137
|
export class TelegramStatusToolHandler {
|
|
125
138
|
async execute(args, _context = defaultContext) {
|
|
126
139
|
try {
|
|
@@ -142,13 +155,17 @@ export class TelegramStatusToolHandler {
|
|
|
142
155
|
if (error instanceof ZodError) {
|
|
143
156
|
throw new ValidationError(TOOLS.TELEGRAM_STATUS, error.message);
|
|
144
157
|
}
|
|
145
|
-
throw new ToolExecutionError(TOOLS.TELEGRAM_STATUS, 'Failed to check Telegram status', error);
|
|
158
|
+
throw new ToolExecutionError(TOOLS.TELEGRAM_STATUS, 'Failed to check Telegram status', error instanceof Error ? error : new Error(String(error)));
|
|
146
159
|
}
|
|
147
160
|
}
|
|
148
161
|
}
|
|
149
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Registry of all tool handlers
|
|
164
|
+
*/
|
|
150
165
|
export const toolHandlers = {
|
|
151
166
|
[TOOLS.SEND_TELEGRAM]: new SendTelegramToolHandler(),
|
|
152
167
|
[TOOLS.TELEGRAM_STATUS]: new TelegramStatusToolHandler(),
|
|
168
|
+
[TOOLS.SEND_AND_WAIT]: new SendAndWaitToolHandler(),
|
|
169
|
+
[TOOLS.CHECK_REPLIES]: new CheckRepliesToolHandler(),
|
|
153
170
|
};
|
|
154
171
|
//# sourceMappingURL=handlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/tools/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAIL,sBAAsB,EACtB,wBAAwB,GAEzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAA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AAC;YAE3B,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,kCAAkC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,gBAAgB,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,EAAE;qBAC5H;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;gBAC9B,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YAClE,CAAC;YACD,MAAM,IAAI,kBAAkB,CAC1B,KAAK,CAAC,eAAe,EACrB,iCAAiC,EACjC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,IAAI,uBAAuB,EAAE;IACpD,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,IAAI,yBAAyB,EAAE;IACxD,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,IAAI,sBAAsB,EAAE;IACnD,CAAC,KAAK,CAAC,aAAa,CAAC,EAAE,IAAI,uBAAuB,EAAE;CAC5C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ToolResult, type ToolHandlerContext } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Handler for send_and_wait tool - send message and optionally poll for replies
|
|
4
|
+
*/
|
|
5
|
+
export declare class SendAndWaitToolHandler {
|
|
6
|
+
execute(args: unknown, context: ToolHandlerContext): Promise<ToolResult>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=send-and-wait.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-and-wait.d.ts","sourceRoot":"","sources":["../../src/tools/send-and-wait.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,kBAAkB,EAExB,MAAM,aAAa,CAAC;AAQrB;;GAEG;AACH,qBAAa,sBAAsB;IAC3B,OAAO,CACX,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,UAAU,CAAC;CAkFvB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { TOOLS, SendAndWaitToolSchema, } from '../types.js';
|
|
2
|
+
import { ToolExecutionError, ValidationError } from '../errors.js';
|
|
3
|
+
import { ZodError } from 'zod';
|
|
4
|
+
import { sendMessage, waitForReply as waitForTelegramReply, } from '../telegram/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Handler for send_and_wait tool - send message and optionally poll for replies
|
|
7
|
+
*/
|
|
8
|
+
export class SendAndWaitToolHandler {
|
|
9
|
+
async execute(args, context) {
|
|
10
|
+
try {
|
|
11
|
+
const { message, waitForReply, timeout, pollInterval } = SendAndWaitToolSchema.parse(args);
|
|
12
|
+
const sendResult = await sendMessage(message);
|
|
13
|
+
if (!sendResult.success) {
|
|
14
|
+
return {
|
|
15
|
+
content: [
|
|
16
|
+
{
|
|
17
|
+
type: 'text',
|
|
18
|
+
text: `✗ Failed to send message: ${sendResult.error}`,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
isError: true,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (!sendResult.messageId) {
|
|
25
|
+
return {
|
|
26
|
+
content: [
|
|
27
|
+
{
|
|
28
|
+
type: 'text',
|
|
29
|
+
text: '✗ Message sent but no ID returned',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
isError: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
if (!waitForReply) {
|
|
36
|
+
return {
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
type: 'text',
|
|
40
|
+
text: `✓ Message sent (ID: ${sendResult.messageId}). Use check_replies tool to poll for responses.`,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const timeoutMs = timeout * 1000;
|
|
46
|
+
const pollIntervalMs = pollInterval * 1000;
|
|
47
|
+
const result = await waitForTelegramReply(sendResult.messageId, timeoutMs, pollIntervalMs, context.sendProgress);
|
|
48
|
+
if (result.found) {
|
|
49
|
+
return {
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: 'text',
|
|
53
|
+
text: `✓ Reply received:\n\n${result.reply}`,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
content: [
|
|
60
|
+
{
|
|
61
|
+
type: 'text',
|
|
62
|
+
text: `⏱ Timeout: No reply received within ${timeout}s. Use check_replies tool to check later.`,
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
if (error instanceof ZodError) {
|
|
69
|
+
throw new ValidationError(TOOLS.SEND_AND_WAIT, error.message);
|
|
70
|
+
}
|
|
71
|
+
throw new ToolExecutionError(TOOLS.SEND_AND_WAIT, 'Failed to send message and wait for reply', error instanceof Error ? error : new Error(String(error)));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=send-and-wait.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send-and-wait.js","sourceRoot":"","sources":["../../src/tools/send-and-wait.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EAGL,qBAAqB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,E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I,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,wBAAwB,MAAM,CAAC,KAAK,EAAE;yBAC7C;qBACF;iBACF,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,uCAAuC,OAAO,2CAA2C;qBAChG;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;gBAC9B,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC,aAAa,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YAChE,CAAC;YACD,MAAM,IAAI,kBAAkB,CAC1B,KAAK,CAAC,aAAa,EACnB,2CAA2C,EAC3C,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAC1D,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* Tool name constants
|
|
4
|
+
*/
|
|
2
5
|
export declare const TOOLS: {
|
|
3
6
|
readonly SEND_TELEGRAM: "send_telegram";
|
|
4
7
|
readonly TELEGRAM_STATUS: "telegram_status";
|
|
8
|
+
readonly SEND_AND_WAIT: "send_and_wait";
|
|
9
|
+
readonly CHECK_REPLIES: "check_replies";
|
|
5
10
|
};
|
|
6
11
|
export type ToolName = typeof TOOLS[keyof typeof TOOLS];
|
|
12
|
+
/**
|
|
13
|
+
* Tool annotations for MCP 2025-11-25 spec
|
|
14
|
+
*/
|
|
7
15
|
export interface ToolAnnotations {
|
|
8
16
|
title?: string;
|
|
9
17
|
readOnlyHint?: boolean;
|
|
@@ -11,6 +19,9 @@ export interface ToolAnnotations {
|
|
|
11
19
|
idempotentHint?: boolean;
|
|
12
20
|
openWorldHint?: boolean;
|
|
13
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Tool definition interface for MCP server
|
|
24
|
+
*/
|
|
14
25
|
export interface ToolDefinition {
|
|
15
26
|
name: ToolName;
|
|
16
27
|
description: string;
|
|
@@ -21,6 +32,9 @@ export interface ToolDefinition {
|
|
|
21
32
|
};
|
|
22
33
|
annotations?: ToolAnnotations;
|
|
23
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Tool result interface matching MCP SDK expectations
|
|
37
|
+
*/
|
|
24
38
|
export interface ToolResult {
|
|
25
39
|
content: Array<{
|
|
26
40
|
type: 'text';
|
|
@@ -29,10 +43,16 @@ export interface ToolResult {
|
|
|
29
43
|
isError?: boolean;
|
|
30
44
|
_meta?: Record<string, unknown>;
|
|
31
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Server configuration
|
|
48
|
+
*/
|
|
32
49
|
export interface ServerConfig {
|
|
33
50
|
name: string;
|
|
34
51
|
version: string;
|
|
35
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Telegram API response structure
|
|
55
|
+
*/
|
|
36
56
|
export interface TelegramResponse {
|
|
37
57
|
ok: boolean;
|
|
38
58
|
description?: string;
|
|
@@ -40,16 +60,28 @@ export interface TelegramResponse {
|
|
|
40
60
|
message_id: number;
|
|
41
61
|
};
|
|
42
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Result of sending a Telegram message
|
|
65
|
+
*/
|
|
43
66
|
export interface SendTelegramResult {
|
|
44
67
|
success: boolean;
|
|
45
68
|
messageId?: number;
|
|
46
69
|
error?: string;
|
|
47
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Progress token from MCP request metadata
|
|
73
|
+
*/
|
|
48
74
|
export type ProgressToken = string | number;
|
|
75
|
+
/**
|
|
76
|
+
* Context passed to tool handlers for sending progress notifications
|
|
77
|
+
*/
|
|
49
78
|
export interface ToolHandlerContext {
|
|
50
79
|
progressToken?: ProgressToken;
|
|
51
80
|
sendProgress: (message: string, progress?: number, total?: number) => Promise<void>;
|
|
52
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Zod schemas for tool arguments
|
|
84
|
+
*/
|
|
53
85
|
export declare const SendTelegramToolSchema: z.ZodObject<{
|
|
54
86
|
header: z.ZodString;
|
|
55
87
|
body: z.ZodOptional<z.ZodString>;
|
|
@@ -57,4 +89,15 @@ export declare const SendTelegramToolSchema: z.ZodObject<{
|
|
|
57
89
|
export declare const TelegramStatusToolSchema: z.ZodObject<{}, z.core.$strip>;
|
|
58
90
|
export type SendTelegramToolArgs = z.infer<typeof SendTelegramToolSchema>;
|
|
59
91
|
export type TelegramStatusToolArgs = z.infer<typeof TelegramStatusToolSchema>;
|
|
92
|
+
export declare const SendAndWaitToolSchema: z.ZodObject<{
|
|
93
|
+
message: z.ZodString;
|
|
94
|
+
waitForReply: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
95
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
96
|
+
pollInterval: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
97
|
+
}, z.core.$strip>;
|
|
98
|
+
export declare const CheckRepliesToolSchema: z.ZodObject<{
|
|
99
|
+
messageId: z.ZodOptional<z.ZodNumber>;
|
|
100
|
+
}, z.core.$strip>;
|
|
101
|
+
export type SendAndWaitToolArgs = z.infer<typeof SendAndWaitToolSchema>;
|
|
102
|
+
export type CheckRepliesToolArgs = z.infer<typeof CheckRepliesToolSchema>;
|
|
60
103
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file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
|
+
SEND_AND_WAIT: 'send_and_wait',
|
|
9
|
+
CHECK_REPLIES: 'check_replies',
|
|
6
10
|
};
|
|
7
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Zod schemas for tool arguments
|
|
13
|
+
*/
|
|
8
14
|
export const SendTelegramToolSchema = z.object({
|
|
9
15
|
header: z.string().describe('Message header/title. Use emoji + status like: ✅ DONE, 🚫 BLOCKED, ❌ ERROR'),
|
|
10
16
|
body: z.string().optional().describe('Optional message body with details. Can be multiline. Supports basic context like PWD, branch, host.'),
|
|
11
17
|
});
|
|
12
18
|
export const TelegramStatusToolSchema = z.object({});
|
|
19
|
+
export const SendAndWaitToolSchema = z.object({
|
|
20
|
+
message: z.string().describe('The message to send to Telegram'),
|
|
21
|
+
waitForReply: z.boolean().optional().default(false).describe('Whether to poll for replies'),
|
|
22
|
+
timeout: z.number().optional().default(300).describe('Maximum seconds to wait for reply'),
|
|
23
|
+
pollInterval: z.number().optional().default(5).describe('Seconds between polls'),
|
|
24
|
+
});
|
|
25
|
+
export const CheckRepliesToolSchema = z.object({
|
|
26
|
+
messageId: z.number().optional().describe('Specific message ID to check, or return all pending'),
|
|
27
|
+
});
|
|
13
28
|
//# sourceMappingURL=types.js.map
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,aAAa,EAAE,eAAe;IAC9B,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;CACtB,CAAC;AAkFX;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,4EAA4E,CAAC;IACzG,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,sGAAsG,CAAC;CAC7I,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAKrD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;IAC/D,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,6BAA6B,CAAC;IAC3F,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,mCAAmC,CAAC;IACzF,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,uBAAuB,CAAC;CACjF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,qDAAqD,CAAC;CACjG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/server.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { TelegramMcpServer } from '../server.js';
|
|
2
|
-
describe('TelegramMcpServer', () => {
|
|
3
|
-
it('should instantiate with correct config', () => {
|
|
4
|
-
const config = {
|
|
5
|
-
name: 'test-server',
|
|
6
|
-
version: '1.0.0',
|
|
7
|
-
};
|
|
8
|
-
const server = new TelegramMcpServer(config);
|
|
9
|
-
expect(server).toBeInstanceOf(TelegramMcpServer);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=server.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.test.js","sourceRoot":"","sources":["../../src/__tests__/server.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAEjD,QAAQ,CAAC,mBAAmB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,MAAM,GAAG;YACb,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,OAAO;SACjB,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|