Skip to main content
Glama
validation.js1.01 kB
/** * Validation utilities for MCP tool handlers * Provides explicit Zod validation to ensure input is validated at handler entry points. */ import { ValidationError } from '../errors/index.js'; /** * Validates tool input against a Zod schema and returns a structured result. * * @param {import('zod').ZodSchema} schema - The Zod schema to validate against * @param {unknown} input - The raw input to validate * @param {string} toolName - The tool name for error context * @returns {{ success: true, data: unknown } | { success: false, errorResponse: object }} */ export const validateToolInput = (schema, input, toolName) => { const result = schema.safeParse(input); if (!result.success) { const error = ValidationError.fromZod(result.error, toolName); return { success: false, errorResponse: { content: [{ type: 'text', text: JSON.stringify(error.toJSON(), null, 2) }], isError: true, }, }; } return { success: true, data: result.data }; };

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/jgardner04/Ghost-MCP-Server'

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