Skip to main content
Glama

contentrain_validate

Validate content against model schemas to detect field violations, type mismatches, broken relations, secret leaks, and i18n issues. Optionally auto-fix structural problems like canonical sorting and missing locale files.

Instructions

Validate project content against model schemas. Detects required field violations, type mismatches, broken relations, secret leaks, i18n parity issues, and more. If fix:true, auto-fixes structural issues (canonical sort, orphan meta, missing locale files) — do NOT manually edit .contentrain/ files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelNoModel ID to validate (omit for all models)
fixNoAuto-fix structural issues (canonical sort, orphan meta, missing locale files). Default: false

Implementation Reference

  • The handler for 'contentrain_validate' tool, which validates project content and optionally auto-fixes issues.
    server.tool(
      'contentrain_validate',
      'Validate project content against model schemas. Detects required field violations, type mismatches, broken relations, secret leaks, i18n parity issues, and more. If fix:true, auto-fixes structural issues (canonical sort, orphan meta, missing locale files) — do NOT manually edit .contentrain/ files.',
      {
        model: z.string().optional().describe('Model ID to validate (omit for all models)'),
        fix: z.boolean().optional().describe('Auto-fix structural issues (canonical sort, orphan meta, missing locale files). Default: false'),
      },
      async (input) => {
        const config = await readConfig(projectRoot)
        if (!config) {
          return {
            content: [{ type: 'text' as const, text: JSON.stringify({ error: 'Project not initialized. Run contentrain_init first.' }) }],
            isError: true,
          }
        }
    
        try {
          let result: Awaited<ReturnType<typeof validateProject>> | undefined
    
          if (input.fix) {
            // Branch health gate for fix mode (creates a branch)
            const fixHealth = await checkBranchHealth(projectRoot)
            if (fixHealth.blocked) {
              return {
                content: [{ type: 'text' as const, text: JSON.stringify({
                  error: fixHealth.message,
                  action: 'blocked',
                  hint: 'Merge or delete old contentrain/* branches before auto-fixing.',
                }, null, 2) }],
                isError: true,
              }
            }
    
            // Use git transaction for fixes
            const branch = buildBranchName('fix', 'validate')
            const tx = await createTransaction(projectRoot, branch)
    
            try {
              await tx.write(async (wt) => {
                result = await validateProject(wt, { model: input.model, fix: true })
              })
    
              if (result!.fixed > 0) {
                await tx.commit(`[contentrain] validate: auto-fix ${result!.fixed} issue(s)`)
                const gitResult = await tx.complete({
                  tool: 'contentrain_validate',
                  model: input.model ?? '*',
                })
    
                const nextSteps: string[] = []
                if (result!.summary.errors > 0) nextSteps.push('Fix remaining errors manually')
                if (result!.summary.warnings > 0) nextSteps.push('Review warnings')
                nextSteps.push('Run contentrain_validate again to verify')
    
                return {
                  content: [{ type: 'text' as const, text: JSON.stringify({
                    status: 'committed',
                    message: `Validation complete. ${result!.fixed} issue(s) auto-fixed and committed to git. Do NOT manually edit .contentrain/ files.`,
                    ...result!,
                    git: { branch, action: gitResult.action, commit: gitResult.commit },
                    context_updated: true,
                    next_steps: nextSteps,
                  }, null, 2) }],
                }
              } else {
                // Nothing to fix, cleanup the branch
                await tx.cleanup()
              }
            } catch (error) {
              await tx.cleanup()
              throw error
            } finally {
              await tx.cleanup()
            }
          }
    
          // No fix or nothing was fixed — run read-only validation
          if (!result) {
            result = await validateProject(projectRoot, { model: input.model, fix: false })
          }
    
          const nextSteps: string[] = []
          if (result.summary.errors > 0) nextSteps.push('Fix errors in content using contentrain_content_save')
          if (result.summary.warnings > 0) nextSteps.push('Review warnings')
          if (result.valid) nextSteps.push('Run contentrain_submit to push changes')
    
          return {
            content: [{ type: 'text' as const, text: JSON.stringify({
              status: 'validated',
              message: result.valid
                ? 'All validation checks passed.'
                : `Validation found ${result.summary.errors} error(s) and ${result.summary.warnings} warning(s).`,
              ...result,
              next_steps: nextSteps,
            }, null, 2) }],
          }
        } catch (error) {
          return {
            content: [{ type: 'text' as const, text: JSON.stringify({
              error: `Validation failed: ${error instanceof Error ? error.message : String(error)}`,
            }) }],
            isError: true,
          }
        }
      },
    )
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, description carries full disclosure burden effectively. Explicitly states mutating behavior when fix:true ('auto-fixes structural issues') and enumerates specific modifications (canonical sort, orphan meta, missing locale files). Includes safety warning about manual file editing, though omits details on atomicity or idempotency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with zero waste. First sentence establishes purpose and validation scope; second sentence covers fix behavior and critical safety constraint. Information is front-loaded and dense without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Appropriately complete for a 2-parameter validation tool with 100% schema coverage. Describes validation scope comprehensively and clarifies auto-fix side effects. Minor gap: no output description provided (and no output schema exists), though this is partially mitigated by the detailed behavioral description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% establishing baseline 3. Description adds value by contextualizing the fix parameter with specific examples of structural issues (canonical sort, orphan meta, missing locale files) and coupling it with the safety warning about manual edits, providing usage context beyond raw schema definitions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description opens with specific verb 'Validate' and resource 'project content against model schemas'. Lists concrete validation targets (required field violations, type mismatches, broken relations, secret leaks, i18n parity) that clearly distinguish this from sibling CRUD operations like content_save or model_delete.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides clear conditional guidance for the fix parameter ('If fix:true, auto-fixes...') and safety constraints ('do NOT manually edit .contentrain/ files'). However, lacks explicit comparison to sibling tools like contentrain_scan or contentrain_apply regarding when validation is the appropriate choice over other operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Contentrain/ai'

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