mcp

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ProtocolModeLegacy uses the stateful initialize/session protocol.
	ProtocolModeLegacy ProtocolMode = "legacy"
	// ProtocolModeModern uses the stateless per-request metadata protocol.
	ProtocolModeModern ProtocolMode = "modern"

	ProtocolVersionLegacy = "2025-11-25"
	ProtocolVersionModern = "2026-07-28"

	// ProtocolVersion is retained for source compatibility and names the
	// default protocol used by existing constructors.
	ProtocolVersion = ProtocolVersionLegacy
)

Variables

This section is empty.

Functions

func AddModernRequestMetadata added in v0.4.4

func AddModernRequestMetadata(params json.RawMessage, options ClientOptions) (json.RawMessage, error)

AddModernRequestMetadata merges the metadata required by the stateless MCP protocol into an object-shaped params payload.

func ProtocolVersionForMode added in v0.4.4

func ProtocolVersionForMode(mode ProtocolMode) (string, error)

ProtocolVersionForMode returns the wire revision for an explicit mode.

Types

type CallToolRequest

type CallToolRequest struct {
	Name      string          `json:"name"`
	Arguments json.RawMessage `json:"arguments,omitempty"`
}

type CallToolResult

type CallToolResult struct {
	Content           []Content       `json:"content,omitempty"`
	StructuredContent json.RawMessage `json:"structuredContent,omitempty"`
	IsError           bool            `json:"isError,omitempty"`
}

type Client

type Client interface {
	ListTools(ctx context.Context) ([]Tool, error)
	CallTool(ctx context.Context, req CallToolRequest) (CallToolResult, error)
}

type ClientOptions added in v0.4.4

type ClientOptions struct {
	Mode               ProtocolMode
	ClientInfo         Implementation
	ClientCapabilities map[string]any
}

ClientOptions configures the MCP protocol era and modern request metadata. The zero value selects legacy mode.

func NormalizeClientOptions added in v0.4.4

func NormalizeClientOptions(options ClientOptions, defaultVersion string) (ClientOptions, error)

NormalizeClientOptions validates options and fills deterministic defaults.

type Content

type Content struct {
	Type string          `json:"type"`
	Text string          `json:"text,omitempty"`
	Data json.RawMessage `json:"data,omitempty"`
	Mime string          `json:"mimeType,omitempty"`
}

type Implementation added in v0.4.4

type Implementation struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Implementation identifies an MCP implementation on the wire.

type ListToolsResult added in v0.4.2

type ListToolsResult struct {
	Tools      []Tool `json:"tools"`
	NextCursor string `json:"nextCursor,omitempty"`
	TTLMs      *int64 `json:"ttlMs,omitempty"`
	CacheScope string `json:"cacheScope,omitempty"`
}

ListToolsResult is the MCP tools/list response shape. TTLMs and CacheScope are optional forward-compatible cache hints for newer protocol revisions.

type ProtocolMode added in v0.4.4

type ProtocolMode string

ProtocolMode selects one MCP protocol era explicitly. Clients never auto-negotiate or fall back between eras: a deployment must choose the mode implemented by its server.

type SessionClient added in v0.3.1

type SessionClient interface {
	Client
	// SessionID returns the session id assigned during initialize (empty when
	// the server is stateless or the handshake has not completed).
	SessionID() string
	// Terminate ends the server-side session and resets local handshake
	// state; the next call re-initializes. No-op without an active session.
	Terminate(ctx context.Context) error
}

SessionClient is an optional capability for clients that hold a server-side MCP session. Callers that manage long-lived clients should terminate the session instead of dropping the client silently, so servers can reclaim session state immediately instead of waiting for their idle TTL.

type Tool

type Tool struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	InputSchema json.RawMessage `json:"inputSchema,omitempty"`
}

Jump to

Keyboard shortcuts

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