transport

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package transport defines the Transport interface used by the orchestrator and provides stdio and HTTP/SSE implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTP

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

HTTP is an HTTP/SSE-based JSON-RPC transport.

func NewHTTP

func NewHTTP(cfg HTTPConfig) (*HTTP, error)

NewHTTP constructs a new HTTP transport.

func (*HTTP) Call

func (h *HTTP) Call(ctx context.Context, method string, params any) ([]byte, error)

Call issues a JSON-RPC call over HTTP. When the server returns text/event-stream and AllowSSE is set, frames are collated.

func (*HTTP) Close

func (h *HTTP) Close() error

Close releases underlying HTTP connections.

type HTTPConfig

type HTTPConfig struct {
	URL     string
	Headers map[string]string
	// Client overrides the default http.Client. Optional.
	Client *http.Client
	// AllowSSE enables parsing of text/event-stream responses. When the
	// server sends SSE, the transport collates all `data:` events into a
	// single JSON-RPC response (the last well-formed frame wins).
	AllowSSE bool
}

HTTPConfig configures the HTTP/SSE transport.

type Kind

type Kind string

Kind enumerates the transport varieties mcpbench can open.

const (
	KindStdio Kind = "stdio"
	KindHTTP  Kind = "http"
	KindSSE   Kind = "sse"
)

Known transport kinds.

func ParseKind

func ParseKind(s string) (Kind, error)

ParseKind normalizes a string into a Kind, returning an error on unknowns.

type Stdio

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

Stdio is a subprocess-backed JSON-RPC transport speaking newline-delimited frames.

func StartStdio

func StartStdio(ctx context.Context, cfg StdioConfig) (*Stdio, error)

StartStdio launches the subprocess and returns a ready Stdio transport.

func (*Stdio) Call

func (s *Stdio) Call(ctx context.Context, method string, params any) ([]byte, error)

Call issues a JSON-RPC call over stdio.

func (*Stdio) Close

func (s *Stdio) Close() error

Close cleanly terminates the subprocess.

func (*Stdio) ReadError

func (s *Stdio) ReadError() error

ReadError returns the error that caused the reader goroutine to exit, if any. Useful for diagnostics in tests. Safe for concurrent use.

type StdioConfig

type StdioConfig struct {
	// Cmd is the binary to execute.
	Cmd string
	// Args are the arguments passed to the subprocess.
	Args []string
	// Env holds additional environment variables (merged with os.Environ).
	Env map[string]string
	// Silent, when true, discards the subprocess stderr instead of forwarding.
	Silent bool
	// ShutdownGrace is the time allowed between SIGTERM and SIGKILL during
	// Close. Defaults to 5 seconds when zero.
	ShutdownGrace time.Duration
	// MaxLineBytes overrides the bufio.Scanner buffer size. Defaults to 16
	// MiB. Oversized responses are reported as transport errors.
	MaxLineBytes int
}

StdioConfig holds subprocess launch parameters.

type Transport

type Transport interface {
	// Call issues a single JSON-RPC request and returns the raw response
	// bytes. Timeouts and cancellation are honored via ctx.
	Call(ctx context.Context, method string, params any) (json []byte, err error)

	// Close releases resources (kills subprocess, closes HTTP connections).
	Close() error
}

Transport is the wire-level abstraction for an MCP server connection. Implementations must be safe for concurrent Call invocation.

Directories

Path Synopsis
Command testmock is a tiny JSON-RPC stdio server used by transport tests.
Command testmock is a tiny JSON-RPC stdio server used by transport tests.

Jump to

Keyboard shortcuts

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