Skip to content

Commit 48c485e

Browse files
committed
Add env vars to servers through stdio client
1 parent 5561d2b commit 48c485e

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

client/stdio.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ type StdioMCPClient struct {
3636
// Returns an error if the subprocess cannot be started or the pipes cannot be created.
3737
func NewStdioMCPClient(
3838
command string,
39+
env []string,
3940
args ...string,
4041
) (*StdioMCPClient, error) {
4142
cmd := exec.Command(command, args...)
4243

44+
cmd.Env = env
45+
4346
stdin, err := cmd.StdinPipe()
4447
if err != nil {
4548
return nil, fmt.Errorf("failed to create stdin pipe: %w", err)

client/stdio_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestStdioMCPClient(t *testing.T) {
3434
}
3535
defer os.Remove(mockServerPath)
3636

37-
client, err := NewStdioMCPClient(mockServerPath)
37+
client, err := NewStdioMCPClient(mockServerPath, []string{})
3838
if err != nil {
3939
t.Fatalf("Failed to create client: %v", err)
4040
}

examples/filesystem_stdio_client/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func main() {
1616
// Using npx to run the filesystem server with /tmp as the only allowed directory
1717
c, err := client.NewStdioMCPClient(
1818
"go",
19+
[]string{}, // Empty ENV
1920
"run",
2021
"github.com/mark3labs/mcp-filesystem-server@latest",
2122
"/tmp",

0 commit comments

Comments
 (0)