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 ¶
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
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 (*MCPClient) Call ¶
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
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 ¶
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.