retrieve_stateful_response
Fetch previously saved conversation responses from xAI servers to review past interactions or recover lost conversations using response IDs from the last 30 days.
Instructions
Fetches a previously saved stateful conversation response from xAI's servers.
Use this to look up old conversations or check what was said in a previous
exchange. Helpful if you lost track of a conversation or want to review past
interactions. Works with any response_id from the last 30 days.
Args:
response_id: The ID of the response you want to retrieve
Returns a dict with all the details: 'content', 'response_id', 'model',
'created_at', 'status', 'reasoning' (if available), 'usage', and
'previous_response_id' (if it was part of a chain).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| response_id | Yes |
Implementation Reference
- src/server.py:591-643 (handler)The core handler function for the 'retrieve_stateful_response' tool. It is decorated with @mcp.tool(), which also handles registration in the FastMCP server. The function fetches the stateful response from xAI's API using the provided response_id, parses the output to extract content and reasoning, and returns a structured dictionary with the response details.@mcp.tool() async def retrieve_stateful_response(response_id: str) -> Dict[str, Any]: """ Fetches a previously saved stateful conversation response from xAI's servers. Use this to look up old conversations or check what was said in a previous exchange. Helpful if you lost track of a conversation or want to review past interactions. Works with any response_id from the last 30 days. Args: response_id: The ID of the response you want to retrieve Returns a dict with all the details: 'content', 'response_id', 'model', 'created_at', 'status', 'reasoning' (if available), 'usage', and 'previous_response_id' (if it was part of a chain). """ client = create_client(use_state=True) response = await client.get(f"/v1/responses/{response_id}") response.raise_for_status() data = response.json() output = data.get("output", []) content = "" reasoning = None #for getting text of reasoning or pass reasoning for item in output: if item.get("type") == "message" and item.get("role") == "assistant": for content_item in item.get("content", []): if content_item.get("type") == "output_text": content = content_item.get("text", "") break elif item.get("type") == "reasoning": for summary_item in item.get("summary", []): if summary_item.get("type") == "summary_text": reasoning = summary_item.get("text", "") break await client.aclose() return { "response_id": data.get("id"), "model": data.get("model"), "created_at": datetime.fromtimestamp(data.get("created_at", 0)).isoformat(), "status": data.get("status"), "content": content, "reasoning": reasoning, "usage": data.get("usage", {}), "previous_response_id": data.get("previous_response_id"), "store": data.get("store", False) }
- src/server.py:591-591 (registration)The @mcp.tool() decorator registers the retrieve_stateful_response function as an MCP tool in the FastMCP server.@mcp.tool()