list_threads
Retrieve all saved conversation threads with their details including ID, name, description, and last used time to continue previous discussions.
Instructions
Lists all locally saved conversation threads from the database. Returns a list of threads with their ID, name, description, and last used time. The thread ID can be used in the ask_assistant_in_thread tool to specify this thread to be continued.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_simple_openai_assistant/app.py:65-90 (handler)MCP tool handler implementation for 'list_threads'. Decorated with @app.tool, it retrieves threads via the AssistantManager and formats them into a readable string output.@app.tool(annotations={"title": "List Managed Threads", "readOnlyHint": True}) async def list_threads() -> str: """ Lists all locally saved conversation threads from the database. Returns a list of threads with their ID, name, description, and last used time. The thread ID can be used in the ask_assistant_in_thread tool to specify this thread to be continued. """ if not manager: raise ToolError("AssistantManager not initialized.") try: threads = manager.list_threads() if not threads: return "No managed threads found." thread_list = [ dedent(f""" Thread ID: {t['thread_id']} Name: {t['name']} Description: {t['description']} Last Used: {t['last_used_at']} """) for t in threads ] return "Managed Threads:\\n\\n" + "\\n---\\n".join(thread_list) except Exception as e: raise ToolError(f"Failed to list threads: {e}")
- Helper method in AssistantManager that delegates the list_threads call to the underlying ThreadStore instance.def list_threads(self) -> list[sqlite3.Row]: """List all managed threads from the local database.""" return self.thread_store.list_threads()
- Core data access helper in ThreadStore that executes the SQL query to fetch all threads from the local SQLite database, ordered by last used time.def list_threads(self) -> list[sqlite3.Row]: """Retrieves all thread records from the database. Returns: A list of rows, where each row is a dictionary-like object representing a thread. """ conn = self._get_connection() cursor = conn.cursor() cursor.execute("SELECT * FROM threads ORDER BY last_used_at DESC") return cursor.fetchall()