Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithOAuth ¶
func WithOAuth(mux *http.ServeMux, cfg *oauth.Config, mcpServer *mcp.Server) (*oauth.Server, http.Handler, error)
WithOAuth returns an OAuth-protected HTTP handler for the official modelcontextprotocol/go-sdk.
Usage:
import mcpoauth "github.com/tuannvm/oauth-mcp-proxy/mcp"
mux := http.NewServeMux()
mcpServer := mcp.NewServer(&mcp.Implementation{
Name: "time-server",
Version: "1.0.0",
}, nil)
oauthServer, handler, err := mcpoauth.WithOAuth(mux, &oauth.Config{
Provider: "okta",
Issuer: "https://company.okta.com",
Audience: "api://my-server",
}, mcpServer)
http.ListenAndServe(":8080", handler)
This function: - Creates OAuth server instance - Registers OAuth HTTP endpoints on mux - Wraps MCP StreamableHTTPHandler with automatic 401 handling - Returns OAuth server and protected HTTP handler
The returned handler automatically: - Returns 401 with WWW-Authenticate headers if Bearer token missing - Passes through OPTIONS requests (CORS pre-flight) - Rejects non-Bearer auth schemes (OAuth-only endpoint)
The returned oauth.Server instance provides access to: - LogStartup() - Log OAuth endpoint information - Discovery URL helpers (GetCallbackURL, GetMetadataURL, etc.)
Tool handlers can access the authenticated user via oauth.GetUserFromContext(ctx).
Types ¶
This section is empty.