Validation
Related Topics: Testing (run assertions) | Linting (metadata quality) | Type System (type definitions) | YAML Schemas (field reference)
Validation ensures your endpoint definitions are structurally correct before execution. It catches errors early in development.
Running Validation
Section titled “Running Validation”# Validate all endpointsmxcp validate
# Validate a specific endpoint (use file path)mxcp validate tools/my_tool.yml
# JSON output for automationmxcp validate --json-output
# Debug mode for detailed errorsmxcp validate --debug
# Read-only database connectionmxcp validate --readonlyWhat Gets Validated
Section titled “What Gets Validated”YAML Syntax
Section titled “YAML Syntax”- Correct YAML formatting
- Proper indentation
- Valid characters
Required Fields
Section titled “Required Fields”mxcp: 1version field- Endpoint type (
tool,resource, orprompt) namefor tools/prompts,urifor resourcessourcespecification (for tools and resources)descriptionfor each parameter
Type Definitions
Section titled “Type Definitions”- Valid type names (
string,number,integer,boolean,array,object) - Valid format annotations (
email,uri,date,time,date-time,duration,timestamp) - Valid language (
sql,python) - Nested type structures
Parameter Names
Section titled “Parameter Names”- Must match pattern
^[a-zA-Z_][a-zA-Z0-9_]*$ - Start with letter or underscore
- Only alphanumeric and underscores allowed
File References
Section titled “File References”- Source files exist
- Paths are resolvable
- Files are readable
SQL/Python Syntax
Section titled “SQL/Python Syntax”- Basic SQL parsing
- Python module loading
- Function existence check
Validation Output
Section titled “Validation Output”Success
Section titled “Success”mxcp validate
🔍 Validation Results Validated 3 endpoint files • 3 passed
✅ Passed validation: ✓ tools/get_user.yml ✓ tools/search_users.yml ✓ resources/user-profile.yml
🎉 All endpoints are valid!Failure
Section titled “Failure”mxcp validate
🔍 Validation Results Validated 3 endpoint files • 1 passed • 2 failed
❌ Failed validation: ✗ tools/broken.yml Error: tool.parameters.0: 'description' is a required property
✗ tools/invalid_type.yml Error: tool.parameters.0.type: 'strng' is not one of ['string', 'number', 'integer', 'boolean', 'array', 'object']
✅ Passed validation: ✓ tools/get_user.yml
💡 Tip: Fix validation errors to ensure endpoints work correctlyJSON Output
Section titled “JSON Output”mxcp validate --json-output{ "status": "ok", "result": { "status": "error", "validated": [ { "status": "ok", "path": "tools/get_user.yml" }, { "status": "error", "path": "tools/broken.yml", "message": "tool.parameters.0: 'description' is a required property" } ] }}Fields:
status: Command execution status (okorerror)result: Validation results objectstatus: Overall validation status (okorerror)validated: List of validation resultsstatus: Individual result (okorerror)path: Path to endpoint filemessage: Error message (only present on errors)
Common Validation Errors
Section titled “Common Validation Errors”Missing Endpoint Type
Section titled “Missing Endpoint Type”# Error: Endpoint definition must include a tool, resource, or prompt definitionmxcp: 1# Missing: tool, resource, or prompt definitionFix:
mxcp: 1tool: name: my_tool source: code: "SELECT 1"Missing Source Specification
Section titled “Missing Source Specification”# Error: tool.source: {} is not valid under any of the given schemastool: name: my_tool source: {} # Missing code or fileFix:
tool: name: my_tool source: code: "SELECT 1"Invalid Type
Section titled “Invalid Type”# Error: 'strng' is not one of ['string', 'number', 'integer', 'boolean', 'array', 'object']parameters: - name: id type: strng # Typo description: User IDFix:
parameters: - name: id type: string # Corrected description: User IDCommon mistake - using map instead of object:
# Error: 'map' is not one of ['string', 'number', 'integer', 'boolean', 'array', 'object']return: type: map # Wrong - use 'object'Fix:
return: type: object # CorrectInvalid Parameter Name
Section titled “Invalid Parameter Name”# Error: 'user-name' does not match '^[a-zA-Z_][a-zA-Z0-9_]*$'parameters: - name: user-name # Hyphens not allowed type: string description: UsernameFix:
parameters: - name: user_name # Use underscores type: string description: UsernameParameter names must start with a letter or underscore and contain only alphanumeric characters and underscores.
Invalid Format
Section titled “Invalid Format”# Error: 'datetime' is not one of ['email', 'uri', 'date', 'time', 'date-time', 'duration', 'timestamp']parameters: - name: created type: string format: datetime # Wrong description: Creation dateFix:
parameters: - name: created type: string format: date-time # Correct (with hyphen) description: Creation dateFile Not Found
Section titled “File Not Found”# Error: Source file not found: ../sql/missing.sqlsource: file: ../sql/missing.sqlFix: Create the file or correct the path.
Missing Parameter Description
Section titled “Missing Parameter Description”# Error: 'description' is a required propertyparameters: - name: user_id type: string # Missing descriptionFix:
parameters: - name: user_id type: string description: The unique user identifierInvalid Source
Section titled “Invalid Source”Source must specify exactly one of code or file:
# Error: tool.source: {'code': 'SELECT 1', 'file': 'query.sql'} is not valid under any of the given schemastool: name: my_tool source: code: "SELECT 1" file: "query.sql" # Can't have bothFix:
tool: name: my_tool source: code: "SELECT 1" # Use either code or fileInvalid Language
Section titled “Invalid Language”# Error: 'javascript' is not one of ['sql', 'python']tool: name: my_tool language: javascript # Invalid source: code: "console.log('hello')"Fix:
tool: name: my_tool language: python # Use 'sql' or 'python' source: code: "print('hello')"Validation vs Linting
Section titled “Validation vs Linting”MXCP separates structural checks from quality checks:
Validation (mxcp validate)
Section titled “Validation (mxcp validate)”Checks structural correctness - fails on errors:
- Valid YAML syntax
- Valid endpoint type (tool, resource, or prompt)
- Valid type and format values
- Valid parameter names
- Source file existence
- Required parameter descriptions
Linting (mxcp lint)
Section titled “Linting (mxcp lint)”Checks metadata quality - provides suggestions:
- Missing endpoint descriptions
- Missing return type descriptions
- Missing examples on parameters
- Missing default values
- Missing test cases
- Missing tags
- Missing behavioral annotations (for tools)
Use both: mxcp validate && mxcp lint
CI/CD Integration
Section titled “CI/CD Integration”GitHub Actions
Section titled “GitHub Actions”name: Validateon: [push, pull_request]
jobs: validate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.11' - run: pip install mxcp - run: mxcp validatePre-commit Hook
Section titled “Pre-commit Hook”#!/bin/bashmxcp validateif [ $? -ne 0 ]; then echo "Validation failed. Please fix errors before committing." exit 1fiGitLab CI
Section titled “GitLab CI”validate: stage: test script: - pip install mxcp - mxcp validateBest Practices
Section titled “Best Practices”1. Validate During Development
Section titled “1. Validate During Development”Run mxcp validate after every change.
2. Use Editor Integration
Section titled “2. Use Editor Integration”Many editors validate YAML syntax automatically.
3. Fix Errors Immediately
Section titled “3. Fix Errors Immediately”Don’t let validation errors accumulate.
4. Include in CI/CD
Section titled “4. Include in CI/CD”Block merges on validation failures.
5. Use Debug Mode
Section titled “5. Use Debug Mode”When errors are unclear:
mxcp validate --debugTroubleshooting
Section titled “Troubleshooting””File not found” but file exists
Section titled “”File not found” but file exists”- Check relative path from YAML file
- Verify case sensitivity
- Check file permissions
”Invalid YAML” with no details
Section titled “”Invalid YAML” with no details”- Run YAML through online validator
- Check for tabs vs spaces
- Look for special characters
Validation passes but tool fails
Section titled “Validation passes but tool fails”- Validation checks structure, not logic
- Run
mxcp testfor functional testing - Check SQL/Python syntax separately
Next Steps
Section titled “Next Steps”- Testing - Functional testing
- Linting - Metadata quality
- Type System - Type reference