Skip to content

Commit 9ea4a10

Browse files
andigclaude
andcommitted
feat: add graceful shutdown handling to sampling HTTP client example
Add signal handling for SIGINT and SIGTERM to allow graceful shutdown of the sampling HTTP client example. This prevents indefinite blocking and provides better production-ready behavior. Addresses review comment about adding graceful shutdown handling. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 83883ed commit 9ea4a10

File tree

1 file changed

+8
-0
lines changed
  • examples/sampling_http_client

1 file changed

+8
-0
lines changed

examples/sampling_http_client/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import (
44
"context"
55
"fmt"
66
"log"
7+
"os"
8+
"os/signal"
9+
"syscall"
710

811
"github.com/mark3labs/mcp-go/client"
912
"github.com/mark3labs/mcp-go/client/transport"
@@ -101,8 +104,13 @@ func main() {
101104
// For this example, we'll just demonstrate that it's working
102105

103106
// Keep the client running (in a real app, you'd have your main application logic here)
107+
sigChan := make(chan os.Signal, 1)
108+
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
109+
104110
select {
105111
case <-ctx.Done():
106112
log.Println("Client context cancelled")
113+
case <-sigChan:
114+
log.Println("Received shutdown signal")
107115
}
108116
}

0 commit comments

Comments
 (0)