Documentation
¶
Overview ¶
Package httpserver serves MCP over Streamable HTTP.
Index ¶
- func DevStaticTokenVerifier(cfg AuthConfig) (auth.TokenVerifier, error)
- func ProtectMCPHandler(handler http.Handler, cfg AuthConfig, verifier auth.TokenVerifier) http.Handler
- func ProtectedResourceHandler(cfg AuthConfig) http.Handler
- func Run(ctx context.Context, cfg Config, app AppFactory, logger *slog.Logger) error
- type AppFactory
- type AuthConfig
- type Config
- type TokenVerifierFactory
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.
Types ¶
type AppFactory ¶
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.