client

package
v0.2.0 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package client implements a minimal MCP client over HTTP (JSON-RPC 2.0), used by `cartographer agents/connect/status/sync` to talk to a remote cartographer server. The client always uses the HTTP transport (see decisions.md D-client-http): generating stdio MCP configs is out of scope, the CLI itself is the only consumer.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnauthorized = errors.New("unauthorized (401): check the bearer token/env var")

ErrUnauthorized indicates the server rejected the request with HTTP 401 — distinguished from other failures (network down, timeout, 5xx) so callers probing a server before committing to a connect (Ping, D64) can tell "wrong token/env" apart from "server unreachable" and word their error accordingly.

Functions

This section is empty.

Types

type Health added in v0.2.0

type Health struct {
	Status  string      `json:"status"`
	Version string      `json:"version"`
	Ready   *bool       `json:"ready"`
	KBs     *[]HealthKB `json:"kbs"`
}

Health is the additive subset of the server's /health response that clients use to distinguish a reachable-but-unusable empty multi-KB server from one that can accept MCP requests. Ready and KBs are pointers so callers can distinguish an older server that did not send either field from an explicit false/empty value.

type HealthKB added in v0.2.0

type HealthKB struct {
	Name string `json:"name"`
}

HealthKB is the additive per-KB item returned by a MultiKB server's /health endpoint. A single-KB (and older) server omits the kbs field altogether, which callers distinguish through Health.KBs being nil.

func (*HealthKB) UnmarshalJSON added in v0.2.0

func (k *HealthKB) UnmarshalJSON(data []byte) error

UnmarshalJSON accepts the current {"name":"..."} health shape and the short string array used by early multi-KB builds. Keeping both shapes makes client enumeration additive in the same way the optional kbs field is.

type MCPClient

type MCPClient struct {
	ServerURL string // e.g. "http://localhost:8080/mcp"
	Token     string // bearer token, empty = no Authorization header
	KB        string // optional KB name; appended as ?kb=<KB> (multi-KB server routing, see httpserver.go)
	HTTP      *http.Client
}

MCPClient is a minimal JSON-RPC 2.0 client for the MCP `tools/call` method.

func New

func New(serverURL, token string) *MCPClient

New creates an MCPClient for serverURL with an optional bearer token.

func (*MCPClient) Call

func (c *MCPClient) Call(tool string, args any) (json.RawMessage, error)

Call invokes an MCP tool via tools/call and returns the decoded JSON payload from the tool's first text content block (the convention used by every cartographer tool: textResult/errorResult in internal/mcpserver/protocol.go).

func (*MCPClient) Health added in v0.2.0

func (c *MCPClient) Health(timeout time.Duration) (*Health, error)

Health fetches GET /health for the configured MCP endpoint. serverURL normally ends in /mcp; only that terminal path segment is stripped, leaving deployments whose endpoint is rooted elsewhere intact. Like Ping, timeout applies only to this call and does not mutate the client shared by later sync_pull requests.

func (*MCPClient) Ping

func (c *MCPClient) Ping(timeout time.Duration) error

Ping performs a minimal round trip against the server to check reachability and, when a token is set, that it's accepted — without invoking any tool. It uses the JSON-RPC "ping" method (see mcpserver.dispatch), the cheapest request the protocol defines: no KB access, no tool lookup. timeout bounds this single call independently of the client's normal HTTP timeout (30s), so a probe before a full connect (D64) fails fast instead of hanging. Returns nil on success, ErrUnauthorized on HTTP 401, or the underlying network/timeout error otherwise.

func (*MCPClient) WithKB

func (c *MCPClient) WithKB(name string) *MCPClient

WithKB returns a copy of the client scoped to the given KB name (multi-KB server: appends ?kb=<name> to the request URL, see MultiKBServer.Handler in httpserver.go). An empty name targets the server's default single-KB endpoint.

Jump to

Keyboard shortcuts

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