validate_tonel_smalltalk_from_file
Validate Tonel formatted Smalltalk source code by providing a file path. Optionally skip method body validation to check only Tonel structure.
Instructions
Validate Tonel formatted Smalltalk source code from a file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | Path to the Tonel file to validate | |
| options | No | Optional validation options - without-method-body: If true, only validates tonel structure |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The core implementation function that validates Tonel Smalltalk from a file. Checks if file exists, creates a TonelTreeSitterParser (optionally ignoring method body errors), parses the file, and returns validation results with errors if any.
def validate_tonel_smalltalk_from_file_impl( file_path: str, options: dict[str, Any] | None = None ) -> dict[str, Any]: """ Validate Tonel formatted Smalltalk source code from a file. Args: file_path: Path to the Tonel file to validate options: Optional validation options - without-method-body: If true, only validates tonel structure Returns: Dictionary with validation results including success status and error details """ try: if not os.path.exists(file_path): return { "valid": False, "error": f"File not found: {file_path}", "file_path": file_path, } options = options or {} without_method_body = options.get("without-method-body", False) parser = TonelTreeSitterParser(ignore_method_body_errors=without_method_body) parse_result = parser.parse_from_file(file_path) result: dict[str, Any] = { "valid": parse_result["valid"], "file_path": file_path, "parser_type": "tonel_only" if without_method_body else "full", } if parse_result["errors"]: result["errors"] = parse_result["errors"] return result except Exception as e: return { "valid": False, "error": f"Validation failed: {str(e)}", "file_path": file_path, "exception": type(e).__name__, } - The handler function signature defines the input schema: file_path (str) and options (optional dict[str,Any]) as inputs; returns dict[str,Any]. Docstring documents the 'without-method-body' option.
_: Context, file_path: str, options: dict[str, Any] | None = None ) -> dict[str, Any]: """ Validate Tonel formatted Smalltalk source code from a file. Args: file_path: Path to the Tonel file to validate options: Optional validation options - without-method-body: If true, only validates tonel structure Returns: Dictionary with validation results including success status and error details """ return validate_tonel_smalltalk_from_file_impl(file_path, options) - smalltalk_validator_mcp_server/server.py:21-36 (registration)The MCP tool is registered with FastMCP using @app.tool('validate_tonel_smalltalk_from_file') decorator, binding the tool name to the handler function that delegates to the implementation.
@app.tool("validate_tonel_smalltalk_from_file") def validate_tonel_smalltalk_from_file( _: Context, file_path: str, options: dict[str, Any] | None = None ) -> dict[str, Any]: """ Validate Tonel formatted Smalltalk source code from a file. Args: file_path: Path to the Tonel file to validate options: Optional validation options - without-method-body: If true, only validates tonel structure Returns: Dictionary with validation results including success status and error details """ return validate_tonel_smalltalk_from_file_impl(file_path, options) - The TonelTreeSitterParser class used by the implementation. The parse_from_file method reads the file and calls parse(), which uses tree-sitter to validate syntax and collect errors.
class TonelTreeSitterParser: """Validates Tonel formatted Smalltalk source using tree-sitter. Args: ignore_method_body_errors: When True, errors inside method_body nodes are suppressed (equivalent to old TonelParser / tonel-only mode). """ def __init__(self, ignore_method_body_errors: bool = False) -> None: self._ignore = ignore_method_body_errors self._parser = _make_parser() def parse(self, content: str) -> dict[str, Any]: tree = self._parser.parse(content.encode("utf-8")) errors = _collect_errors(tree.root_node, self._ignore) return {"valid": len(errors) == 0, "errors": errors} def parse_from_file(self, file_path: str) -> dict[str, Any]: with open(file_path, encoding="utf-8") as f: content = f.read() return self.parse(content)