mcp

package
v1.0.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

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

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL