Skip to content

Commit 7d2188b

Browse files
committed
add fallback for demonstration
1 parent 96b2183 commit 7d2188b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

examples/roots_client/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import (
2020
type MockRootsHandler struct{}
2121

2222
func (h *MockRootsHandler) ListRoots(ctx context.Context, request mcp.ListRootsRequest) (*mcp.ListRootsResult, error) {
23-
home, _ := os.UserHomeDir()
23+
home, err := os.UserHomeDir()
24+
if err != nil {
25+
log.Printf("Warning: failed to get home directory: %v", err)
26+
home = "/tmp" // fallback for demonstration
27+
}
2428
app := filepath.ToSlash(filepath.Join(home, "app"))
2529
proj := filepath.ToSlash(filepath.Join(home, "projects", "test-project"))
2630
result := &mcp.ListRootsResult{

examples/roots_http_client/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ import (
2020
type MockRootsHandler struct{}
2121

2222
func (h *MockRootsHandler) ListRoots(ctx context.Context, request mcp.ListRootsRequest) (*mcp.ListRootsResult, error) {
23-
home, _ := os.UserHomeDir()
23+
home, err := os.UserHomeDir()
24+
if err != nil {
25+
log.Printf("Warning: failed to get home directory: %v", err)
26+
home = "/tmp" // fallback for demonstration
27+
}
2428
app := filepath.ToSlash(filepath.Join(home, "app"))
2529
proj := filepath.ToSlash(filepath.Join(home, "projects", "test-project"))
2630
result := &mcp.ListRootsResult{

0 commit comments

Comments
 (0)