httpserver

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package httpserver serves MCP over Streamable HTTP.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DevStaticTokenVerifier

func DevStaticTokenVerifier(cfg AuthConfig) (auth.TokenVerifier, error)

DevStaticTokenVerifier constructs a verifier using a token from an environment variable. It is intended only for tests and local development.

func ProtectMCPHandler

func ProtectMCPHandler(handler http.Handler, cfg AuthConfig, verifier auth.TokenVerifier) http.Handler

ProtectMCPHandler requires a valid bearer token when authentication is enabled.

func ProtectedResourceHandler

func ProtectedResourceHandler(cfg AuthConfig) http.Handler

ProtectedResourceHandler serves RFC 9728 protected resource metadata.

func Run

func Run(ctx context.Context, cfg Config, app AppFactory, logger *slog.Logger) error

Run serves MCP and health endpoints until ctx is canceled or serving fails.

Types

type AppFactory

type AppFactory interface {
	ServerForRequest(req *http.Request) *mcp.Server
}

AppFactory creates an MCP server for an HTTP request.

type AuthConfig

type AuthConfig struct {
	Required             bool     `json:"required"`
	ResourceURL          string   `json:"resourceUrl,omitempty"`
	ResourceName         string   `json:"resourceName,omitempty"`
	MetadataPath         string   `json:"metadataPath,omitempty"`
	MetadataURL          string   `json:"metadataUrl,omitempty"`
	RequiredScopes       []string `json:"requiredScopes,omitzero"`
	AuthorizationServers []string `json:"authorizationServers,omitzero"`
	DevStaticTokenEnv    string   `json:"-"`
}

AuthConfig configures bearer authentication and protected resource metadata.

func DefaultAuthConfig

func DefaultAuthConfig() AuthConfig

DefaultAuthConfig returns the default HTTP authentication configuration.

func (AuthConfig) Validate

func (c AuthConfig) Validate(addr string) error

Validate checks that the authentication configuration is safe for addr.

type Config

type Config struct {
	Addr           string
	MCPPath        string
	ProjectRoot    string
	SessionTimeout time.Duration
	JSONResponse   bool
	Auth           AuthConfig
}

Config configures the Streamable HTTP server.

type TokenVerifierFactory

type TokenVerifierFactory func(AuthConfig) (auth.TokenVerifier, error)

TokenVerifierFactory constructs a token verifier from HTTP auth configuration.

Jump to

Keyboard shortcuts

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