Skip to content

Commit 6dbbc7e

Browse files
committed
update
1 parent 66dd4cc commit 6dbbc7e

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

cmd/mcptools/commands/new.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func findTemplatesDir(sdk string) string {
267267
filepath.Join("templates", sdk),
268268

269269
// User home directory
270-
filepath.Join(os.Getenv("HOME"), ".mcpt", "templates", sdk),
270+
filepath.Join(getHomeDirectory(), ".mcpt", "templates", sdk),
271271

272272
// TemplatesPath from env
273273
filepath.Join(TemplatesPath, sdk),

cmd/mcptools/commands/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func parseJSONBestEffort(jsonString string, params *map[string]any) error {
286286
}
287287

288288
func setUpHistory(line *liner.State) func() {
289-
historyFile := filepath.Join(os.Getenv("HOME"), ".mcp_history")
289+
historyFile := filepath.Join(getHomeDirectory(), ".mcp_history")
290290
if f, err := os.Open(filepath.Clean(historyFile)); err == nil {
291291
_, _ = line.ReadHistory(f)
292292
_ = f.Close()

cmd/mcptools/commands/version.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,18 @@ import (
1010
// Version information placeholder.
1111
var Version = "dev"
1212

13+
// getHomeDirectory returns the user's home directory
14+
// Tries HOME first, then falls back to USERPROFILE for Windows
15+
func getHomeDirectory() string {
16+
homeDir := os.Getenv("HOME")
17+
if homeDir == "" {
18+
homeDir = os.Getenv("USERPROFILE")
19+
}
20+
return homeDir
21+
}
22+
1323
// TemplatesPath information placeholder.
14-
var TemplatesPath = os.Getenv("HOME") + "/.mcpt/templates"
24+
var TemplatesPath = getHomeDirectory() + "/.mcpt/templates"
1525

1626
// VersionCmd creates the version command.
1727
func VersionCmd() *cobra.Command {

pkg/guard/guard_proxy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ func NewFilterServer(allowPatterns, denyPatterns map[string][]string) (*FilterSe
2424
// Create log directory
2525
homeDir := os.Getenv("HOME")
2626
if homeDir == "" {
27-
return nil, fmt.Errorf("HOME environment variable not set")
27+
// On Windows, try USERPROFILE if HOME is not set
28+
homeDir = os.Getenv("USERPROFILE")
29+
if homeDir == "" {
30+
return nil, fmt.Errorf("HOME environment variable not set and USERPROFILE not found")
31+
}
2832
}
2933

3034
logDir := filepath.Join(homeDir, ".mcpt", "logs")

pkg/mock/mock.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ func NewServer() (*Server, error) {
4646
// Create log directory - using a fixed, safe path
4747
homeDir := os.Getenv("HOME")
4848
if homeDir == "" {
49-
return nil, fmt.Errorf("HOME environment variable not set")
49+
// On Windows, try USERPROFILE if HOME is not set
50+
homeDir = os.Getenv("USERPROFILE")
51+
if homeDir == "" {
52+
return nil, fmt.Errorf("HOME environment variable not set and USERPROFILE not found")
53+
}
5054
}
5155

5256
logDir := filepath.Join(homeDir, ".mcpt", "logs")

pkg/proxy/proxy.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func NewProxyServer() (*Server, error) {
4343
// Create log directory
4444
homeDir := os.Getenv("HOME")
4545
if homeDir == "" {
46-
return nil, fmt.Errorf("HOME environment variable not set")
46+
// On Windows, try USERPROFILE if HOME is not set
47+
homeDir = os.Getenv("USERPROFILE")
48+
if homeDir == "" {
49+
return nil, fmt.Errorf("HOME environment variable not set and USERPROFILE not found")
50+
}
4751
}
4852

4953
logDir := filepath.Join(homeDir, ".mcpt", "logs")

0 commit comments

Comments
 (0)