Skip to main content
Glama
validation-helpers.ts637 B
import Zod from 'zod'; import { ApiError } from "./api-error"; export function validate<Z extends Zod.Schema>(obj: any, schema: Z) { try { return schema.parse(obj) as Zod.infer<typeof schema>; } catch (err) { if (!(err instanceof Zod.ZodError)) throw err; const firstError = err.errors[0]; const pathStr = firstError.path.join('.'); throw new ApiError('BadRequest', 'ValidationError', `Invalid \`${pathStr}\` - ${firstError.message}`); } } export const ALLOWED_INPUT_REGEX = /^[0-9A-Za-zÀ-ÖØ-öø-ÿĀ-ỹ-.,_@/+ ]*$/; export const ALLOWED_URL_REGEX = "^https?://([\\da-z.-]+)(:\\d+)?(/[\\w .-]*)*/?$";

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/systeminit/si'

If you have feedback or need assistance with the MCP directory API, please join our Discord server