Skip to main content
Glama

validate_optimization_input

Validate input data for optimization problems, ensuring accuracy by checking for errors, warnings, and providing suggestions. Supports diverse problem types and structured data input.

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
input_dataYes
problem_typeYes

Implementation Reference

  • The main execution logic of the 'validate_optimization_input' tool. It validates the problem_type using ProblemType enum, dispatches to specific validation functions based on the type, and returns a serialized ValidationResult.
    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 the registration function that adds the 'validate_optimization_input' tool to the MCP server.
    register_validation_tools(mcp)
  • The registration function that defines and registers the tool using the @mcp.tool() decorator within the MCP server instance.
    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")
  • Pydantic model used for the output of the validation tool, containing is_valid, errors, warnings, and suggestions.
    class ValidationResult(BaseModel): """Result of input validation.""" is_valid: bool = Field(description="Whether the input is valid") errors: list[str] = Field( default_factory=list, description="List of validation errors", ) warnings: list[str] = Field( default_factory=list, description="List of validation warnings", ) suggestions: list[str] = Field( default_factory=list, description="List of suggestions for improvement", )
  • Enum defining supported problem types, used internally to validate and route the input problem_type parameter.
    class ProblemType(str, Enum): """Types of optimization problems.""" LINEAR_PROGRAM = "linear_program" INTEGER_PROGRAM = "integer_program" ASSIGNMENT = "assignment" TRANSPORTATION = "transportation" KNAPSACK = "knapsack" TSP = "tsp" VRP = "vrp" JOB_SCHEDULING = "job_scheduling" SHIFT_SCHEDULING = "shift_scheduling" PORTFOLIO = "portfolio" PRODUCTION_PLANNING = "production_planning"

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