Skip to content

Commit 6c82d02

Browse files
committed
Use the main context for the MCP handler as well
1 parent 048185f commit 6c82d02

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

internal/tiger/cmd/mcp.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import (
66
"fmt"
77
"net"
88
"net/http"
9-
"os"
10-
"os/signal"
11-
"syscall"
129

1310
"github.com/spf13/cobra"
1411
"go.uber.org/zap"
@@ -211,7 +208,7 @@ func startStdioServer(ctx context.Context) error {
211208
logging.Info("Starting Tiger MCP server", zap.String("transport", "stdio"))
212209

213210
// Setup graceful shutdown handling
214-
ctx, stop := signalContext(ctx)
211+
ctx, stop := watchContext(ctx)
215212
defer stop()
216213

217214
// Create MCP server
@@ -238,7 +235,7 @@ func startHTTPServer(ctx context.Context, host string, port int) error {
238235
logging.Info("Starting Tiger MCP server", zap.String("transport", "http"))
239236

240237
// Setup graceful shutdown handling
241-
ctx, stop := signalContext(ctx)
238+
ctx, stop := watchContext(ctx)
242239
defer stop()
243240

244241
// Create MCP server
@@ -312,27 +309,16 @@ func getListener(host string, startPort int) (net.Listener, int, error) {
312309
return nil, 0, fmt.Errorf("no available port found in range %d-%d", startPort, startPort+99)
313310
}
314311

315-
// signalContext sets up graceful shutdown handling and returns a context and
312+
// watchContext sets up graceful shutdown handling and returns a context and
316313
// cleanup function. This is nearly identical to [signal.NotifyContext], except
317314
// that it logs a message when a signal is received.
318-
func signalContext(parent context.Context) (context.Context, context.CancelFunc) {
315+
func watchContext(parent context.Context) (context.Context, context.CancelFunc) {
319316
ctx, cancel := context.WithCancel(parent)
320317

321-
sigChan := make(chan os.Signal, 1)
322-
signal.Notify(sigChan, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
323318
go func() {
324-
select {
325-
case sig := <-sigChan:
326-
logging.Info("Received interrupt signal, shutting down MCP server...",
327-
zap.Stringer("signal", sig),
328-
)
329-
cancel()
330-
case <-ctx.Done():
331-
}
319+
<-ctx.Done()
320+
logging.Info("Received interrupt signal, shutting down MCP server...")
332321
}()
333322

334-
return ctx, func() {
335-
cancel()
336-
signal.Stop(sigChan)
337-
}
323+
return ctx, func() { cancel() }
338324
}

0 commit comments

Comments
 (0)