Documentation
¶
Overview ¶
Package client provides the MCP client implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface {
grpc.ClientConnInterface
// Close closes the connection to the server.
Close() error
// GetState returns the connectivity.State of the ClientConn.
GetState() connectivity.State
}
Conn is an interface that represents a gRPC client connection. It is used to allow for mocking of the gRPC client in tests.
type GrpcClient ¶
type GrpcClient interface {
// Invoke performs a unary RPC and blocks until the response is received.
//
// Parameters:
// - ctx: The context for the RPC.
// - method: The full gRPC method string (e.g., "/service.Service/Method").
// - args: The request message to be sent.
// - reply: The response message to be populated.
// - opts: gRPC call options.
Invoke(ctx context.Context, method string, args any, reply any, opts ...grpc.CallOption) error
// NewStream creates a new gRPC stream.
//
// Parameters:
// - ctx: The context for the stream.
// - desc: The stream description.
// - method: The full gRPC method string.
// - opts: gRPC call options.
NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
}
GrpcClient defines a standard interface for a gRPC client, abstracting the underlying implementation. It provides methods for both unary and streaming RPCs and is compatible with the standard `*grpc.ClientConn`.
type GrpcClientWrapper ¶
type GrpcClientWrapper struct {
Conn
// contains filtered or unexported fields
}
GrpcClientWrapper wraps a `Conn` to adapt it to the `pool.ClosableClient` interface. This allows gRPC clients to be managed by a connection pool, which can improve performance by reusing connections.
func NewGrpcClientWrapper ¶
func NewGrpcClientWrapper(conn Conn, config *configv1.UpstreamServiceConfig) *GrpcClientWrapper
NewGrpcClientWrapper creates a new GrpcClientWrapper.
func (*GrpcClientWrapper) Close ¶
func (w *GrpcClientWrapper) Close() error
Close terminates the underlying gRPC connection, releasing any associated resources.
func (*GrpcClientWrapper) IsHealthy ¶
func (w *GrpcClientWrapper) IsHealthy(ctx context.Context) bool
IsHealthy checks if the underlying gRPC connection is in a usable state.
It returns `true` if the connection's state is not `connectivity.Shutdown`, indicating that it is still active and can be used for new RPCs.
type HTTPClient ¶
type HTTPClient interface {
// Do sends an HTTP request and returns an HTTP response.
//
// Parameters:
// - req: The HTTP request to send.
Do(req *http.Request) (*http.Response, error)
}
HTTPClient defines a standard interface for an HTTP client, abstracting the underlying implementation. This interface is compatible with the standard `*http.Client`.
type HTTPClientWrapper ¶
HTTPClientWrapper wraps an `*http.Client` to adapt it to the `pool.ClosableClient` interface. This allows HTTP clients to be managed by a connection pool, which can help control the number of concurrent connections and reuse them where appropriate.
func NewHTTPClientWrapper ¶
func NewHTTPClientWrapper(client *http.Client, config *configv1.UpstreamServiceConfig) *HTTPClientWrapper
NewHTTPClientWrapper creates a new HTTPClientWrapper.
func (*HTTPClientWrapper) Close ¶
func (w *HTTPClientWrapper) Close() error
Close is a no-op for the `*http.Client` wrapper. The underlying transport manages the connections, and closing the client itself is not typically necessary.
type MCPClient ¶
type MCPClient interface {
// CallTool executes a tool on the MCP service, sending the tool name and
// inputs and returning the result.
//
// Parameters:
// - ctx: The context for the call.
// - params: The parameters for the tool call, including the tool name and
// arguments.
CallTool(ctx context.Context, params *mcp.CallToolParams) (*mcp.CallToolResult, error)
}
MCPClient defines the interface for a client that interacts with an MCP service. It provides a standard method for executing tools.
type WebsocketClientWrapper ¶
WebsocketClientWrapper wraps a *websocket.Conn to adapt it for use in a connection pool, implementing the pool.ClosableClient interface.
func (*WebsocketClientWrapper) Close ¶
func (w *WebsocketClientWrapper) Close() error
Close terminates the underlying WebSocket connection.