stdio

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package stdio implements a minimal single-connection MCP transport over stdin/stdout. It is intended for embedding servers as subprocesses, local development, and environments where spawning a child process and piping JSON is simpler than running an HTTP server.

Characteristics

Connection model : 1 process <-> 1 client
Auth             : OS user (lightweight implicit principal)
Sessions         : Ephemeral; no host abstraction (memory only)
Transport        : Line / stream oriented JSON-RPC

Options allow supplying alternate io.Reader / io.Writer or a custom logger.

Example:

srv := mcpservice.NewServer(
    mcpservice.WithServerInfo(mcp.ImplementationInfo{Name: "my-stdio-server", Version: "0.1.0"}),
    // mcpservice.WithToolsCapability(...), etc.
)
h := stdio.NewHandler(srv)
if err := h.Serve(context.Background()); err != nil { log.Fatal(err) }

For multi-session, horizontally scalable deployments prefer the streaming HTTP transport which integrates with session hosts, authentication and subscription fan-out.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

func NewHandler

func NewHandler(srv mcpservice.ServerCapabilities, opts ...Option) *Handler

func (*Handler) Serve

func (h *Handler) Serve(ctx context.Context) error

type Option

type Option func(*Handler)

Option customizes a Handler.

func WithIO

func WithIO(r io.Reader, w io.Writer) Option

WithIO sets the reader and writer for the handler.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger overrides the logger.

func WithReader

func WithReader(r io.Reader) Option

WithReader overrides the input stream.

func WithWriter

func WithWriter(w io.Writer) Option

WithWriter overrides the output stream.

Jump to

Keyboard shortcuts

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