Function createRequireAuthMiddleware

  • Create a middleware that requires a Bearer token in the Authorization header. Returns HTTP 401 if the token is missing or malformed.

    This is a lightweight check that only verifies presence of a token. Full validation (is the token valid? does the user have access?) is handled by withPaywall() when a tool is actually called.

    Returns ((req, res, next) => void)

    Express middleware for token requirement

      • (req, res, next): void
      • Parameters

        • req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>
        • res: Response<any, Record<string, any>>
        • next: NextFunction

        Returns void

    Example

    const requireAuth = createRequireAuthMiddleware()

    // Protect MCP endpoints
    app.post('/mcp', requireAuth, mcpHandler)
    app.get('/mcp', requireAuth, sseHandler)