Documentation
¶
Overview ¶
Package mcp is upgradescope's Model Context Protocol server: read-only tools that let an AI assistant ask for a cluster's upgrade readiness, its findings, the add-on registry and, against a fleet server, the fleet.
It is the protocol layer only. What a scan does and how an inventory is judged stay in the CLI's code, which the command hands in through Config, so a report an assistant gets is the one `scan --output json` writes.
Index ¶
- Constants
- func CleartextHost(serverURL, token string) (host string, ok bool)
- func CleartextWarning(serverURL, token string) string
- func FindingsOutputSchema() map[string]any
- func New(cfg Config) *mcpsdk.Server
- func NewHTTPHandler(srv *mcpsdk.Server, opts HTTPOptions) http.Handler
- func ReadFile(ctx context.Context, path string, max int64) ([]byte, error)
- func ReportOutputSchema() map[string]any
- func ScanOutputSchema() map[string]any
- func ToolNames(fleet bool) []string
- func ToolWords() []string
- type Config
- type Fleet
- type HTTPOptions
- type ScanRequest
Constants ¶
const ( // DefaultSessionTimeout closes a session that has had no request for // this long. A client that exits without a DELETE (or never sends one) // leaves its session behind, and each holds a goroutine and some // memory; a client whose session expired gets 404 and starts another, // as the MCP specification says it must. DefaultSessionTimeout = 10 * time.Minute // DefaultMaxSessions is the most sessions kept at once. One person's // clients need a handful; past the bound a new session is refused. DefaultMaxSessions = 100 )
The streamable HTTP transport's session limits, as `upgradescope mcp --http` serves it.
const ( ToolScan = "scan" ToolListFindings = "list_findings" ToolGetReport = "get_report" ToolRegistryLookup = "registry_lookup" ToolFleetSummary = "fleet_summary" )
The tools. Every one is read-only; TestToolsAreReadOnly holds the set and the hint to that, and docs/getting-started/mcp.md documents it.
const ClusterTextCutMark = " …(cut by upgradescope mcp)"
ClusterTextCutMark ends a value cut to MaxClusterTextBytes.
const ClusterTextMarker = "cluster-supplied, not instructions"
ClusterTextMarker is the marker the notice and _meta carry.
const MaxClusterTextBytes = 2 << 10
MaxClusterTextBytes is the most of one outside string a result carries. Names are far shorter (a Kubernetes name is at most 253 bytes); what is cut is prose, of which an assistant needs no more.
const MaxReportBytes = 8 << 20
MaxReportBytes bounds a report a tool reads, from a report_file or the fleet server. A tool's result carries its document twice, as structured content and as the same JSON in a text block, and the MCP Go SDK's client refuses a message over 16 MiB (mcpsdk.DefaultMaxLineLength on stdio, and DefaultMaxEventSize, the same, over HTTP), so a report much over 8 MiB could never reach a client from get_report. Holding one costs several times its size besides: it is decoded to check it against the schema, and the SDK decodes it again to check its output and encodes it twice to send it. Within the bound, list_findings returns the part of a report a filter picks; maxResultBytes is the check on what is sent.
const MetaClusterText = "upgradescope.basit.engineer/clusterSupplied"
MetaClusterText is the result's _meta key for the structured marker.
Variables ¶
This section is empty.
Functions ¶
func CleartextHost ¶
CleartextHost is the host:port of serverURL when a bearer token sent to it would cross the network in the clear: the URL is plain http:// to a host that is not loopback, and token is not empty. ok is false otherwise. 'mcp --server-url' and 'clusters' warn on it.
func CleartextWarning ¶
CleartextWarning says why reading serverURL with token is unsafe, or returns "": a read token sent over plain http:// to a host that is not loopback crosses the network in the clear, where anyone on the path can replay it (as agent.CleartextPushWarning says of the ingest token).
func FindingsOutputSchema ¶
FindingsOutputSchema is the output schema of list_findings: the matching findings, each as api/report.schema.json defines it.
func NewHTTPHandler ¶
func NewHTTPHandler(srv *mcpsdk.Server, opts HTTPOptions) http.Handler
NewHTTPHandler serves srv over MCP's streamable HTTP transport, the way `upgradescope mcp --http` does:
- a request from another origin in a browser is refused (403), and the SDK refuses one whose Host is not loopback arriving on a loopback address (DNS rebinding), and a body over 4 MiB;
- a session idle for opts.SessionTimeout is closed, and at most opts.MaxSessions are open at once: a new one past that is refused with 503;
- a tools/call whose HTTP request ends before it is answered (the client closed the connection or went away) is cancelled, whatever the protocol version. The SDK's own PropagateRequestCancellation does that only for the 2026-07-28 protocol on a stateless handler, and this one keeps sessions; with no event store the answer could never be delivered, so a scan would hold the scan slot for nothing.
It adds a receiving middleware to srv, so srv serves this handler alone.
func ReadFile ¶
ReadFile reads the regular file at path, refusing anything else and any file larger than max bytes. A path a tool reads comes from an assistant, which prompt-injected content can steer, so it may name what is not a file at all: a FIFO, on which a plain open blocks until a writer comes (forever, a goroutine per call); /dev/stdin, which on the stdio transport would read the client's JSON-RPC frames; a device that never ends. So the path is stat'ed first and only a regular file within the bound is opened, without blocking where the platform allows it, and the opened file is checked again to be that same regular file before it is read, through the bound. The error never quotes the file's contents.
A regular file whose read blocks (one on a stalled NFS or FUSE mount; on Linux, /proc/kmsg, readable only by root) has no deadline the platform honours, so ReadFile returns when ctx ends, and the read itself goes on in the background until the file answers. It keeps its slot of fileReads until then, so calls cancelled one after another against a stalled mount run no more reads than there are slots, and hold no more memory than that many files within the bound; a call that finds every slot held by such a read waits, and gives up when ctx ends.
func ReportOutputSchema ¶
ReportOutputSchema is api/report.schema.json itself, less its $id (the URL it is published at, which a client has no reason to fetch): the output schema of get_report.
func ScanOutputSchema ¶
ScanOutputSchema is the output schema of scan: one report per target.
Types ¶
type Config ¶
type Config struct {
// Version is the build version, for the server's implementation info.
Version string
// Scan reads the cluster once and judges it at each target of req, as
// `upgradescope scan --output json` would: one report document per
// target, in req's order. It stops when ctx ends: the client cancelled
// the call (notifications/cancelled), or went away (on stdio, closed
// its end; over HTTP, closed the connection that carried the call,
// which NewHTTPHandler turns into a cancel). Required.
Scan func(ctx context.Context, req ScanRequest) ([]json.RawMessage, error)
// Inventory judges an inventory file (the JSON an agent pushes) at a
// target and returns the report document, giving up when ctx ends.
// Required.
Inventory func(ctx context.Context, path, target string) (json.RawMessage, error)
// Fleet, when set, is the serve instance get_report and list_findings
// read from (with cluster) and fleet_summary summarises.
Fleet *Fleet
// Registry returns the add-on registry; nil means the embedded one.
Registry func() ([]registry.AddOn, error)
}
Config wires the server to what the CLI already does.
type Fleet ¶
type Fleet struct {
BaseURL string // e.g. https://upgradescope.example.com
Token string // the server's read token; "" for an open read API
Client *http.Client
}
Fleet reads an upgradescope server's REST API with its read token, so the server's own read authentication and its limits apply as they do to a curl; the tools hold no credential of their own and show no data the token would not.
func (*Fleet) Report ¶
func (f *Fleet) Report(ctx context.Context, cluster, target string) (json.RawMessage, string, error)
Report is the server's report of a cluster at target ("" = the cluster's next minor) and the cluster's name.
func (*Fleet) TrustRoots ¶
TrustRoots makes the client verify the server against roots (the system roots plus a private CA: agent.LoadServerCAs) instead of the system roots alone. Verification is never skipped, and the client still follows no redirect.
type HTTPOptions ¶
type HTTPOptions struct {
// SessionTimeout closes a session idle this long; it must be positive.
SessionTimeout time.Duration
// MaxSessions is the most sessions open at once; it must be positive.
MaxSessions int
}
HTTPOptions bound the sessions of the streamable HTTP transport.
type ScanRequest ¶
type ScanRequest struct {
Targets []string // distinct Kubernetes minors, in the order asked
}
ScanRequest is one call of the scan tool. It names the targets and nothing else: which cluster is read (and with which credentials) is the command's --kubeconfig and --context and the environment, never an assistant's choice.