Documentation
¶
Overview ¶
Package mcp provides MCP client adapters for connecting to upstream servers.
Package mcp provides MCP client adapters for connecting to upstream servers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientOption ¶
type ClientOption func(*HTTPClient)
ClientOption is a functional option for configuring HTTPClient.
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient sets a custom HTTP client.
func WithTimeout ¶
func WithTimeout(d time.Duration) ClientOption
WithTimeout sets the request timeout for the HTTP client.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient connects to an MCP server via HTTP (Streamable HTTP transport). It implements the outbound.MCPClient interface.
func NewHTTPClient ¶
func NewHTTPClient(endpoint string, opts ...ClientOption) *HTTPClient
NewHTTPClient creates a client for the given MCP server HTTP endpoint. The endpoint is the base URL of the remote MCP server.
func (*HTTPClient) Close ¶
func (c *HTTPClient) Close() error
Close terminates the HTTP connection and cleans up resources. Close is idempotent: calling it multiple times is safe and returns nil. After Close(), the client can be restarted with Start() for a new request cycle. This is required for HTTP mode where each request is a separate Start/Close cycle.
func (*HTTPClient) Start ¶
func (c *HTTPClient) Start(ctx context.Context) (io.WriteCloser, io.ReadCloser, error)
Start establishes the connection to the remote MCP server. Returns io.WriteCloser for sending requests and io.ReadCloser for receiving responses. Uses pipe adapters to bridge HTTP request/response to stream interface.
func (*HTTPClient) Wait ¶
func (c *HTTPClient) Wait() error
Wait blocks until the HTTP connection is closed. Returns nil (HTTP has no process exit like stdio).
type StdioClient ¶
type StdioClient struct {
// contains filtered or unexported fields
}
StdioClient connects to an MCP server via stdio (subprocess). It implements the outbound.MCPClient interface.
func NewStdioClient ¶
func NewStdioClient(serverPath string, serverArgs ...string) *StdioClient
NewStdioClient creates a client for the given MCP server command. The serverPath is the executable to run, and serverArgs are passed to it.
func (*StdioClient) Close ¶
func (c *StdioClient) Close() error
Close terminates the upstream connection and cleans up resources. It kills the process if still running and closes all pipes.
func (*StdioClient) Start ¶
func (c *StdioClient) Start(ctx context.Context) (io.WriteCloser, io.ReadCloser, error)
Start launches the upstream MCP server as a subprocess. Returns the server's stdin (for sending) and stdout (for receiving). The server's stderr is forwarded to os.Stderr (MCP spec allows server logging).
func (*StdioClient) Wait ¶
func (c *StdioClient) Wait() error
Wait blocks until the upstream server process terminates. Returns nil on graceful shutdown, error on failure.