Skip to main content
Glama

solve_z3_simple

Solve Z3 constraint satisfaction problems by providing variables and constraints as simple lists without complex model structures.

Instructions

Simplified interface for Z3 constraint problems.

A more direct way to solve Z3 problems without full model structure.
Just provide variables and constraints as simple lists.

Args:
    variables: List of dicts with 'name' and 'type' for each variable
    constraints: List of constraint expressions as strings
    description: Optional problem description

Returns:
    Solution results as TextContent list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
variablesYes
constraintsYes
descriptionNo

Implementation Reference

  • The main handler function for the 'solve_z3_simple' MCP tool. Converts simple input lists into Z3Problem model and calls solve_problem from z3_solver.
    @app.tool("solve_z3_simple")
    async def solve_z3_simple(
        variables: list[dict[str, str]],
        constraints: list[str],
        description: str = "",
    ) -> list[TextContent]:
        """Simplified interface for Z3 constraint problems.
    
        A more direct way to solve Z3 problems without full model structure.
        Just provide variables and constraints as simple lists.
    
        Args:
            variables: List of dicts with 'name' and 'type' for each variable
            constraints: List of constraint expressions as strings
            description: Optional problem description
    
        Returns:
            Solution results as TextContent list
        """
        try:
            # Convert to Problem model
            problem_variables = []
            for var in variables:
                if "name" not in var or "type" not in var:
                    return [
                        TextContent(
                            type="text",
                            text="Each variable must have 'name' and 'type' fields",
                        )
                    ]
    
                try:
                    var_type = Z3VariableType(var["type"])
                except ValueError:
                    return [
                        TextContent(
                            type="text",
                            text=(
                                f"Invalid variable type: {var['type']}. "
                                f"Must be one of: {', '.join([t.value for t in Z3VariableType])}"
                            ),
                        )
                    ]
    
                problem_variables.append(Z3Variable(name=var["name"], type=var_type))
    
            problem_constraints = [Z3Constraint(expression=expr) for expr in constraints]
    
            problem = Z3Problem(
                variables=problem_variables,
                constraints=problem_constraints,
                description=description,
            )
    
            # Solve the problem
            result = solve_problem(problem)
    
            match result:
                case Success(solution):
                    return [
                        TextContent(
                            type="text",
                            text=json.dumps(
                                {
                                    "values": solution.values,
                                    "is_satisfiable": solution.is_satisfiable,
                                    "status": solution.status,
                                }
                            ),
                        )
                    ]
                case Failure(error):
                    return [
                        TextContent(type="text", text=f"Error solving problem: {error}")
                    ]
                case _:
                    return [
                        TextContent(type="text", text="Unexpected error in solve_z3_simple")
                    ]
        except Exception as e:
            return [TextContent(type="text", text=f"Error in solve_z3_simple: {e!s}")]
  • Pydantic models defining the structure for Z3 problems, variables, constraints, and solutions, used internally by the tool handler.
    class Z3VariableType(str, Enum):
        """Variable types in Z3."""
    
        INTEGER = "integer"
        REAL = "real"
        BOOLEAN = "boolean"
        STRING = "string"
    
    
    class Z3Variable(BaseModel):
        """Typed variable in a Z3 problem."""
    
        name: str
        type: Z3VariableType
    
    
    class Z3Constraint(BaseModel):
        """Constraint in a Z3 problem."""
    
        expression: str  # expression as string (run through eval)
        description: str = ""
    
    
    class Z3Problem(BaseModel):
        """Complete Z3 constraint satisfaction problem."""
    
        variables: list[Z3Variable]
        constraints: list[Z3Constraint]
        description: str = ""
    
    
    class Z3Solution(BaseModel):
        """Solution to a Z3 problem."""
    
        values: dict[str, Z3Value]
        is_satisfiable: bool
        status: str
  • FastMCP decorator registering the solve_z3_simple function as an MCP tool.
    @app.tool("solve_z3_simple")
  • Core solver function that takes Z3Problem and uses Z3 library to find a satisfying assignment or determine unsatisfiability.
    def solve_problem(problem: Z3Problem) -> Result[Z3Solution, str]:
        """Orchestrates the complete process of solving a Z3 problem.
    
        Args:
            problem: The problem definition containing variables and constraints.
    
        Returns:
            Result: A Result containing either a Solution object or a failure with error details.
        """
        try:
            vars_result = create_variables(problem.variables)
            if isinstance(vars_result, Failure):
                return vars_result
    
            variables = vars_result.unwrap()
    
            constraints_result = create_constraints(problem.constraints, variables)
            if isinstance(constraints_result, Failure):
                return constraints_result
    
            z3_constraints = constraints_result.unwrap()
    
            solve_result = solve(variables, z3_constraints)
            if isinstance(solve_result, Failure):
                return solve_result
    
            result_tuple = solve_result.unwrap()
    
            return extract_solution(result_tuple[0], result_tuple[1], variables)
        except Exception as e:
            return Failure(f"Error solving problem: {e!s}")
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. It mentions the tool 'solves' problems and returns 'Solution results as TextContent list,' but lacks details on behavioral traits such as error handling, performance characteristics, whether it's read-only or destructive, authentication needs, or rate limits. For a solver tool with zero annotation coverage, this is a significant gap in transparency.

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?

The description is appropriately sized and front-loaded: it starts with the core purpose, explains the simplified approach, lists parameters with clear explanations, and states the return value. Every sentence adds value without redundancy, and the structure (overview, args, returns) is logical and efficient.

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

Completeness3/5

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

Given the tool's complexity (solving constraint problems), no annotations, no output schema, and 0% schema description coverage, the description is partially complete. It covers the purpose, parameters, and return type, but lacks details on behavioral aspects (e.g., what happens on failure, output format specifics). Without annotations or output schema, more context on behavior and results would improve completeness.

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 description coverage is 0%, so the description must compensate. It adds meaningful semantics beyond the schema by explaining each parameter: 'variables' as 'List of dicts with 'name' and 'type' for each variable,' 'constraints' as 'List of constraint expressions as strings,' and 'description' as 'Optional problem description.' This clarifies the structure and purpose of all three parameters, effectively compensating for the lack of schema descriptions.

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: 'Simplified interface for Z3 constraint problems' and 'A more direct way to solve Z3 problems without full model structure.' It specifies the verb ('solve'), resource ('Z3 constraint problems'), and distinguishes it from the sibling 'solve_z3' by emphasizing simplicity and directness. However, it doesn't explicitly contrast with all siblings like 'solve_ortools_problem' or 'simple_cvxpy_solver'.

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 when to use this tool versus alternatives by stating it's 'simplified' and 'more direct' compared to 'full model structure,' suggesting it's for simpler problems. However, it doesn't explicitly name alternatives (e.g., 'use solve_z3 for complex models') or provide clear exclusions (e.g., 'not for optimization problems'). The guidance is present but not fully explicit.

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/sdiehl/usolver'

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