@ebowwa/channel-telegram 1.12.6 → 1.13.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 +78 -44
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +3 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/commands/restart.d.ts +7 -0
- package/dist/commands/restart.d.ts.map +1 -0
- package/dist/commands/restart.js +29 -0
- package/dist/commands/restart.js.map +1 -0
- package/dist/commands/settings.d.ts +8 -0
- package/dist/commands/settings.d.ts.map +1 -0
- package/dist/commands/settings.js +16 -0
- package/dist/commands/settings.js.map +1 -0
- package/dist/index.d.ts +83 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +352 -712
- package/dist/index.js.map +1 -1
- package/package.json +8 -12
- package/src/commands/index.ts +3 -0
- package/src/commands/restart.ts +41 -0
- package/src/commands/settings.ts +24 -0
- package/src/index.ts +418 -823
- package/dist/mcp/client.d.ts +0 -50
- package/dist/mcp/client.d.ts.map +0 -1
- package/dist/mcp/client.js +0 -150
- package/dist/mcp/client.js.map +0 -1
- package/dist/mcp/index.d.ts +0 -5
- package/dist/mcp/index.d.ts.map +0 -1
- package/dist/mcp/index.js +0 -5
- package/dist/mcp/index.js.map +0 -1
- package/src/api/fetch-retry.js +0 -96
- package/src/api/keys.js +0 -25
- package/src/commands/cancel.js +0 -120
- package/src/commands/clear.js +0 -59
- package/src/commands/doppler.js +0 -118
- package/src/commands/git.js +0 -126
- package/src/commands/help.js +0 -74
- package/src/commands/index.js +0 -65
- package/src/commands/logs.js +0 -81
- package/src/commands/pause.js +0 -133
- package/src/commands/resources.js +0 -87
- package/src/commands/resume.js +0 -95
- package/src/commands/start.js +0 -68
- package/src/commands/status.js +0 -62
- package/src/commands/tools.js +0 -67
- package/src/commands/toolsoutput.js +0 -85
- package/src/commands/types.js +0 -5
- package/src/conversation-memory.js +0 -216
- package/src/index.js +0 -736
- package/src/mcp/client.ts +0 -188
- package/src/mcp/index.ts +0 -5
- package/src/types.js +0 -5
package/src/mcp/client.ts
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Client - Connect to MCP servers and expose their tools
|
|
3
|
-
*
|
|
4
|
-
* Uses stdio transport to communicate with local MCP servers
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
8
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
9
|
-
|
|
10
|
-
export interface MCPTool {
|
|
11
|
-
name: string;
|
|
12
|
-
description: string;
|
|
13
|
-
inputSchema: Record<string, unknown>;
|
|
14
|
-
serverName: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface MCPServerConfig {
|
|
18
|
-
name: string;
|
|
19
|
-
command: string;
|
|
20
|
-
args?: string[];
|
|
21
|
-
env?: Record<string, string>;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export class MCPClient {
|
|
25
|
-
private clients: Map<string, Client> = new Map();
|
|
26
|
-
private transports: Map<string, StdioClientTransport> = new Map();
|
|
27
|
-
private tools: MCPTool[] = [];
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Default MCP servers to connect to
|
|
31
|
-
* Uses globally installed @ebowwa/*-mcp packages
|
|
32
|
-
*/
|
|
33
|
-
static DEFAULT_SERVERS: MCPServerConfig[] = [
|
|
34
|
-
{
|
|
35
|
-
name: 'hetzner',
|
|
36
|
-
command: '/root/.bun/bin/bun',
|
|
37
|
-
args: ['/root/.bun/install/global/node_modules/@ebowwa/hetzner-mcp/dist/index.js'],
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
constructor(private servers: MCPServerConfig[] = MCPClient.DEFAULT_SERVERS) {}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Connect to all configured MCP servers
|
|
45
|
-
*/
|
|
46
|
-
async connect(): Promise<void> {
|
|
47
|
-
console.log(`[MCP] Connecting to ${this.servers.length} servers...`);
|
|
48
|
-
|
|
49
|
-
for (const server of this.servers) {
|
|
50
|
-
try {
|
|
51
|
-
await this.connectToServer(server);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
console.error(`[MCP] Failed to connect to ${server.name}:`, error);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
console.log(`[MCP] Connected. Found ${this.tools.length} tools.`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Connect to a single MCP server
|
|
62
|
-
*/
|
|
63
|
-
private async connectToServer(server: MCPServerConfig): Promise<void> {
|
|
64
|
-
console.log(`[MCP] Connecting to ${server.name}...`);
|
|
65
|
-
|
|
66
|
-
// Build env - filter out undefined values
|
|
67
|
-
const env: Record<string, string> = {};
|
|
68
|
-
for (const [key, value] of Object.entries(process.env)) {
|
|
69
|
-
if (value !== undefined) {
|
|
70
|
-
env[key] = value;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (server.env) {
|
|
74
|
-
Object.assign(env, server.env);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Create stdio transport - it handles spawning the process
|
|
78
|
-
const transport = new StdioClientTransport({
|
|
79
|
-
command: server.command,
|
|
80
|
-
args: server.args,
|
|
81
|
-
env,
|
|
82
|
-
stderr: 'pipe',
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
this.transports.set(server.name, transport);
|
|
86
|
-
|
|
87
|
-
// Handle stderr for debugging
|
|
88
|
-
const stderr = transport.stderr;
|
|
89
|
-
if (stderr) {
|
|
90
|
-
stderr.on('data', (data: Buffer) => {
|
|
91
|
-
console.error(`[MCP:${server.name}] ${data.toString().trim()}`);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Create MCP client
|
|
96
|
-
const client = new Client(
|
|
97
|
-
{ name: `telegram-bot-mcp-${server.name}`, version: '1.0.0' },
|
|
98
|
-
{ capabilities: {} }
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
await client.connect(transport);
|
|
102
|
-
this.clients.set(server.name, client);
|
|
103
|
-
|
|
104
|
-
// Discover tools
|
|
105
|
-
const toolsResult = await client.listTools();
|
|
106
|
-
|
|
107
|
-
for (const tool of toolsResult.tools) {
|
|
108
|
-
this.tools.push({
|
|
109
|
-
name: tool.name,
|
|
110
|
-
description: tool.description || '',
|
|
111
|
-
inputSchema: tool.inputSchema as Record<string, unknown>,
|
|
112
|
-
serverName: server.name,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
console.log(`[MCP] ${server.name}: Found ${toolsResult.tools.length} tools`);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Get all discovered MCP tools
|
|
121
|
-
*/
|
|
122
|
-
getTools(): MCPTool[] {
|
|
123
|
-
return this.tools;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Call an MCP tool
|
|
128
|
-
*/
|
|
129
|
-
async callTool(name: string, args: Record<string, unknown>): Promise<string> {
|
|
130
|
-
const tool = this.tools.find(t => t.name === name);
|
|
131
|
-
|
|
132
|
-
if (!tool) {
|
|
133
|
-
throw new Error(`Tool not found: ${name}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const client = this.clients.get(tool.serverName);
|
|
137
|
-
|
|
138
|
-
if (!client) {
|
|
139
|
-
throw new Error(`MCP server not connected: ${tool.serverName}`);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
const result = await client.callTool({
|
|
144
|
-
name,
|
|
145
|
-
arguments: args,
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// Extract text content from result
|
|
149
|
-
if (result.content && Array.isArray(result.content)) {
|
|
150
|
-
return result.content
|
|
151
|
-
.map((c: { type: string; text?: string }) => c.text || '')
|
|
152
|
-
.join('\n');
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return JSON.stringify(result);
|
|
156
|
-
} catch (error) {
|
|
157
|
-
throw new Error(`MCP tool error: ${(error as Error).message}`);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Disconnect from all MCP servers
|
|
163
|
-
*/
|
|
164
|
-
async disconnect(): Promise<void> {
|
|
165
|
-
console.log('[MCP] Disconnecting...');
|
|
166
|
-
|
|
167
|
-
for (const [name, client] of this.clients) {
|
|
168
|
-
try {
|
|
169
|
-
await client.close();
|
|
170
|
-
console.log(`[MCP] Disconnected from ${name}`);
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error(`[MCP] Error disconnecting from ${name}:`, error);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
for (const [name, transport] of this.transports) {
|
|
177
|
-
try {
|
|
178
|
-
await transport.close();
|
|
179
|
-
} catch (error) {
|
|
180
|
-
console.error(`[MCP] Error closing transport ${name}:`, error);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
this.clients.clear();
|
|
185
|
-
this.transports.clear();
|
|
186
|
-
this.tools = [];
|
|
187
|
-
}
|
|
188
|
-
}
|
package/src/mcp/index.ts
DELETED