Skip to content

Commit

Permalink
Add env vars to servers through stdio client
Browse files Browse the repository at this point in the history
  • Loading branch information
ezynda3 committed Dec 13, 2024
1 parent 5561d2b commit 48c485e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/stdio.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ type StdioMCPClient struct {
// Returns an error if the subprocess cannot be started or the pipes cannot be created.
func NewStdioMCPClient(
command string,
env []string,
args ...string,
) (*StdioMCPClient, error) {
cmd := exec.Command(command, args...)

cmd.Env = env

stdin, err := cmd.StdinPipe()
if err != nil {
return nil, fmt.Errorf("failed to create stdin pipe: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion client/stdio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestStdioMCPClient(t *testing.T) {
}
defer os.Remove(mockServerPath)

client, err := NewStdioMCPClient(mockServerPath)
client, err := NewStdioMCPClient(mockServerPath, []string{})
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
Expand Down
1 change: 1 addition & 0 deletions examples/filesystem_stdio_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func main() {
// Using npx to run the filesystem server with /tmp as the only allowed directory
c, err := client.NewStdioMCPClient(
"go",
[]string{}, // Empty ENV
"run",
"github.com/mark3labs/mcp-filesystem-server@latest",
"/tmp",
Expand Down

0 comments on commit 48c485e

Please sign in to comment.