fixed stdio mcp tool usage
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
@@ -165,13 +166,11 @@ var defaultMCPFactory MCPClientFactory = func(toolset string) (MCPClientInterfac
|
||||
env = os.Environ()
|
||||
}
|
||||
|
||||
// Use WithCommandFunc and redirect Stderr directly to os.Stderr
|
||||
// This provides the most reliable way to see subprocess errors
|
||||
// Use WithCommandFunc to configure the command environment
|
||||
c, err = client.NewStdioMCPClientWithOptions(command, env, args,
|
||||
transport.WithCommandFunc(func(ctx context.Context, command string, env []string, args []string) (*exec.Cmd, error) {
|
||||
cmd := exec.CommandContext(ctx, command, args...)
|
||||
cmd.Env = env
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd, nil
|
||||
}),
|
||||
)
|
||||
@@ -209,6 +208,13 @@ var defaultMCPFactory MCPClientFactory = func(toolset string) (MCPClientInterfac
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Redirect stderr from the stdio transport to os.Stderr
|
||||
if cfg.Transport == "stdio" {
|
||||
if stderr, ok := client.GetStderr(c); ok {
|
||||
go io.Copy(os.Stderr, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize the client session
|
||||
initReq := mcp.InitializeRequest{}
|
||||
initReq.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION
|
||||
|
||||
Reference in New Issue
Block a user