Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
105 lines (95 loc) · 2.38 KB
/
Copy pathmain.go
File metadata and controls
105 lines (95 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"context"
"os"
"path/filepath"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v3"
)
const (
dir = ".telegram-mcp"
)
func main() {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
debugPath := os.Getenv("TG_DEBUG_LOG")
if debugPath != "" {
logFile, err := os.OpenFile(debugPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
log.Fatal().Err(err).Msg("Failed to open debug log file")
}
log.Logger = log.Output(logFile)
log.Info().Msgf("Enabling debug logging to %s", debugPath)
}
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal().Err(err).Msg("Failed to get home dir")
}
configDir := filepath.Join(homeDir, dir)
sesionPath := filepath.Join(configDir, "session.json")
app := &cli.Command{
Name: "telegram-mcp",
Usage: "Telegram MCP server",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "app-id",
Usage: "Telegram App ID",
Required: true,
Sources: cli.EnvVars("TG_APP_ID"),
},
&cli.StringFlag{
Name: "api-hash",
Usage: "Telegram API Hash",
Required: true,
Sources: cli.EnvVars("TG_API_HASH"),
},
&cli.StringFlag{
Name: "session",
Usage: "Path to session file",
Value: sesionPath,
Sources: cli.EnvVars("TG_SESSION_PATH"),
},
&cli.StringFlag{
Name: "schema-version",
Usage: "JSON Schema version URL (e.g. https://json-schema.org/draft-07/schema#)",
Sources: cli.EnvVars("TG_SCHEMA_VERSION"),
},
&cli.BoolFlag{
Name: "dry",
Usage: "Test configuration",
Local: true,
HideDefault: true,
},
},
Commands: []*cli.Command{
{
Name: "auth",
Usage: "Authenticate with Telegram",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "phone",
Usage: "Phone number to authenticate with",
Required: true,
Aliases: []string{"p"},
},
&cli.StringFlag{
Name: "password",
Usage: "Password for 2FA if exists",
HideDefault: true,
},
&cli.BoolFlag{
Name: "new",
Usage: "Remove old session and create new one",
HideDefault: true,
},
},
Action: authCommand,
},
},
Action: serve,
}
if err := app.Run(context.Background(), os.Args); err != nil {
log.Fatal().Msg(err.Error())
}
}