Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package server serves an mcp.Server over stdio, HTTP, or both.

HTTP transports require a caller-configured *http.Server. Its handler, address, timeouts, TLS settings, and hooks are used unchanged. A non-nil TLSConfig selects HTTPS. WithShutdownTimeout controls graceful shutdown.

A stateless streamable HTTP handler supports protocol 2026-07-28 and current elicitation. Older clients need stdio or a stateful handler for gated writes. Stateful multi-replica deployments need session affinity.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilServer        = errors.New("nil mcp server")
	ErrInvalidTransport = errors.New("invalid transport")
	ErrInvalidAddr      = errors.New("invalid server address")
	ErrServe            = errors.New("serve")
	ErrShutdown         = errors.New("shutdown")
	ErrNilHandler       = errors.New("nil http handler")
	ErrNoHTTPServer     = errors.New("no http server")
)

Sentinels for server failures, wrapped with detail at the entry point.

Functions

This section is empty.

Types

type Option

type Option func(*Server)

Option configures a Server.

func WithHTTPServer added in v0.2.0

func WithHTTPServer(srv *http.Server) Option

WithHTTPServer sets the caller-owned *http.Server for HTTP and Both.

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Option

WithShutdownTimeout sets the HTTP graceful-shutdown timeout (default 30s).

func WithTransport

func WithTransport(t Transport) Option

WithTransport sets the transport (default Stdio).

type Server

type Server struct {
	MCP *mcp.Server // Underlying MCP server.
	// contains filtered or unexported fields
}

Server serves an mcp.Server over the configured transport(s).

func New

func New(mcpServer *mcp.Server, opts ...Option) *Server

New builds a Server wrapping mcpServer (default: Stdio, 30s shutdown).

func (*Server) ListenAndServe

func (s *Server) ListenAndServe(ctx context.Context) error

ListenAndServe validates, serves on the transport(s), and shuts down on ctx.

type Transport

type Transport string

Transport selects the MCP transport mechanism.

const (
	Stdio Transport = "stdio" // Stdio uses standard input and output.
	HTTP  Transport = "http"  // HTTP uses streamable HTTP.
	Both  Transport = "both"  // Both runs Stdio and HTTP concurrently.
)

Supported transport values.

func ParseTransport

func ParseTransport(s string) (Transport, error)

ParseTransport parses s, wrapping ErrInvalidTransport for a bad value.

func (*Transport) UnmarshalText

func (t *Transport) UnmarshalText(b []byte) error

UnmarshalText lets text config loaders (env, flag, json) parse a Transport.

Jump to

Keyboard shortcuts

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