Documentation
¶
Overview ¶
Package connection resolves MCP protocol versions and opens client sessions to MCP servers over stdio or streamable HTTP.
Index ¶
Constants ¶
const DraftAlias = "draft"
DraftAlias selects the newest protocol version the linked SDK supports.
Variables ¶
var KnownVersions = [...]string{"2024-11-05", "2025-03-26", "2025-06-18", "2025-11-25", "2026-07-28"}
KnownVersions lists the MCP protocol version dates this CLI can name, oldest first. It mirrors the versions spoken by go-sdk v1.8.0 (mcp.SupportedProtocolVersions()).
Functions ¶
func Open ¶
Open validates opts, assembles the transport (stdio command or streamable HTTP), and connects an mcp client, returning the initialized session. When the resolved protocol version is non-empty it is pinned via mcp.ClientSessionOptions.ProtocolVersion. A failed stdio connect is enriched with the subprocess's captured stderr.
func ResolveVersion ¶
ResolveVersion maps a --protocol value to the protocol version to pin, or "" for the SDK's default negotiation:
"auto" -> "" (let the SDK negotiate) "draft" -> lexicographically greatest of mcp.SupportedProtocolVersions() a known date -> itself anything else -> error
A known date resolves to itself even when the linked SDK cannot speak it (KnownVersions may lead the SDK after an upgrade, or trail it): validation passes, the pin is attempted at Connect time, and the SDK rejects values it does not support there. Compat (task 8) relies on that distinction to probe what a server actually accepts.
Types ¶
type Options ¶
type Options struct {
Command string // shell-like argv string to launch over stdio
URL string // streamable HTTP endpoint of the MCP server
Auth string // auth mode: none, bearer, client-credentials, oauth
ProtocolVersion string // auto, draft, or a date; see ResolveVersion
// AuthHandler authorizes streamable HTTP requests. The cli layer builds
// it from internal/auth; stdio connections reject it because a spawned
// subprocess has no HTTP surface to authorize.
AuthHandler sdkauth.OAuthHandler
// Env, when non-empty, is injected into a stdio child's environment:
// os.Environ() as the base with these pairs appended — os/exec's
// dedupEnv keeps the LAST occurrence of a KEY, so an injected KEY
// overrides the inherited one. HTTP transports ignore it.
Env map[string]string
// Tracer, when non-nil, collects per-call round-trip timing for the run:
// Open registers its middleware on the client before Connect and starts
// one labeled section (Label, or "connect" when empty) — compat's
// per-version probes pass their own labels. Nil means tracing is off and
// adds nothing.
Tracer *trace.Tracer
Label string
}
Options describes how to reach an MCP server: either a stdio command or a streamable HTTP endpoint, plus protocol version pinning and auth.