@@ -3,12 +3,14 @@ package main
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "io"
6
7
stdlog "log"
7
8
"os"
8
9
"os/signal"
9
10
"syscall"
10
11
11
12
"github.com/github/github-mcp-server/pkg/github"
13
+ iolog "github.com/github/github-mcp-server/pkg/log"
12
14
gogithub "github.com/google/go-github/v69/github"
13
15
"github.com/mark3labs/mcp-go/server"
14
16
log "github.com/sirupsen/logrus"
33
35
if err != nil {
34
36
stdlog .Fatal ("Failed to initialize logger:" , err )
35
37
}
36
- if err := runStdioServer (logger ); err != nil {
38
+ logCommands := viper .GetBool ("enable-command-logging" )
39
+ if err := runStdioServer (logger , logCommands ); err != nil {
37
40
stdlog .Fatal ("failed to run stdio server:" , err )
38
41
}
39
42
},
@@ -45,9 +48,11 @@ func init() {
45
48
46
49
// Add global flags that will be shared by all commands
47
50
rootCmd .PersistentFlags ().String ("log-file" , "" , "Path to log file" )
51
+ rootCmd .PersistentFlags ().Bool ("enable-command-logging" , false , "When enabled, the server will log all command requests and responses to the log file" )
48
52
49
53
// Bind flag to viper
50
54
viper .BindPFlag ("log-file" , rootCmd .PersistentFlags ().Lookup ("log-file" ))
55
+ viper .BindPFlag ("enable-command-logging" , rootCmd .PersistentFlags ().Lookup ("enable-command-logging" ))
51
56
52
57
// Add subcommands
53
58
rootCmd .AddCommand (stdioCmd )
@@ -70,12 +75,13 @@ func initLogger(outPath string) (*log.Logger, error) {
70
75
}
71
76
72
77
logger := log .New ()
78
+ logger .SetLevel (log .DebugLevel )
73
79
logger .SetOutput (file )
74
80
75
81
return logger , nil
76
82
}
77
83
78
- func runStdioServer (logger * log.Logger ) error {
84
+ func runStdioServer (logger * log.Logger , logCommands bool ) error {
79
85
// Create app context
80
86
ctx , stop := signal .NotifyContext (context .Background (), os .Interrupt , syscall .SIGTERM )
81
87
defer stop ()
@@ -97,7 +103,14 @@ func runStdioServer(logger *log.Logger) error {
97
103
// Start listening for messages
98
104
errC := make (chan error , 1 )
99
105
go func () {
100
- errC <- stdioServer .Listen (ctx , os .Stdin , os .Stdout )
106
+ in , out := io .Reader (os .Stdin ), io .Writer (os .Stdout )
107
+
108
+ if logCommands {
109
+ loggedIO := iolog .NewIOLogger (in , out , logger )
110
+ in , out = loggedIO , loggedIO
111
+ }
112
+
113
+ errC <- stdioServer .Listen (ctx , in , out )
101
114
}()
102
115
103
116
// Output github-mcp-server string
0 commit comments