server

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package server provides MCP transport serving (stdio/http/both) and the Transport type shared across acidsailor MCP servers.

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

func Handler added in v0.2.0

func Handler(m *mcp.Server) http.Handler

Handler returns the SDK streamable HTTP handler for m (stateless, JSON mode) — set it as the Handler of an *http.Server for WithHTTPServer, optionally wrapped with middleware or mounted in a mux.

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 *http.Server for the HTTP and Both transports, served as-is (Handler, Addr, timeouts, TLSConfig, … unchanged). Set its Handler yourself — typically Handler(mcpServer), optionally wrapped or mounted in a mux. A non-nil TLSConfig serves HTTPS and must carry its own certificates. Required for HTTP and Both (else ErrNoHTTPServer); a nil Handler is rejected at serve time with ErrNilHandler.

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 // escape hatch to the underlying 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. Defaults: Stdio transport, 30s graceful-shutdown timeout. The HTTP and Both transports require WithHTTPServer.

func (*Server) ListenAndServe

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

ListenAndServe validates config, serves on the configured transport(s), blocks until ctx is cancelled, then runs graceful shutdown.

type Transport

type Transport string

Transport selects the MCP transport mechanism.

const (
	Stdio Transport = "stdio" // stdin/stdout
	HTTP  Transport = "http"  // streamable HTTP
	Both  Transport = "both"  // stdio + HTTP concurrently
)

Supported transports.

func ParseTransport

func ParseTransport(s string) (Transport, error)

ParseTransport parses s into a Transport, wrapping ErrInvalidTransport for an unsupported value.

func (*Transport) UnmarshalText

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

UnmarshalText lets text-based 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