Skip to content

solidworks_mcp.selftest.results

solidworks_mcp.selftest.results

What a selftest run produces: checks, area results, and the tool caller.

Classes

AreaResult dataclass

AreaResult(name: str, outcome: Outcome, checks: list[Check] = list(), calls: list[str] = list(), note: str | None = None)

One area's outcome, its checks, the tools it called, and why if not PASS.

Attributes
passed_count property
passed_count: int

The number of checks that passed.

Check dataclass

Check(name: str, expected: Any, measured: Any, tolerance: Any = None, unit: str = '', passed: bool | None = None)

One value read back from SolidWorks against the hand calculation.

passed is None when the value could not be measured, which counts as a failure.

Outcome

Bases: StrEnum

An area's result.

ToolCaller

ToolCaller(client: Any)

Call MCP tools by name with dict input, as a client does; log each call.

Wrap a connected fastmcp.Client.

Parameters:

Name Type Description Default
client Any

The client, already entered.

required
Source code in src/solidworks_mcp/selftest/results.py
def __init__(self, client: Any) -> None:
    """Wrap a connected ``fastmcp.Client``.

    Args:
        client: The client, already entered.
    """
    self._client = client
    self.calls: list[str] = []
Methods:
__call__ async
__call__(name: str, args: dict[str, Any] | None = None, record: bool = True) -> dict[str, Any]

Call name and return its reply; raise when it reports an error.

Parameters:

Name Type Description Default
name str

The tool's name.

required
args dict[str, Any] | None

Its input, sent as input_data; None for a tool without input.

None
record bool

Whether the call is listed in the report.

True

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The tool's reply.

Raises:

Type Description
ToolFailed

The tool replied with status: error.

Source code in src/solidworks_mcp/selftest/results.py
async def __call__(
    self, name: str, args: dict[str, Any] | None = None, record: bool = True
) -> dict[str, Any]:
    """Call ``name`` and return its reply; raise when it reports an error.

    Args:
        name: The tool's name.
        args: Its input, sent as ``input_data``; ``None`` for a tool
            without input.
        record: Whether the call is listed in the report.

    Returns:
        dict[str, Any]: The tool's reply.

    Raises:
        ToolFailed: The tool replied with ``status: error``.
    """
    if record:
        self.calls.append(name)
    result = await self._client.call_tool(
        name, {} if args is None else {"input_data": args}, raise_on_error=False
    )
    reply = tool_reply(result)
    if reply.get("status") != "success":
        raise ToolFailed(name, str(reply.get("message") or "no message"))
    return reply

ToolFailed

ToolFailed(tool: str, message: str)

Bases: Exception

A tool call returned status: error.

Remember which tool failed and its message.

Parameters:

Name Type Description Default
tool str

The tool's name.

required
message str

The tool's error message.

required
Source code in src/solidworks_mcp/selftest/results.py
def __init__(self, tool: str, message: str) -> None:
    """Remember which tool failed and its message.

    Args:
        tool: The tool's name.
        message: The tool's error message.
    """
    super().__init__(f"{tool} failed: {message}")
    self.tool = tool
    self.message = message
Methods:

Functions:

tool_reply

tool_reply(result: Any) -> dict[str, Any]

A FastMCP client's tool result as the payload dict an agent sees.

Parameters:

Name Type Description Default
result Any

The CallToolResult from Client.call_tool.

required

Returns:

Type Description
dict[str, Any]

dict[str, Any]: The tool's reply.

Source code in src/solidworks_mcp/selftest/results.py
def tool_reply(result: Any) -> dict[str, Any]:
    """A FastMCP client's tool result as the payload dict an agent sees.

    Args:
        result: The ``CallToolResult`` from ``Client.call_tool``.

    Returns:
        dict[str, Any]: The tool's reply.
    """
    data = result.structured_content
    if isinstance(data, dict) and set(data) == {"result"}:
        data = data["result"]
    if isinstance(data, dict):
        return data
    text = "".join(getattr(c, "text", "") for c in result.content)
    try:
        parsed = json.loads(text)
    except ValueError:
        parsed = None
    if isinstance(parsed, dict):
        return parsed
    return {"status": "error" if result.is_error else "success", "message": text}