Documentation
¶
Overview ¶
Package client provides shared MCP client creation and initialization logic used by both the CLI and TUI.
It wraps the mcp-go SDK client constructors and handles transport selection, auto-detection (streamable-http with SSE fallback), and the MCP initialize handshake using the ToolHive version reported by versions.GetVersionInfo.
Index ¶
Constants ¶
const TransportAuto = "auto"
TransportAuto is the sentinel value that triggers auto-detection of the transport type (try streamable-http first, then fall back to SSE).
Variables ¶
This section is empty.
Functions ¶
func CallTool ¶ added in v0.29.0
func CallTool( ctx context.Context, serverURL, transport, clientName, toolName string, args map[string]any, ) (*mcp.CallToolResult, error)
CallTool connects to the MCP server at serverURL, performs the initialize handshake, invokes the named tool with the supplied arguments, and returns the result. The connection is closed before returning.
args may be nil; in that case the `arguments` field is omitted from the tool call request (equivalent to calling the tool with no inputs).
A nil error indicates the MCP call completed; the returned result may still have IsError=true to signal a tool-level failure that the caller should surface to the user.
func Connect ¶
func Connect(ctx context.Context, serverURL, transport, clientName string) (*mcpclient.Client, error)
Connect creates an MCP SDK client for the given serverURL and transport, starts the underlying transport, and performs the MCP initialize handshake.
The clientName is included in the ClientInfo sent during initialization (e.g. "toolhive-cli" or "toolhive-tui").
transport must be one of:
- TransportAuto -- try streamable-http, fall back to SSE
- "sse"
- "streamable-http"
The returned client is fully connected and ready for use. The caller is responsible for calling Close when done.
Types ¶
This section is empty.