Skip to main content
Glama
andybrandt

MCP Simple OpenAI Assistant

by andybrandt

delete_thread

Remove conversation threads from OpenAI servers and local databases. This permanent deletion helps manage storage and organize assistant interactions.

Instructions

Deletes a conversation thread from both OpenAI's servers and the local database. This action is irreversible.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
thread_idYes

Implementation Reference

  • MCP tool handler and registration for 'delete_thread'. Decorated with @app.tool(), it calls AssistantManager.delete_thread() and handles errors, providing user-friendly responses.
    @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's servers using the API and conditionally deletes from the 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
  • Core helper implementation in ThreadStore that performs the SQL DELETE operation to remove 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()

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/andybrandt/mcp-simple-openai-assistant'

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