MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / _dump_result

Function _dump_result

src/mcp/server/runner.py:146–157  ·  view source on GitHub ↗
(result: Any)

Source from the content-addressed store, hash-verified

144
145
146def _dump_result(result: Any) -> dict[str, Any]:
147 if result is None:
148 return {}
149 if isinstance(result, ErrorData):
150 # ErrorData is a JSON-RPC error, not a success result. Handler returns
151 # already raise in `_inner`; this catches middleware returning one.
152 raise MCPError.from_error_data(result)
153 if isinstance(result, BaseModel):
154 return result.model_dump(by_alias=True, mode="json", exclude_none=True)
155 if isinstance(result, dict):
156 return cast(dict[str, Any], result)
157 raise TypeError(f"handler returned {type(result).__name__}; expected BaseModel, dict, or None")
158
159
160async def aclose_shielded(connection: Connection) -> None:

Callers 1

_on_requestMethod · 0.85

Calls 1

from_error_dataMethod · 0.80

Tested by

no test coverage detected