Skip to content

solidworks_mcp.adapters.complexity_analyzer

solidworks_mcp.adapters.complexity_analyzer

Complexity analysis for routing operations between COM and VBA paths.

Classes

ComplexityAnalyzer

ComplexityAnalyzer(parameter_threshold: int = 12, score_threshold: float = 0.6)

Analyze operation complexity and recommend COM or VBA execution path.

Parameters:

Name Type Description Default
parameter_threshold int

The parameter threshold value. Defaults to 12.

12
score_threshold float

The score threshold value. Defaults to 0.6.

0.6

Attributes:

Name Type Description
_parameter_threshold Any

The parameter threshold value.

_score_threshold Any

The score threshold value.

Initialize analyzer state.

Parameters:

Name Type Description Default
parameter_threshold int

The parameter threshold value. Defaults to 12.

12
score_threshold float

The score threshold value. Defaults to 0.6.

0.6

Returns:

Name Type Description
None None

None.

Source code in src/solidworks_mcp/adapters/complexity_analyzer.py
def __init__(
    self,
    parameter_threshold: int = 12,
    score_threshold: float = 0.6,
) -> None:
    """Initialize analyzer state.

    Args:
        parameter_threshold (int): The parameter threshold value. Defaults to 12.
        score_threshold (float): The score threshold value. Defaults to 0.6.

    Returns:
        None: None.
    """
    self._parameter_threshold = max(parameter_threshold, 1)
    self._score_threshold = max(min(score_threshold, 1.0), 0.1)
    self._profiles: dict[str, OperationProfile] = self._default_profiles()
    self._history: dict[str, dict[str, int]] = {}
Functions
analyze
analyze(operation: str, payload: object) -> RoutingDecision

Produce a routing recommendation for an operation call.

Parameters:

Name Type Description Default
operation str

Callable object executed by the helper.

required
payload object

The payload value.

required

Returns:

Name Type Description
RoutingDecision RoutingDecision

The result produced by the operation.

Source code in src/solidworks_mcp/adapters/complexity_analyzer.py
def analyze(self, operation: str, payload: object) -> RoutingDecision:
    """Produce a routing recommendation for an operation call.

    Args:
        operation (str): Callable object executed by the helper.
        payload (object): The payload value.

    Returns:
        RoutingDecision: The result produced by the operation.
    """
    profile = self._profiles.get(
        operation,
        OperationProfile(name=operation, base_complexity=0.2, vba_preferred=False),
    )
    parameter_count = self._count_parameters(payload)

    parameter_component = min(
        parameter_count / float(self._parameter_threshold), 1.0
    )
    history_component = self._history_bias(operation)
    complexity_score = min(
        1.0,
        (parameter_component * 0.45)
        + (profile.base_complexity * 0.40)
        + (history_component * 0.15),
    )

    prefer_vba = (
        parameter_count > self._parameter_threshold
        or profile.vba_preferred
        or complexity_score >= self._score_threshold
    )

    reason = (
        "parameter threshold exceeded"
        if parameter_count > self._parameter_threshold
        else "profile prefers VBA"
        if profile.vba_preferred
        else "complexity score exceeded threshold"
        if complexity_score >= self._score_threshold
        else "COM path preferred"
    )

    return RoutingDecision(
        operation=operation,
        parameter_count=parameter_count,
        complexity_score=complexity_score,
        prefer_vba=prefer_vba,
        reason=reason,
    )
record_result
record_result(operation: str, route: str, success: bool) -> None

Record operation outcome for future routing influence.

Parameters:

Name Type Description Default
operation str

Callable object executed by the helper.

required
route str

The route value.

required
success bool

The success value.

required

Returns:

Name Type Description
None None

None.

Source code in src/solidworks_mcp/adapters/complexity_analyzer.py
def record_result(self, operation: str, route: str, success: bool) -> None:
    """Record operation outcome for future routing influence.

    Args:
        operation (str): Callable object executed by the helper.
        route (str): The route value.
        success (bool): The success value.

    Returns:
        None: None.
    """
    history = self._history.setdefault(
        operation,
        {
            "com_success": 0,
            "com_failure": 0,
            "vba_success": 0,
            "vba_failure": 0,
        },
    )
    key = f"{route}_{'success' if success else 'failure'}"
    if key in history:
        history[key] += 1

OperationProfile dataclass

OperationProfile(name: str, base_complexity: float, vba_preferred: bool = False)

Complexity profile metadata for an operation.

Attributes:

Name Type Description
base_complexity float

The base complexity value.

name str

The name value.

vba_preferred bool

The vba preferred value.

RoutingDecision

Bases: BaseModel

Complexity-based routing decision.

Attributes:

Name Type Description
complexity_score float

The complexity score value.

operation str

The operation value.

parameter_count int

The parameter count value.

prefer_vba bool

The prefer vba value.

reason str

The reason value.