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")
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions validation and the return structure ('errors, warnings, and suggestions'), but lacks details on what validation entails (e.g., checks for data format, constraints, or feasibility), potential side effects, error handling, or performance considerations. This is inadequate for a tool with no annotation coverage.

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

Conciseness4/5

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

The description is front-loaded with the core purpose in the first sentence, followed by a structured Args/Returns section. It's appropriately sized with no redundant information, though the formatting with indentation could be slightly cleaner for readability.

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

Completeness2/5

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

Given the complexity (validation tool with 2 parameters, nested objects, and no output schema), the description is incomplete. It lacks details on validation criteria, error formats, and how it integrates with sibling optimization tools. Without annotations or an output schema, more context is needed to fully understand the tool's behavior and outputs.

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

Parameters3/5

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

Schema description coverage is 0%, so the description must compensate. It lists the parameters ('problem_type' and 'input_data') and briefly explains them, adding some meaning beyond the bare schema. However, it doesn't elaborate on valid values for 'problem_type' (e.g., possible optimization types) or the structure of 'input_data,' leaving significant gaps in parameter understanding.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Validate input data for optimization problems.' It specifies the verb ('validate') and resource ('input data for optimization problems'), making the function unambiguous. However, it doesn't explicitly differentiate from sibling tools, which are all optimization solvers rather than validation tools, so it misses full sibling distinction.

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?

The description implies usage by mentioning 'optimization problems,' suggesting it should be used before running optimization tools. However, it doesn't provide explicit guidance on when to use this tool versus alternatives (e.g., which sibling tools it complements), nor does it state any exclusions or prerequisites, leaving usage context partially inferred.

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/dmitryanchikov/mcp-optimizer'

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