list_chat_sessions
Retrieve available chat sessions from the Grok MCP server to continue conversations or review previous interactions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.py:52-63 (handler)Implementation of the 'list_chat_sessions' tool. It reads JSON files from the 'chats' directory, calculates turns, and returns a formatted list of sessions.
async def list_chat_sessions(): Path("chats").mkdir(exist_ok=True) sessions = sorted(Path("chats").glob("*.json")) if not sessions: return "No chat sessions found." result = ["**Chat Sessions:**\n"] for s in sessions: history = json.loads(s.read_text()) turns = len(history) // 2 last = history[-1]["time"] if history else "empty" result.append(f"- `{s.stem}` — {turns} turn(s), last: {last}") return "\n".join(result)