mcpclient

package
v0.2.30 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mcpclient provides a lightweight MCP HTTP client for communicating with klaus agent instances. It wraps the mcp-go client library to handle session initialization, tool invocation, and per-instance session caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractText added in v0.0.42

func ExtractText(result *mcp.CallToolResult) string

ExtractText returns the concatenated text content from an MCP tool result. Only TextContent items are extracted; non-text content types (images, etc.) are silently skipped.

func IsTerminalStatus added in v0.0.42

func IsTerminalStatus(status string) bool

IsTerminalStatus reports whether the given agent status indicates that the task is finished (successfully or otherwise).

func ParseStatusField added in v0.0.42

func ParseStatusField(result *mcp.CallToolResult) string

ParseStatusField extracts the "status" JSON field from an MCP tool result. Returns the status string if found, or empty string otherwise.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages MCP connections to klaus agent instances. It caches sessions per instance to avoid re-initializing on every call.

func New

func New(version string) *Client

New creates a new Client. The version string is sent during MCP session initialization so the remote agent knows which klausctl build is calling.

func NewWithHeaders added in v0.0.58

func NewWithHeaders(version string, headers map[string]string) *Client

NewWithHeaders returns a Client that attaches the given HTTP headers to every MCP HTTP request. Use this for remote klaus-gateway sessions that need the X-Klaus-* routing headers and/or Authorization bearer.

func (*Client) Close

func (c *Client) Close()

Close closes all cached sessions.

func (*Client) Messages added in v0.0.34

func (c *Client) Messages(ctx context.Context, instanceName, baseURL string, opts *MessagesOpts) (*mcp.CallToolResult, error)

Messages retrieves the agent's conversation messages. When opts is non-nil, offset and types are forwarded to the agent.

func (*Client) Prompt

func (c *Client) Prompt(ctx context.Context, instanceName, baseURL, message string) (*mcp.CallToolResult, error)

Prompt sends a prompt message to the agent instance.

func (*Client) Result

func (c *Client) Result(ctx context.Context, instanceName, baseURL string, full bool) (*mcp.CallToolResult, error)

Result retrieves the agent's last result. When full is true, the agent returns extended detail (tool_calls, model_usage, token_usage, etc.).

func (*Client) SessionID

func (c *Client) SessionID(instanceName string) string

SessionID returns the MCP session ID for the given instance, if any.

func (*Client) Status

func (c *Client) Status(ctx context.Context, instanceName, baseURL string) (*mcp.CallToolResult, error)

Status queries the agent's current status.

type MessagesOpts added in v0.0.42

type MessagesOpts struct {
	Offset int
	Types  string
}

MessagesOpts holds optional parameters for the Messages call.

Jump to

Keyboard shortcuts

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