mcpclient

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotDispatched = errors.New("MCP request was not dispatched")

ErrNotDispatched distinguishes a failed local authorization/preflight check from a transport error after a write may have reached the gateway.

View Source
var ErrUnauthorized = errors.New("MCP authorization was rejected")

ErrUnauthorized means the gateway explicitly rejected authentication. It is not an unknown write outcome and never triggers an automatic login or replay.

Functions

func WithDispatchGuard

func WithDispatchGuard(ctx context.Context, guard func() error) context.Context

WithDispatchGuard checks session-local state after token refresh and directly before dispatch. A rejected guard never sends the HTTP request. It is used to prevent a preview authorized before reauthentication from being confirmed.

Types

type Client

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

func Connect

func Connect(ctx context.Context, accessToken string) (*Client, error)

func ConnectTo

func ConnectTo(ctx context.Context, endpoint, accessToken string, base *http.Client) (*Client, error)

func ConnectToWithTokenProvider

func ConnectToWithTokenProvider(ctx context.Context, endpoint string, provider TokenProvider, base *http.Client) (*Client, error)

func ConnectWithTokenProvider

func ConnectWithTokenProvider(ctx context.Context, provider TokenProvider) (*Client, error)

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, arguments map[string]any) (*ToolOutcome, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) ListResourceTemplates

func (c *Client) ListResourceTemplates(ctx context.Context) ([]*mcp.ResourceTemplate, error)

func (*Client) ListResources

func (c *Client) ListResources(ctx context.Context) ([]*mcp.Resource, error)

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context) ([]*mcp.Tool, error)

func (*Client) ReadResource

func (c *Client) ReadResource(ctx context.Context, uri string) (*ResourceOutcome, error)

type ResourceOutcome

type ResourceOutcome struct {
	URI    string                  `json:"uri"`
	Result *mcp.ReadResourceResult `json:"result"`
}

func (*ResourceOutcome) HumanText

func (o *ResourceOutcome) HumanText() string

type TokenProvider

type TokenProvider func(context.Context) (string, error)

TokenProvider is called for each HTTP request, allowing the CLI-owned OAuth service to refresh expiring credentials without reconnecting or replaying a tool call. Calls to a provider are serialized by this package.

type ToolOutcome

type ToolOutcome struct {
	Tool      string              `json:"tool"`
	State     ToolState           `json:"state"`
	PreviewID string              `json:"preview_id,omitempty"`
	Result    *mcp.CallToolResult `json:"result"`
}

func NewToolOutcome

func NewToolOutcome(name string, result *mcp.CallToolResult) *ToolOutcome

func (*ToolOutcome) HumanText

func (o *ToolOutcome) HumanText() string

func (*ToolOutcome) IsError

func (o *ToolOutcome) IsError() bool

func (*ToolOutcome) IsPreview

func (o *ToolOutcome) IsPreview() bool

type ToolState

type ToolState string
const (
	StateReturned  ToolState = "returned"
	StateCommitted ToolState = "committed"
	StatePreview   ToolState = "preview"
	StateSubmitted ToolState = "submitted_for_approval"
	StateError     ToolState = "error"
)

Jump to

Keyboard shortcuts

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