mcp

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 21 Imported by: ? 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 mcp adapts explicitly reviewed MCP tools to the local agent runtime. It uses the official SDK over explicit HTTP or caller-supplied streams and does not discover credentials, launch processes, or grant permissions from server metadata.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConfig      = errors.New("mcp: invalid client configuration")
	ErrConnect     = errors.New("mcp: connection failed")
	ErrProtocol    = errors.New("mcp: incompatible protocol or server capabilities")
	ErrClosed      = errors.New("mcp: client closed")
	ErrRemote      = errors.New("mcp: remote tool failed")
	ErrUnsupported = errors.New("mcp: unsupported tool result")
	ErrLimit       = errors.New("mcp: tool result exceeds limit")
)
View Source
var ErrDiscovery = errors.New("mcp: discovery failed")

Functions

This section is empty.

Types

type Binding

type Binding struct {
	RemoteName string
	Spec       agent.ToolSpec
}

Binding is a caller-reviewed tool specification and the exact remote name. Server annotations and discovered schemas do not confer permission.

type Catalog

type Catalog struct {
	Tools    []ToolInfo `json:"tools"`
	Pages    int        `json:"pages"`
	Complete bool       `json:"complete"`
}

Catalog contains only metadata from SDK-returned pages. Complete means pagination ended within the configured budgets, not that the server disclosed every tool (the SDK may filter invalid definitions).

func DiscoverHTTP

func DiscoverHTTP(ctx context.Context, h HTTPConfig, cfg DiscoveryConfig) (Catalog, error)

DiscoverHTTP opens and closes a fresh discovery-only HTTP connection. Use the same endpoint trust policy as ConnectHTTP. No executable client or remotely supplied schema is returned. Never register tools from this data.

func DiscoverIO

func DiscoverIO(ctx context.Context, stream io.ReadWriteCloser, cfg DiscoveryConfig) (Catalog, error)

DiscoverIO uses a separate, already-open duplex stream. Configuration failure leaves ownership with the caller; once discovery begins the stream is owned and closed by this function, including on failure.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client owns the initialized SDK connection and its approved tool set. Close it after all runs finish. Tools must not be used after Close.

func ConnectHTTP

func ConnectHTTP(ctx context.Context, h HTTPConfig, cfg Config) (*Client, error)

ConnectHTTP uses the official SDK's Streamable HTTP request/response subset. Responses must terminate within the request deadline and fit in maxFrame. No standalone SSE, redirect, OAuth discovery, proxy or automatic reconnect. The caller chooses the trusted endpoint; this is not SSRF or remote isolation.

func ConnectIO

func ConnectIO(ctx context.Context, stream io.ReadWriteCloser, cfg Config) (*Client, error)

ConnectIO connects through an already-open, trusted duplex stream. The caller retains ownership on configuration failure. Once the SDK connection attempt begins, this function owns the stream, including on failure. Closing the stream must unblock reads and writes. Context limits are cooperative; the transport is not a sandbox for remote effects.

func (*Client) Close

func (c *Client) Close() error

func (*Client) Tools

func (c *Client) Tools() []agent.Tool

Tools returns a separate slice of the fixed, approved bindings.

type Config

type Config struct {
	// ProtocolVersion must be 2025-11-25 or 2026-07-28. A different
	// negotiated version is rejected.
	ProtocolVersion string
	Bindings        []Binding
	// Zero selects the defaults (15 seconds for connect, 30 for each call).
	// Positive values must not exceed two minutes.
	ConnectTimeout time.Duration
	CallTimeout    time.Duration
}

type DiscoveryConfig

type DiscoveryConfig struct {
	ProtocolVersion string
	Timeout         time.Duration
	MaxPages        int
	MaxTools        int
}

DiscoveryConfig is independent of execution Config. Zero values select 15 seconds, four pages, and 64 tools; ProtocolVersion is required.

type HTTPConfig

type HTTPConfig struct {
	Endpoint    string
	BearerToken string
	// RootCAs optionally replaces the system trust roots with a copied pool.
	// Certificate and hostname verification are always enabled.
	RootCAs *x509.CertPool
}

HTTPConfig specifies a caller-trusted MCP endpoint and optional credentials. HTTPS is required except for unauthenticated literal loopback HTTP.

type TextResult

type TextResult struct {
	Text []string `json:"text"`
}

TextResult retains individual textual blocks in order. Remote metadata and annotations are not included. Text may contain sensitive or untrusted data.

type ToolInfo

type ToolInfo struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
}

ToolInfo is untrusted display metadata, never a reviewed executable binding.

Jump to

Keyboard shortcuts

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