Handle tasks/result — retrieve and format the callback result. Uses the framework's background callback retrieval functions (``_update_background_callback`` and ``_prepare_response``) with ``cache_key`` and ``job_id`` supplied directly, bypassing the request adapter query-param look
(task_id: str)
| 104 | |
| 105 | |
| 106 | def get_task_result(task_id: str) -> Any: |
| 107 | """Handle tasks/result — retrieve and format the callback result. |
| 108 | |
| 109 | Uses the framework's background callback retrieval functions |
| 110 | (``_update_background_callback`` and ``_prepare_response``) with |
| 111 | ``cache_key`` and ``job_id`` supplied directly, bypassing the |
| 112 | request adapter query-param lookup. |
| 113 | """ |
| 114 | tool_name, job_id, cache_key, _created_at = parse_task_id(task_id) |
| 115 | |
| 116 | manager = _get_callback_manager(tool_name) |
| 117 | if manager is None: |
| 118 | raise MCPError("No background callback manager configured.") |
| 119 | |
| 120 | app = get_app() |
| 121 | adapter = app.mcp_callback_map.find_by_tool_name(tool_name) |
| 122 | if adapter is None: |
| 123 | raise MCPError(f"Task not found: {tool_name}") |
| 124 | # pylint: disable-next=protected-access |
| 125 | cb_info = adapter._cb_info |
| 126 | background = cb_info.get("background") |
| 127 | has_output = not cb_info.get("no_output") |
| 128 | multi = adapter.output_id.startswith("..") |
| 129 | output = split_callback_id(adapter.output_id) |
| 130 | |
| 131 | # Build the body to get output_spec, same as as_callback_body |
| 132 | body = adapter.as_callback_body({}) |
| 133 | output_spec = body.get("outputs", []) |
| 134 | |
| 135 | callback_ctx = AttributeDict({"updated_props": {}}) |
| 136 | response: CallbackExecutionResponse = {"multi": True} |
| 137 | |
| 138 | output_value, has_update, skip = _update_background_callback( |
| 139 | error_handler=None, |
| 140 | callback_ctx=callback_ctx, |
| 141 | response=response, |
| 142 | kwargs={"background_callback_manager": manager}, |
| 143 | background=background, |
| 144 | multi=multi, |
| 145 | cache_key=cache_key, |
| 146 | job_id=job_id, |
| 147 | ) |
| 148 | |
| 149 | if skip: |
| 150 | # Result not ready — still polling |
| 151 | raise MCPError( |
| 152 | "Task result not ready. Poll tasks/get until status is 'completed'." |
| 153 | ) |
| 154 | |
| 155 | _prepare_response( |
| 156 | output_value, |
| 157 | output_spec, |
| 158 | multi, |
| 159 | response, |
| 160 | callback_ctx, |
| 161 | app, |
| 162 | set(ComponentRegistry.registry), |
| 163 | background, |
no test coverage detected
searching dependent graphs…