Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶
func NewMiddleware(s *oauth.Server) func(server.ToolHandlerFunc) server.ToolHandlerFunc
NewMiddleware creates an authentication middleware for mark3labs/mcp-go SDK. It validates OAuth tokens, caches results, and adds authenticated user to context.
The middleware:
- Extracts OAuth token from context (set by CreateHTTPContextFunc)
- Validates token using Server.ValidateTokenCached (with 5-minute cache)
- Adds User to context via oauth.WithUser
- Passes request to tool handler with authenticated context
Use oauth.GetUserFromContext(ctx) in tool handlers to access authenticated user.
func WithOAuth ¶
func WithOAuth(mux *http.ServeMux, cfg *oauth.Config) (*oauth.Server, mcpserver.ServerOption, error)
WithOAuth returns a server option that enables OAuth authentication for mark3labs/mcp-go SDK.
Usage:
import "github.com/tuannvm/oauth-mcp-proxy/mark3labs"
mux := http.NewServeMux()
oauthServer, oauthOption, err := mark3labs.WithOAuth(mux, &oauth.Config{
Provider: "okta",
Issuer: "https://company.okta.com",
Audience: "api://my-server",
})
mcpServer := server.NewMCPServer("Server", "1.0.0", oauthOption)
This function: - Creates OAuth server instance - Registers OAuth HTTP endpoints on mux - Returns server instance and middleware as server option
The returned Server instance provides access to: - WrapHandler() - Wrap HTTP handlers with OAuth token validation - GetHTTPServerOptions() - Get StreamableHTTPServer options - LogStartup() - Log OAuth endpoint information - Discovery URL helpers (GetCallbackURL, GetMetadataURL, etc.)
Note: You must also configure HTTPContextFunc to extract the OAuth token from HTTP headers. Use GetHTTPServerOptions() or CreateHTTPContextFunc().
Types ¶
This section is empty.