Skip to main content
Glama

retrieve_stateful_response

Retrieve previous responses from the Grok MCP server using a response ID to maintain conversation continuity and access stored interactions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
response_idYes

Implementation Reference

  • The retrieve_stateful_response tool handler - retrieves a previously stored chat completion by response_id using the XAI client's get_stored_completion method, returns the response content and ID, or an error message if not found.
    @mcp.tool() async def retrieve_stateful_response(response_id: str): client = Client(api_key=XAI_API_KEY) responses = client.chat.get_stored_completion(response_id) client.close() if not responses: return f"No response found for id {response_id}" response = responses[0] if isinstance(responses, list) else responses return f"{response.content}\n\n**Response ID:** `{response.id}`"
  • src/server.py:420-420 (registration)
    Tool registration via @mcp.tool() decorator that exposes retrieve_stateful_response as an MCP tool.
    @mcp.tool()
  • Related stateful_chat tool that creates stateful chat sessions and returns response IDs which can later be retrieved using retrieve_stateful_response.
    @mcp.tool() async def stateful_chat( prompt: str, model: str = "grok-4", response_id: Optional[str] = None, system_prompt: Optional[str] = None ): client = Client(api_key=XAI_API_KEY) chat_params = {"model": model, "store_messages": True} if response_id: chat_params["previous_response_id"] = response_id chat = client.chat.create(**chat_params) if system_prompt and not response_id: chat.append(system(system_prompt)) chat.append(user(prompt)) response = chat.sample() client.close() return f"{response.content}\n\n**Response ID:** `{response.id}`"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/merterbak/Grok-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server