Skip to content

serialize

serialize

Serialize crew-dcs return values into JSON-safe structures for MCP tools.

to_mcp_json

to_mcp_json(obj: Any) -> Any

Convert a crew-dcs return value into a JSON-safe Python value.

Dispatch: ResponseGetData -> .response; objects with to_mcp() -> that; DomoEntity -> .raw; list -> element-wise; dataclass -> field dict (dropping non-serializable fields like auth); otherwise the value if JSON-safe, else str().

Source code in src/crew_dcs/mcp_server/serialize.py
48
49
50
51
52
53
54
55
56
def to_mcp_json(obj: Any) -> Any:
    """Convert a crew-dcs return value into a JSON-safe Python value.

    Dispatch: ResponseGetData -> .response; objects with to_mcp() -> that;
    DomoEntity -> .raw; list -> element-wise; dataclass -> field dict (dropping
    non-serializable fields like `auth`); otherwise the value if JSON-safe, else str().
    """
    reduced = _reduce(obj)
    return str(obj) if reduced is _DROP else reduced