Skip to content

Commit 82caadb

Browse files
committed
catch and log panic
1 parent 4f7077a commit 82caadb

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

cmd/github-mcp-server/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
stdlog "log"
88
"os"
99
"os/signal"
10+
"runtime/debug"
1011
"syscall"
1112

1213
"github.com/github/github-mcp-server/pkg/github"
@@ -133,13 +134,19 @@ func runStdioServer(readOnly bool, logger *log.Logger, logCommands bool, exportT
133134
// Start listening for messages
134135
errC := make(chan error, 1)
135136
go func() {
137+
defer func() {
138+
if r := recover(); r != nil {
139+
logger.Errorf("panic occurred: %v\n stack trace:\n%s", r, debug.Stack())
140+
errC <- fmt.Errorf("panic: %v", r)
141+
}
142+
}()
143+
136144
in, out := io.Reader(os.Stdin), io.Writer(os.Stdout)
137145

138146
if logCommands {
139147
loggedIO := iolog.NewIOLogger(in, out, logger)
140148
in, out = loggedIO, loggedIO
141149
}
142-
143150
errC <- stdioServer.Listen(ctx, in, out)
144151
}()
145152

0 commit comments

Comments
 (0)