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(),

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