delete_thread
Remove a conversation thread permanently from OpenAI servers and local database. This action cannot be undone.
Instructions
Deletes a conversation thread from both OpenAI's servers and the local database. This action is irreversible.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| thread_id | Yes |
Implementation Reference
- MCP tool handler for 'delete_thread', registered with @app.tool decorator. Validates manager, calls AssistantManager.delete_thread, and returns success or error message.@app.tool(annotations={"title": "Delete Managed Thread", "readOnlyHint": False}) async def delete_thread(thread_id: str) -> str: """ Deletes a conversation thread from both OpenAI's servers and the local database. This action is irreversible. """ if not manager: raise ToolError("AssistantManager not initialized.") try: result = await manager.delete_thread(thread_id) if result.deleted: return f"Successfully deleted thread {thread_id}." else: return f"Failed to delete thread {thread_id} on the server." except Exception as e: raise ToolError(f"Failed to delete thread {thread_id}: {e}")
- Helper method in AssistantManager that deletes the thread from OpenAI API and conditionally from local ThreadStore.async def delete_thread(self, thread_id: str): """Delete a thread from OpenAI and the local database.""" # First, delete the thread from OpenAI's servers result = self.client.beta.threads.delete(thread_id) # If successful, delete from the local database if result.deleted: self.thread_store.delete_thread(thread_id) return result
- Helper method in ThreadStore that deletes the thread record from the local SQLite database.def delete_thread(self, thread_id: str): """Deletes a thread record from the database by its thread_id. Args: thread_id: The ID of the thread to delete. """ conn = self._get_connection() cursor = conn.cursor() cursor.execute("DELETE FROM threads WHERE thread_id = ?", (thread_id,)) conn.commit()