MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / _coerce_args

Function _coerce_args

src/ifcmcp/ifcmcp/embedded.py:19–41  ·  view source on GitHub ↗

Convert JS objects / JsProxy / mappings into a real Python dict.

(args: Any)

Source from the content-addressed store, hash-verified

17
18
19def _coerce_args(args: Any) -> dict[str, Any]:
20 """Convert JS objects / JsProxy / mappings into a real Python dict."""
21 if args is None:
22 return {}
23
24 # Pyodide: JS object arrives as JsProxy; convert recursively to Python.
25 if JsProxy is not None and isinstance(args, JsProxy):
26 # dict_converter=dict ensures JS object -> Python dict (not Map)
27 return to_py(args, dict_converter=dict)
28
29 # Already a Python dict
30 if isinstance(args, dict):
31 return args
32
33 # Any Mapping-like object
34 if isinstance(args, Mapping):
35 return dict(args)
36
37 # Last resort: try dict() coercion
38 try:
39 return dict(args)
40 except Exception as e:
41 raise TypeError(f"Tool args must be a mapping/dict; got {type(args)}") from e
42
43
44def tools_openai() -> list[dict[str, Any]]:

Callers 1

call_toolFunction · 0.85

Calls 1

typeFunction · 0.50

Tested by

no test coverage detected