Skip to main content
Glama

validate_optimization_input

Validate input data for optimization problems to ensure correct format and identify errors before processing.

Instructions

Validate input data for optimization problems.

Args: problem_type: Type of optimization problem input_data: Input data to validate Returns: Validation result with errors, warnings, and suggestions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
problem_typeYes
input_dataYes

Implementation Reference

  • The main handler function for the 'validate_optimization_input' MCP tool. It dispatches to specific problem validators based on problem_type and returns a ValidationResult.
    @with_resource_limits(timeout_seconds=30.0, estimated_memory_mb=50.0) # type: ignore[arg-type] @mcp.tool() def validate_optimization_input( problem_type: str, input_data: dict[str, Any], ) -> dict[str, Any]: """Validate input data for optimization problems. Args: problem_type: Type of optimization problem input_data: Input data to validate Returns: Validation result with errors, warnings, and suggestions """ try: # Validate problem type try: prob_type = ProblemType(problem_type) except ValueError: return ValidationResult( is_valid=False, errors=[f"Unknown problem type: {problem_type}"], warnings=[], suggestions=[f"Supported types: {[t.value for t in ProblemType]}"], ).model_dump() # Route to appropriate validator if prob_type == ProblemType.LINEAR_PROGRAM: result = validate_linear_program(input_data) elif prob_type == ProblemType.INTEGER_PROGRAM: result = validate_linear_program(input_data) # Same validation as linear program elif prob_type == ProblemType.ASSIGNMENT: result = validate_assignment_problem(input_data) elif prob_type == ProblemType.TRANSPORTATION: result = validate_transportation_problem(input_data) elif prob_type == ProblemType.KNAPSACK: result = validate_knapsack_problem(input_data) elif prob_type in [ProblemType.TSP, ProblemType.VRP]: result = validate_routing_problem(input_data) elif prob_type in [ ProblemType.JOB_SCHEDULING, ProblemType.SHIFT_SCHEDULING, ]: result = validate_scheduling_problem(input_data) elif prob_type == ProblemType.PORTFOLIO: result = validate_portfolio_problem(input_data) elif prob_type == ProblemType.PRODUCTION_PLANNING: result = validate_production_problem(input_data) else: result = ValidationResult( is_valid=False, errors=[f"Validation not yet implemented for {problem_type}"], warnings=[], suggestions=["This problem type will be supported in future versions"], ) logger.info( f"Validated {problem_type} problem: {'valid' if result.is_valid else 'invalid'}" ) return result.model_dump() except Exception as e: logger.error(f"Validation error: {e}") return ValidationResult( is_valid=False, errors=[f"Validation failed: {str(e)}"], warnings=[], suggestions=["Check input data format and try again"], ).model_dump()
  • Invocation of register_validation_tools which adds the validation tools, including 'validate_optimization_input', to the FastMCP server instance.
    register_validation_tools(mcp)
  • The registration function that defines and registers the 'validate_optimization_input' tool using the @mcp.tool() decorator.
    def register_validation_tools(mcp: FastMCP[Any]) -> None: """Register validation tools with the MCP server.""" @with_resource_limits(timeout_seconds=30.0, estimated_memory_mb=50.0) # type: ignore[arg-type] @mcp.tool() def validate_optimization_input( problem_type: str, input_data: dict[str, Any], ) -> dict[str, Any]: """Validate input data for optimization problems. Args: problem_type: Type of optimization problem input_data: Input data to validate Returns: Validation result with errors, warnings, and suggestions """ try: # Validate problem type try: prob_type = ProblemType(problem_type) except ValueError: return ValidationResult( is_valid=False, errors=[f"Unknown problem type: {problem_type}"], warnings=[], suggestions=[f"Supported types: {[t.value for t in ProblemType]}"], ).model_dump() # Route to appropriate validator if prob_type == ProblemType.LINEAR_PROGRAM: result = validate_linear_program(input_data) elif prob_type == ProblemType.INTEGER_PROGRAM: result = validate_linear_program(input_data) # Same validation as linear program elif prob_type == ProblemType.ASSIGNMENT: result = validate_assignment_problem(input_data) elif prob_type == ProblemType.TRANSPORTATION: result = validate_transportation_problem(input_data) elif prob_type == ProblemType.KNAPSACK: result = validate_knapsack_problem(input_data) elif prob_type in [ProblemType.TSP, ProblemType.VRP]: result = validate_routing_problem(input_data) elif prob_type in [ ProblemType.JOB_SCHEDULING, ProblemType.SHIFT_SCHEDULING, ]: result = validate_scheduling_problem(input_data) elif prob_type == ProblemType.PORTFOLIO: result = validate_portfolio_problem(input_data) elif prob_type == ProblemType.PRODUCTION_PLANNING: result = validate_production_problem(input_data) else: result = ValidationResult( is_valid=False, errors=[f"Validation not yet implemented for {problem_type}"], warnings=[], suggestions=["This problem type will be supported in future versions"], ) logger.info( f"Validated {problem_type} problem: {'valid' if result.is_valid else 'invalid'}" ) return result.model_dump() except Exception as e: logger.error(f"Validation error: {e}") return ValidationResult( is_valid=False, errors=[f"Validation failed: {str(e)}"], warnings=[], suggestions=["Check input data format and try again"], ).model_dump() logger.info("Registered validation 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/dmitryanchikov/mcp-optimizer'

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