Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

543 B
Raw Blame
import { z } from 'zod'

const CONTROL_CHARACTERS = /[\u0000-\u001F\u007F]/
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/

function isStorableText(value: string): boolean {
    return !CONTROL_CHARACTERS.test(value) && !LONE_SURROGATE.test(value)
}

export const mcpOAuthValidation = {
    storableText(maxLength: number) {
        return z.string().max(maxLength).refine(isStorableText, {
            message: 'Control characters and unpaired surrogates are not allowed',
        })
    },
}