From 51148facbcad44c2d154edb543631c9da6ef9dc0 Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Wed, 18 Dec 2024 10:48:38 +0300 Subject: [PATCH] update stdio handling of env --- client/stdio.go | 6 +++++- examples/filesystem_stdio_client/main.go | 8 +++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client/stdio.go b/client/stdio.go index d2b0ed5..ab5301c 100644 --- a/client/stdio.go +++ b/client/stdio.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io" + "os" "os/exec" "sync" "sync/atomic" @@ -41,7 +42,10 @@ func NewStdioMCPClient( ) (*StdioMCPClient, error) { cmd := exec.Command(command, args...) - cmd.Env = env + mergedEnv := os.Environ() + mergedEnv = append(mergedEnv, env...) + + cmd.Env = mergedEnv stdin, err := cmd.StdinPipe() if err != nil { diff --git a/examples/filesystem_stdio_client/main.go b/examples/filesystem_stdio_client/main.go index 8a1a101..5a2d9af 100644 --- a/examples/filesystem_stdio_client/main.go +++ b/examples/filesystem_stdio_client/main.go @@ -12,13 +12,11 @@ import ( ) func main() { - // Create a new client instance - // Using npx to run the filesystem server with /tmp as the only allowed directory c, err := client.NewStdioMCPClient( - "go", + "npx", []string{}, // Empty ENV - "run", - "github.com/mark3labs/mcp-filesystem-server@latest", + "-y", + "@modelcontextprotocol/server-filesystem", "/tmp", ) if err != nil {