mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
2bd709db63
Bumps [github.com/mark3labs/mcp-go](https://github.com/mark3labs/mcp-go) from 0.37.0 to 0.43.0. - [Release notes](https://github.com/mark3labs/mcp-go/releases) - [Commits](https://github.com/mark3labs/mcp-go/compare/v0.37.0...v0.43.0) --- updated-dependencies: - dependency-name: github.com/mark3labs/mcp-go dependency-version: 0.43.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/mark3labs/mcp-go/client/transport"
|
|
)
|
|
|
|
// NewStdioMCPClient creates a new stdio-based MCP client that communicates with a subprocess.
|
|
// It launches the specified command with given arguments and sets up stdin/stdout pipes for communication.
|
|
// Returns an error if the subprocess cannot be started or the pipes cannot be created.
|
|
//
|
|
// NOTICE: NewStdioMCPClient will start the connection automatically.
|
|
// This is for backward compatibility.
|
|
func NewStdioMCPClient(
|
|
command string,
|
|
env []string,
|
|
args ...string,
|
|
) (*Client, error) {
|
|
return NewStdioMCPClientWithOptions(command, env, args)
|
|
}
|
|
|
|
// NewStdioMCPClientWithOptions creates a new stdio-based MCP client that communicates with a subprocess.
|
|
// It launches the specified command with given arguments and sets up stdin/stdout pipes for communication.
|
|
// Optional configuration functions can be provided to customize the transport before it starts,
|
|
// such as setting a custom command function.
|
|
//
|
|
// NOTICE: NewStdioMCPClientWithOptions automatically starts the underlying transport.
|
|
// This is for backward compatibility.
|
|
func NewStdioMCPClientWithOptions(
|
|
command string,
|
|
env []string,
|
|
args []string,
|
|
opts ...transport.StdioOption,
|
|
) (*Client, error) {
|
|
stdioTransport := transport.NewStdioWithOptions(command, env, args, opts...)
|
|
|
|
if err := stdioTransport.Start(context.Background()); err != nil {
|
|
return nil, fmt.Errorf("failed to start stdio transport: %w", err)
|
|
}
|
|
|
|
return NewClient(stdioTransport), nil
|
|
}
|
|
|
|
// GetStderr returns a reader for the stderr output of the subprocess.
|
|
// This can be used to capture error messages or logs from the subprocess.
|
|
func GetStderr(c *Client) (io.Reader, bool) {
|
|
t := c.GetTransport()
|
|
|
|
stdio, ok := t.(*transport.Stdio)
|
|
if !ok {
|
|
return nil, false
|
|
}
|
|
|
|
return stdio.Stderr(), true
|
|
}
|