http

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package http provides a Streamable HTTP implementation of the MCP transport.

This package implements the Transport interface using Streamable HTTP, following the MCP 2025-03-26 specification. It supports streaming HTTP responses, session management, OAuth authentication, and proper content negotiation.

Index

Constants

View Source
const DefaultMCPEndpoint = "/mcp"

DefaultMCPEndpoint is the default MCP endpoint path

View Source
const DefaultShutdownTimeout = 10 * time.Second

DefaultShutdownTimeout is the default timeout for graceful shutdown

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPHeaderFunc added in v1.6.0

type HTTPHeaderFunc func() map[string]string

HTTPHeaderFunc is a function type for generating dynamic headers

type Option added in v1.6.0

type Option func(*Transport)

Option is a function that configures a Transport

func WithHTTPClient added in v1.6.0

func WithHTTPClient(client *http.Client) Option

WithHTTPClient returns an option that sets a custom HTTP client

func WithHeaders added in v1.6.0

func WithHeaders(headers map[string]string) Option

WithHeaders returns an option that sets additional HTTP headers

func WithMCPEndpoint added in v1.6.0

func WithMCPEndpoint(path string) Option

WithMCPEndpoint returns an option that sets the MCP endpoint path

func WithPathPrefix added in v1.6.0

func WithPathPrefix(prefix string) Option

WithPathPrefix returns an option that sets the path prefix for all endpoints

func WithTimeout added in v1.6.0

func WithTimeout(timeout time.Duration) Option

WithTimeout returns an option that sets the HTTP timeout

type SessionInfo added in v1.6.0

type SessionInfo struct {
	ID        string
	CreatedAt time.Time
	LastSeen  time.Time
	ClientID  string
}

SessionInfo holds information about an active session

type Transport

type Transport struct {
	transport.BaseTransport
	// contains filtered or unexported fields
}

Transport implements the transport.Transport interface for Streamable HTTP

func NewClientTransport added in v1.6.0

func NewClientTransport(url string, options ...Option) *Transport

NewClientTransport creates a new Streamable HTTP transport configured for client mode

func NewServerTransport added in v1.6.0

func NewServerTransport(addr string, options ...Option) *Transport

NewServerTransport creates a new Streamable HTTP transport configured for server mode

func NewTransport

func NewTransport(addr string, options ...Option) *Transport

NewTransport creates a new Streamable HTTP transport

func (*Transport) GetAddr added in v1.2.2

func (t *Transport) GetAddr() string

GetAddr returns the transport's address

func (*Transport) GetFullAPIPath added in v1.2.1

func (t *Transport) GetFullAPIPath() string

GetFullAPIPath returns the complete path for the MCP endpoint (compatibility alias)

func (*Transport) GetFullMCPEndpoint added in v1.6.0

func (t *Transport) GetFullMCPEndpoint() string

GetFullMCPEndpoint returns the complete path for the MCP endpoint

func (*Transport) Initialize

func (t *Transport) Initialize() error

Initialize initializes the transport

func (*Transport) Receive

func (t *Transport) Receive() ([]byte, error)

Receive receives a message (not applicable for HTTP client)

func (*Transport) Send

func (t *Transport) Send(message []byte) error

Send sends a JSON-RPC message

func (*Transport) SetAPIPath added in v1.2.1

func (t *Transport) SetAPIPath(path string) *Transport

SetAPIPath sets the path for the MCP endpoint (compatibility alias)

func (*Transport) SetClientMode added in v1.6.0

func (t *Transport) SetClientMode(isClient bool) *Transport

SetClientMode sets the transport to client mode

func (*Transport) SetMCPEndpoint added in v1.6.0

func (t *Transport) SetMCPEndpoint(path string) *Transport

SetMCPEndpoint sets the path for the MCP endpoint

func (*Transport) SetPathPrefix added in v1.2.1

func (t *Transport) SetPathPrefix(prefix string) *Transport

SetPathPrefix sets a prefix for all endpoint paths

func (*Transport) Start

func (t *Transport) Start() error

Start starts the transport

func (*Transport) Stop

func (t *Transport) Stop() error

Stop stops the transport

Jump to

Keyboard shortcuts

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