Skip to main content
Glama

validate_stylus_code

Validate Stylus Rust code for smart contracts by running cargo check to detect compilation errors and provide structured fixes with line numbers and guidance.

Instructions

Compile-check Stylus Rust code via cargo check and return structured errors with Stylus-specific fix guidance. Use AFTER generating code to verify correctness. Returns error codes, line numbers, and suggested fixes. Requires Docker.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYeslib.rs source code to validate
cargo_tomlNoCargo.toml content (uses default SDK 0.10.0 template if omitted)

Implementation Reference

  • The execute method in ValidateStylusCodeTool handles the validation logic by invoking the CompilerVerifier.
    def execute(
        self,
        code: str,
        cargo_toml: Optional[str] = None,
        main_rs: Optional[str] = None,
        **kwargs,
    ) -> dict:
        """Validate Stylus code by compiling with cargo check.
    
        Args:
            code: lib.rs source code to validate.
            cargo_toml: Cargo.toml content (uses default if omitted).
            main_rs: main.rs content (uses minimal stub if omitted).
    
        Returns:
            Dict with valid, errors, warnings, fix_guidance, and raw_output.
        """
        error = self._validate_required({"code": code}, ["code"])
        if error:
            return {"error": error}
    
        if self.compiler is None or not self.compiler.is_available():
            return {
                "valid": None,
                "errors": [],
                "warnings": [],
                "fix_guidance": "",
                "raw_output": "",
                "skipped": True,
                "skip_reason": (
                    "Docker not available or arbbuilder-verify image "
                    "not found. Install Docker and build the verify "
                    "image to enable compilation checks."
                ),
            }
    
        # Use defaults if not provided
        if not cargo_toml:
            cargo_toml = DEFAULT_CARGO_TOML
    
        # Run cargo check
        result = self.compiler.verify(code, cargo_toml)
    
        if result.skipped:
            return {
                "valid": None,
                "errors": [],
                "warnings": [],
                "fix_guidance": "",
                "raw_output": "",
                "skipped": True,
                "skip_reason": result.skip_reason or "Verification skipped",
            }
    
        # Separate errors from warnings
        errors = [e for e in result.errors if e.level == "error"]
        warnings = [e for e in result.errors if e.level == "warning"]
    
        # Build fix guidance from error codes
        from src.utils.compiler_verifier import format_fix_guidance
        guidance = format_fix_guidance(errors)
    
        return {
            "valid": result.success,
            "errors": [
                {
                    "code": e.code,
                    "message": e.message,
                    "line": e.line,
                    "column": e.column,
                    "suggestion": e.suggestion,
                }
                for e in errors
            ],
            "warnings": [
                {
                    "code": e.code,
                    "message": e.message,
                    "line": e.line,
                    "column": e.column,
                    "suggestion": e.suggestion,
                }
                for e in warnings
            ],
            "fix_guidance": guidance,
            "raw_output": result.raw_output,
            "skipped": False,
        }
  • The ValidateStylusCodeTool is registered in the server's tool registry.
    "validate_stylus_code": ValidateStylusCodeTool(),
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it specifies the validation method ('via cargo check'), output format ('structured errors with Stylus-specific fix guidance'), and a requirement ('Requires Docker'). However, it doesn't mention potential side effects like resource usage or execution time limits.

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 efficiently structured in three sentences: first states the core function, second provides usage timing, third describes output and requirement. Every sentence adds essential information with zero wasted words, and key information is front-loaded.

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

Completeness4/5

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

For a validation tool with no annotations and no output schema, the description provides good context about what the tool does, when to use it, and behavioral requirements. However, without an output schema, it could more explicitly describe the return structure (error codes, line numbers, fixes) or error handling for edge cases.

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 100%, so the schema already fully documents both parameters. The description doesn't add any parameter-specific information beyond what's in the schema (e.g., it doesn't explain code format expectations or Cargo.toml template details). This meets the baseline for high schema coverage.

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

Purpose5/5

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

The description clearly states the specific action ('Compile-check Stylus Rust code via cargo check') and resource ('Stylus Rust code'), distinguishing it from sibling tools like 'generate_stylus_code' (which creates code) and 'get_stylus_context' (which retrieves context). It explicitly mentions the tool's function of returning structured errors with fix guidance.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('Use AFTER generating code to verify correctness'), which clearly differentiates it from code generation siblings. It also implies an alternative (not using it after generation would lead to unverified code), though it doesn't name specific alternative tools.

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/Quantum3-Labs/ARBuilder'

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