Skip to main content
Glama

validate_prompt

Check parameters against a prompt template to ensure compatibility before rendering, preventing errors in automated workflows.

Instructions

Validate parameters against a prompt template without rendering

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
templateIdYesThe ID of the template
parametersYesParameters to validate

Implementation Reference

  • Registers the 'validate_prompt' MCP tool with Zod input schema (templateId and parameters) and a handler that calls registry.prompts.validate and returns JSON result.
    server.tool( "validate_prompt", "Validate parameters against a prompt template without rendering", { templateId: z.string().describe("The ID of the template"), parameters: z.record(z.any()).describe("Parameters to validate"), }, async (args) => { const validation = registry.prompts.validate(args.templateId, args.parameters); return { content: [ { type: "text", text: JSON.stringify(validation, null, 2), }, ], }; } );
  • Main handler logic in PromptManager.validate: checks template existence, required parameters via helper, and performs type checking on provided parameters.
    /** * Validate parameters against a template without rendering */ validate( templateId: string, params: Record<string, unknown> ): { valid: boolean; errors: string[] } { const template = this.get(templateId); if (!template) { return { valid: false, errors: [`Template not found: ${templateId}`] }; } const paramValidation = validateParameters(template, params); if (!paramValidation.valid) { return { valid: false, errors: [`Missing required parameters: ${paramValidation.missing.join(", ")}`], }; } // Type validation const errors: string[] = []; for (const param of template.parameters) { const value = params[param.name]; if (value !== undefined && !this.validateType(value, param.type)) { errors.push( `Parameter '${param.name}' should be type '${param.type}', got '${typeof value}'` ); } } return { valid: errors.length === 0, errors, }; }
  • Helper function to validate presence of required parameters.
    function validateParameters( template: PromptTemplate, params: Record<string, unknown> ): { valid: boolean; missing: string[] } { const required = template.parameters.filter((p) => p.required); const missing = required.filter((p) => !(p.name in params)); return { valid: missing.length === 0, missing: missing.map((p) => p.name), }; }
  • Private helper for type validation of parameter values against expected types.
    private validateType(value: unknown, expectedType: string): boolean { switch (expectedType) { case "string": return typeof value === "string"; case "number": return typeof value === "number"; case "boolean": return typeof value === "boolean"; case "array": return Array.isArray(value); case "object": return typeof value === "object" && value !== null && !Array.isArray(value); default: return true; } }

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/ishuru/open-mcp'

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