Skip to main content
Glama

validate_component_protocol_signatures

Check that component classes have required methods with correct return-type annotations, flagging missing methods or mismatched annotations.

Instructions

AST-check that each required component class has the required method with a matching return-type annotation (if annotated at all).

    - STR-003: class is missing the required method.
    - VAL-006: method declares a return annotation but it doesn't match
      the expected BaseModel (EntrySignalOutput / ExitSignalOutput / ...).

    Missing annotations are NOT flagged (policy vs correctness — missing
    annotation is a stylistic choice, Pydantic catches runtime
    mismatches). Missing files are silently skipped (preflight STR-001
    territory).

    Returns ``{"any_errors": bool, "findings": [...]}``.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
strategy_dirYes

Implementation Reference

  • MCP tool handler that delegates to the internal validator. Defined as a @server.tool() decorated function validate_component_protocol_signatures(strategy_dir: str) -> dict. Imports and calls validate_component_signatures from echolon.strategy.validators.component_signatures and returns its .to_dict() result.
    @server.tool()
    def validate_component_protocol_signatures(strategy_dir: str) -> dict:
        """AST-check that each required component class has the required
        method with a matching return-type annotation (if annotated at all).
    
        - STR-003: class is missing the required method.
        - VAL-006: method declares a return annotation but it doesn't match
          the expected BaseModel (EntrySignalOutput / ExitSignalOutput / ...).
    
        Missing annotations are NOT flagged (policy vs correctness — missing
        annotation is a stylistic choice, Pydantic catches runtime
        mismatches). Missing files are silently skipped (preflight STR-001
        territory).
    
        Returns ``{"any_errors": bool, "findings": [...]}``.
        """
        from echolon.strategy.validators.component_signatures import (
            validate_component_signatures as _impl,
        )
        return _impl(strategy_dir=strategy_dir).to_dict()
  • Core implementation: validate_component_signatures() performs AST-based checking of 4 required component files (entry.py, exit.py, risk.py, sizer.py). Checks STR-003 (class missing required method) and VAL-006 (return annotation doesn't match expected BaseModel). Silently skips missing files and missing annotations (by design).
    def validate_component_signatures(strategy_dir: "Path | str") -> Report:
        """Return a Report with findings for method / return-annotation issues
        across the 4 required component files in ``strategy_dir``.
    
        Silently skips files that don't exist — that's preflight's STR-001
        concern, not ours.
        """
        strategy_dir = Path(strategy_dir)
        report = Report()
    
        for file_name, (class_name, method_name, expected_return) in _CONTRACT.items():
            file_path = strategy_dir / file_name
            if not file_path.exists():
                continue  # file-presence is preflight's concern (STR-001)
    
            try:
                tree = ast.parse(file_path.read_text(encoding="utf-8"))
            except SyntaxError as e:
                # Syntax errors propagate upstream — surface as STR-003 so
                # the caller still gets a structured finding.
                report.add(Finding(
                    code="STR-003",
                    message=f"Cannot parse {file_name}: {e}",
                    context={
                        "file": str(file_path),
                        "component": class_name,
                        "method": method_name,
                    },
                ))
                continue
    
            class_node = _find_class_in_module(tree, class_name)
            if class_node is None:
                # preflight STR-002 already catches wrong class names; skip.
                continue
    
            method_node = _find_method_in_class(class_node, method_name)
            if method_node is None:
                report.add(Finding(
                    code="STR-003",
                    message=(
                        f"Class {class_name} in {file_name} is missing required method "
                        f"{method_name}"
                    ),
                    context={
                        "file": str(file_path),
                        "component": class_name,
                        "class_name": class_name,
                        "method": method_name,
                        "missing_method": method_name,
                    },
                ))
                continue
    
            actual_annotation_tail = _annotation_tail(method_node.returns)
            if actual_annotation_tail is None:
                # Missing annotation → NO finding (FP-insurance principle 2).
                continue
            if actual_annotation_tail != expected_return:
                report.add(Finding(
                    code="VAL-006",
                    message=(
                        f"{class_name}.{method_name} return annotation is "
                        f"{actual_annotation_tail!r}, expected {expected_return!r}"
                    ),
                    context={
                        "file": str(file_path),
                        "component": class_name,
                        "method": method_name,
                        "expected_return": expected_return,
                        "actual_annotation": actual_annotation_tail,
                    },
                ))
    
        return report
  • Contract definition: maps each component file to (class_name, method_name, expected_return_type_tail_identifier) — the protocol requirements for entry.py/entry_rule.generate_signal -> EntrySignalOutput, exit.py/exit_rule.should_exit -> ExitSignalOutput, risk.py/risk_manager.can_trade -> RiskOutput, sizer.py/position_sizer.calculate_size -> SizerOutput.
    _CONTRACT: Dict[str, Tuple[str, str, str]] = {
        "entry.py": ("entry_rule",     "generate_signal", "EntrySignalOutput"),
        "exit.py":  ("exit_rule",      "should_exit",     "ExitSignalOutput"),
        "risk.py":  ("risk_manager",   "can_trade",       "RiskOutput"),
        "sizer.py": ("position_sizer", "calculate_size",  "SizerOutput"),
    }
  • Utility _annotation_tail() extracts the trailing identifier from an AST annotation node, handling ast.Name, ast.Constant (string forward refs), ast.Attribute (dotted names). Returns None for missing annotations.
    def _annotation_tail(annotation: ast.AST | None) -> str | None:
        """Return the trailing identifier of an annotation AST node.
    
        Handles:
        - ``ast.Name`` (bare: EntrySignalOutput) -> "EntrySignalOutput"
        - ``ast.Constant`` (string forward ref: "EntrySignalOutput") -> "EntrySignalOutput"
        - ``ast.Attribute`` (dotted: schemas.EntrySignalOutput) -> "EntrySignalOutput"
        - ``None`` (no annotation) -> None
    
        Anything else (generics, unions, subscripts) returns the raw AST dump
        so callers can surface the unusual shape verbatim in context.
        """
        if annotation is None:
            return None
        if isinstance(annotation, ast.Name):
            return annotation.id
        if isinstance(annotation, ast.Constant) and isinstance(annotation.value, str):
            # String forward reference — take the trailing identifier.
            return annotation.value.strip().split(".")[-1]
        if isinstance(annotation, ast.Attribute):
            return annotation.attr
        return ast.dump(annotation)
  • Registration via @server.tool() decorator on the validate_component_protocol_signatures method. Also referenced in validate_strategy_full at line 638 which composes it with other validators.
    @server.tool()
    def validate_component_protocol_signatures(strategy_dir: str) -> dict:
Behavior4/5

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

With no annotations, the description bears full disclosure burden. It explains that missing annotations are not flagged, missing files are skipped, and specifies the return format {"any_errors": bool, "findings": [...]}. It does not mention side effects, but as a read-only validation tool, the description is sufficiently transparent.

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 structured with bullet points and a return definition. It front-loads the main purpose and uses compact language. However, it is somewhat verbose for a single-parameter tool, but every sentence adds value. It is generally concise.

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?

For a validator with one parameter and no output schema, the description covers the behavior and return format well. However, the lack of parameter explanation and absence of prerequisites or error conditions (though it implies handling) leave gaps. It is minimally adequate.

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

Parameters1/5

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

The only parameter, strategy_dir, lacks any explanation in the description or schema description. Since schema description coverage is 0%, the description should compensate but fails to clarify what this parameter represents, its expected format, or constraints. This is a significant gap.

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 identifies the tool's purpose: an AST-check for required component classes having required methods with matching return-type annotations. It specifies concrete rules (STR-003, VAL-006) and differentiates from siblings like validate_component_integration by focusing on method signatures.

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

Usage Guidelines4/5

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

The description implies when to use: to validate method signatures against expected annotations and existence of required methods. It provides context on what is not flagged (missing annotations as stylistic choice, missing files silently skipped), but does not explicitly state when to use an alternative or when not to use. Nonetheless, the guidance is clear for a specialized validator.

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/DolphinQuant/echolon'

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