connection

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 12 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 connection resolves MCP protocol versions and opens client sessions to MCP servers over stdio or streamable HTTP.

Index

Constants

View Source
const DraftAlias = "draft"

DraftAlias selects the newest protocol version the linked SDK supports.

Variables

View Source
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

func Open(ctx context.Context, o *Options) (*mcp.ClientSession, error)

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

func ResolveVersion(v string) (string, error)

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.

func (*Options) Validate

func (o *Options) Validate() error

Validate checks that exactly one transport target is set and that OAuth is not combined with stdio.

Jump to

Keyboard shortcuts

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