Skip to main content
Glama
andybrandt

MCP Simple OpenAI Assistant

by andybrandt

Ask Assistant in Thread and Stream Response

ask_assistant_in_thread

Send messages to OpenAI assistants within existing conversation threads and receive streaming responses for continuous dialogue management.

Instructions

Sends a message to an assistant within a specific thread and streams the response. This provides progress updates and the final message in a single call.

Use this to continue a conversation with an assistant in a specific thread. The thread ID can be retrieved from the list_threads tool. The assistant ID can be retrieved from the list_assistants tool. Threads are not inherently linked to a particular assistant, so you can use this tool to talk to any assistant in any thread.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
thread_idYes
assistant_idYes
messageYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function that executes the tool logic: sends message to thread, streams assistant response events, accumulates final message, and reports progress via ctx.
    async def ask_assistant_in_thread(thread_id: str, assistant_id: str, message: str, ctx: Context) -> str:
        """
        Sends a message to an assistant within a specific thread and streams the response.
        This provides progress updates and the final message in a single call.
    
        Use this to continue a conversation with an assistant in a specific thread.
        The thread ID can be retrieved from the list_threads tool.
        The assistant ID can be retrieved from the list_assistants tool.
        Threads are not inherently linked to a particular assistant, so you can use this tool to talk to any assistant in any thread.
        """
        if not manager:
            raise ToolError("AssistantManager not initialized.")
    
        final_message = ""
        try:
            await ctx.report_progress(progress=0, message="Starting assistant run...")
            async for event in manager.run_thread(thread_id, assistant_id, message):
                if event.event == 'thread.message.delta':
                    text_delta = event.data.delta.content[0].text
                    final_message += text_delta.value
                    await ctx.report_progress(progress=50, message=f"Assistant writing: {final_message}")
                elif event.event == 'thread.run.step.created':
                    await ctx.report_progress(progress=25, message="Assistant is performing a step...")
            
            await ctx.report_progress(progress=100, message="Run complete.")
            return final_message
    
        except Exception as e:
            raise ToolError(f"An error occurred during the run: {e}")
  • FastMCP decorator that registers the ask_assistant_in_thread function as a tool with title and readOnlyHint metadata.
    @app.tool(
        annotations={
            "title": "Ask Assistant in Thread and Stream Response",
            "readOnlyHint": False
        }
    )
  • Supporting async generator that updates thread usage, adds user message, creates and streams the assistant run events, used by the tool handler.
    async def run_thread(
        self,
        thread_id: str,
        assistant_id: str,
        message: str
    ):
        """
        Sends a message to a thread and streams the assistant's response.
        This is an async generator that yields events from the run.
        """
        # Update the last used timestamp
        self.thread_store.update_thread_last_used(thread_id)
    
        # Add the user's message to the thread
        self.client.beta.threads.messages.create(
            thread_id=thread_id,
            role="user",
            content=message
        )
    
        # Stream the assistant's response
        stream = self.client.beta.threads.runs.create(
            thread_id=thread_id,
            assistant_id=assistant_id,
            stream=True
        )
        for event in stream:
            yield event 
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description adds valuable behavioral context beyond annotations: it explains the streaming nature ('provides progress updates and the final message in a single call'), clarifies that threads aren't inherently linked to assistants, and mentions the conversational context. While annotations only provide readOnlyHint=false and title, the description meaningfully expands on operational behavior without contradicting annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement first, followed by usage guidance. Every sentence adds value: the first explains the core functionality, the second provides context for use, and the third clarifies parameter relationships. No redundant or unnecessary information is included.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's conversational nature, 3 parameters with 0% schema coverage, readOnlyHint=false annotation, and presence of an output schema, the description is complete. It covers purpose, usage context, parameter semantics, and behavioral aspects like streaming. The output schema handles return values, so the description appropriately focuses on operational guidance.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must compensate for the lack of parameter documentation in the schema. It effectively explains the purpose and source of all three required parameters (thread_id, assistant_id, message) by describing their roles in the operation and how to obtain them, though it doesn't provide format or validation details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('sends a message to an assistant within a specific thread and streams the response'), identifies the resource (assistant, thread), and distinguishes from siblings by emphasizing streaming and thread/assistant combination. It explicitly mentions this is for continuing conversations, which differentiates it from thread creation tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool ('to continue a conversation with an assistant in a specific thread'), how to obtain required parameters (thread_id from list_threads, assistant_id from list_assistants), and clarifies the relationship between threads and assistants. It effectively distinguishes this from sibling tools like create_new_assistant_thread.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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