mcpclient

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package mcpclient is a small Model Context Protocol client for the AudD account service: Streamable HTTP transport, JSON-RPC 2.0, tools/list and tools/call. The session ID is cached on disk for a few minutes so back-to-back commands skip the initialize handshake.

Index

Constants

View Source
const ProtocolVersion = "2025-06-18"

ProtocolVersion is the MCP revision the client speaks.

View Source
const SessionTTL = 10 * time.Minute

SessionTTL is how long a cached session ID is reused.

Variables

View Source
var ToolScopes = map[string]string{
	"get_profile":            "profile:read",
	"get_account_status":     "account:read",
	"get_usage_stats":        "usage:read",
	"get_api_token":          "token:read",
	"rotate_api_token":       "token:write",
	"list_plans":             "billing:read",
	"get_billing_history":    "billing:read",
	"get_amount_owed":        "billing:read",
	"subscribe_to_plan":      "billing:pay",
	"create_renewal_payment": "billing:pay",
	"buy_bonus_requests":     "billing:pay",
}

ToolScopes names the OAuth scope each AudD tool needs; used in hints.

Functions

func ToolError

func ToolError(tool, text string) *output.Error

ToolError maps a tool result with isError set to a CLI error.

Types

type Client

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

Client talks to one MCP server.

func New

func New(baseURL string, token func(ctx context.Context) (string, error), opts ...Option) *Client

New returns a client for the MCP endpoint baseURL. token returns the current OAuth access token.

func (*Client) CallTool

func (c *Client) CallTool(ctx context.Context, name string, args map[string]any) (structured map[string]any, text string, err error)

CallTool calls a tool. It returns the structured result (nil when the tool returned none) and the text content. A result with isError set is returned as an *output.Error.

func (*Client) ListTools

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

ListTools returns the tools available to this sign-in.

type Option

type Option func(*Client)

Option configures a Client.

func WithHTTPClient

func WithHTTPClient(h *http.Client) Option

WithHTTPClient sets the HTTP client.

func WithNow

func WithNow(f func() time.Time) Option

WithNow sets the clock.

func WithRefresh

func WithRefresh(f func(ctx context.Context) (string, error)) Option

WithRefresh sets how to get a new access token, whatever its expiry, when the server rejects the current one (revoked early, clock skew). The request is then retried once.

func WithSessionCache

func WithSessionCache(path string) Option

WithSessionCache stores the session ID at path (e.g. CacheDir()/mcp-session-<profile>).

func WithUserAgent

func WithUserAgent(ua string) Option

WithUserAgent sets the User-Agent header.

type Tool

type Tool struct {
	Name         string         `json:"name"`
	Description  string         `json:"description,omitempty"`
	InputSchema  map[string]any `json:"inputSchema,omitempty"`
	OutputSchema map[string]any `json:"outputSchema,omitempty"`
}

Tool describes a server tool.

Jump to

Keyboard shortcuts

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