extractToken (mcp-endpoint/index.ts)

Flowise · packages/server/src/controllers/mcp-endpoint/index.ts · typescript · Apache-2.0
auth

Middleware to extract and validate Bearer tokens for MCP endpoints.

// Source: https://github.com/FlowiseAI/Flowise | License: Apache-2.0 | Copyright 2023-present FlowiseAI, Inc
// Provided via justclaw.it.com; keep this notice with the code.
import { NextFunction, Request, Response } from 'express'
import mcpEndpointService from '../../services/mcp-endpoint'
import { RateLimiterManager } from '../../utils/rateLimit'
import logger from '../../utils/logger'

/**
 * Extract token from the Authorization: Bearer <token> header.
 * Returns null if not present or malformed.
 */
function extractToken(req: Request): string | null {
    const authHeader = req.headers.authorization
    if (!authHeader || !authHeader.startsWith('Bearer ')) return null
    const token = authHeader.slice(7).trim()
    return token.length > 0 ? token : null
}

/**
 * Authentication midd

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key