MCPcopy Create free account
hub / github.com/dagger/dagger / serve

Method serve

sdk/python/src/dagger/mod/_module.py:89–114  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

87 return self.main_cls is other.cls
88
89 async def serve(self):
90 if await dag.current_function_call().parent_name():
91 result = await self.invoke()
92 else:
93 try:
94 result = await self._typedefs()
95 except TypeError as e:
96 raise RegistrationError(str(e)) from e
97
98 try:
99 output = json.dumps(result)
100 except (TypeError, ValueError) as e:
101 # Not expected to happen because unstructuring should reduce
102 # Python complex types to primitive values that are easily
103 # serialized to JSON. If not, it's something that should be caught
104 # earlier.
105 msg = f"Failed to serialize final result as JSON: {e}"
106 raise InvalidResultError(msg) from e
107
108 if logger.isEnabledFor(logging.DEBUG):
109 logger.debug(
110 "output => %s",
111 textwrap.shorten(repr(output), 144),
112 )
113
114 await dag.current_function_call().return_value(dagger.JSON(output))
115
116 async def register(self):
117 """Register the module and its types with the Dagger API."""

Callers 1

mainFunction · 0.45

Calls 9

invokeMethod · 0.95
_typedefsMethod · 0.95
RegistrationErrorClass · 0.90
InvalidResultErrorClass · 0.90
parent_nameMethod · 0.80
current_function_callMethod · 0.80
return_valueMethod · 0.80
debugMethod · 0.45
JSONMethod · 0.45

Tested by

no test coverage detected