mcpprobe

package
v0.29.2 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 16 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 mcpprobe checks an MCP descriptor without launching it: which ${VAR} references are unset, whether its host can be reached, and which of the usual network and TLS faults an error is. It prints and writes nothing; the command in cmd/cartographer shows the Result. A value is never part of it.

Index

Constants

View Source
const (
	ExitOK         = 0
	ExitNotUsable  = 1
	ExitUsage      = 2
	ExitUnresolved = 3
	ExitNetwork    = 4
	ExitTLS        = 5
)

Exit codes of `cartographer mcp probe`, documented in its help and in docs/configurator.md and docs/mcp-clients.md. 2 (usage, not found, not approved) is decided before a Result exists.

View Source
const DialTimeout = 15 * time.Second

DialTimeout is how long Dial waits for DNS, TCP and TLS together: the same 15 s as gitx.FetchTimeout (internal/gitx/gitx.go), so a network that drops packets is reported as a timeout instead of hanging the command.

View Source
const MaxToolNames = 10

MaxToolNames is how many tool names a report lists.

View Source
const MinScrubLen = 4

MinScrubLen is the shortest value that is replaced inside a text. A shorter one ("1", "ab") would match unrelated characters and leave the text unreadable or, worse, half-scrubbed, so a text that contains one is masked whole instead.

View Source
const ReachTimeout = 2 * time.Second

ReachTimeout is the total bound of the quick check doctor and status make for the descriptors that declare a network: all dials run in parallel, so a network that is down costs this once, never 15 s per descriptor.

View Source
const SessionTimeout = 20 * time.Second

SessionTimeout bounds initialize plus tools/list when the caller gives none.

Variables

View Source
var ErrRedirectHost = errors.New("redirect to another host refused")

ErrRedirectHost is the refusal of a redirect to another host. It is a typed error so no text match can mistake it, or a server's "refused", for a connection that nothing answered.

Functions

func Blocked

func Blocked(err error) bool

Blocked reports whether err means the host did not answer: DNS, refused or a silent drop. It is the case a `requires` label words as "needs <network>"; a TLS fault is the server's, not the network's.

func BlockedAll

func BlockedAll(ctx context.Context, urls []string, timeout time.Duration, dial func(context.Context, string, time.Duration) error) []bool

BlockedAll dials every URL in parallel within timeout (0 means ReachTimeout) and reports for each whether the host did not answer. dial is Dial in production.

func Dial

func Dial(ctx context.Context, rawURL string, timeout time.Duration) error

Dial resolves the host of rawURL, opens a TCP connection and, for https, runs the TLS handshake, then closes it. It sends no MCP bytes. timeout 0 means DialTimeout. The system proxy is not used: the probe answers whether this machine reaches the host itself.

func ExitCode

func ExitCode(r Result) int

ExitCode maps r to an exit code, the first fault in the order the probe finds them: variables (nothing was launched), then network, then TLS, then session.

func Hint

func Hint(k Kind) string

Hint is one sentence on what to do about k, empty when there is nothing to add.

func NewScrub

func NewScrub(values []string) func(string) string

NewScrub returns a function that removes every value from a text: values of MinScrubLen or more are replaced where they occur (longest first, so a value that contains another is not left in pieces); a shorter one makes the whole text "<redacted>". Empty values are ignored.

func Unresolved

func Unresolved(refs []string, lookup func(string) (string, bool)) []string

Unresolved returns the names in refs that lookup reports unset or empty, in the order given. lookup is os.LookupEnv for the real command.

This is the environment of the process that runs the probe. A client started from the dock or from an older shell may have another one, which is the fault the probe exists to explain: the report says so.

Types

type Info

type Info struct {
	Protocol string
	Server   string
	Version  string
	Tools    []string // every tool name, in the server's order
}

Info is what a working session answered.

func Run

func Run(ctx context.Context, t Target, timeout time.Duration, scrub func(string) string) (Info, error)

Run opens one MCP session with t, lists the tools and closes it, within timeout (0 means SessionTimeout). Every error text goes through scrub, which removes the resolved values; a stdio child that fails carries the last lines of its stderr, scrubbed too.

type Kind

type Kind string

Kind classifies a network error. The empty Kind means no error.

const (
	KindDNS                 Kind = "dns"
	KindRefused             Kind = "refused"
	KindTimeout             Kind = "timeout"
	KindTLSUnknownAuthority Kind = "tls_unknown_authority"
	KindTLSOther            Kind = "tls_other"
	KindOther               Kind = "other"
)

func Classify

func Classify(err error) Kind

Classify says which fault err is. TLS comes before the timeout test because a handshake that fails is not a slow network, and DNS before it because a resolver that does not answer is a name problem to the person reading.

func SessionKind

func SessionKind(err error) Kind

SessionKind is Classify for a session error.

type Result

type Result struct {
	Target    string `json:"target"`    // the approved endpoint or command
	Transport string `json:"transport"` // "http" or "stdio"
	// Unresolved are the ${VAR} names unset or empty in the probing shell.
	Unresolved []string `json:"unresolved,omitempty"`
	Net        Kind     `json:"net,omitempty"`
	Detail     string   `json:"detail,omitempty"`
	Hint       string   `json:"hint,omitempty"`
	// Error is a failure of the MCP session itself (initialize or tools/list):
	// the server answered but is not usable.
	Error string `json:"error,omitempty"`
	Tools int    `json:"tools"`
	// Protocol, Server and ToolNames come from a session that worked; ToolNames
	// lists at most MaxToolNames. Via says how the descriptor was started.
	Protocol  string   `json:"protocol,omitempty"`
	Server    string   `json:"server,omitempty"`
	ToolNames []string `json:"tool_names,omitempty"`
	Via       string   `json:"via,omitempty"`
	// Needs is the descriptor's `requires` label, set when the host did not
	// answer (dns, refused, timeout): the report then reads "needs <label>".
	Needs string `json:"needs,omitempty"`
}

Result is what one probe found. It holds names and classes, never a value.

type Target

type Target struct {
	// Command, Args and Env start a stdio server (Env is the whole environment).
	Command string
	Args    []string
	Env     []string
	// URL and Headers reach an http server.
	URL     string
	Headers map[string]string
}

Target is a launch ready to talk to: what mcpexec.Resolve produced, copied to plain fields so this package keeps no import of the launcher. It holds the resolved values; nothing here prints or stores one.

Jump to

Keyboard shortcuts

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