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
- Variables
- func Blocked(err error) bool
- func BlockedAll(ctx context.Context, urls []string, timeout time.Duration, ...) []bool
- func Dial(ctx context.Context, rawURL string, timeout time.Duration) error
- func ExitCode(r Result) int
- func Hint(k Kind) string
- func NewScrub(values []string) func(string) string
- func Unresolved(refs []string, lookup func(string) (string, bool)) []string
- type Info
- type Kind
- type Result
- type Target
Constants ¶
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.
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.
const MaxToolNames = 10
MaxToolNames is how many tool names a report lists.
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.
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.
const SessionTimeout = 20 * time.Second
SessionTimeout bounds initialize plus tools/list when the caller gives none.
Variables ¶
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 ¶
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 ¶
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 ¶
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 NewScrub ¶
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 ¶
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.
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.