update_thread
Modify an existing Microsoft Teams thread by adding new content or mentioning a member. Use the thread ID and desired content to update discussions efficiently.
Instructions
Update an existing thread with new content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes | The content to update in the thread | |
| member_name | No | Member name to mention in the thread | |
| thread_id | Yes | The thread ID as a string in the format '1743086901347' |
Implementation Reference
- src/mcp_teams_server/__init__.py:124-139 (handler)MCP tool handler for update_thread: registers the tool, defines input schema via Field, and delegates to TeamsClient.update_thread@mcp.tool( name="update_thread", description="Update an existing thread with new content" ) async def update_thread( ctx: Context, thread_id: str = Field( description="The thread ID as a string in the format '1743086901347'" ), content: str = Field(description="The content to update in the thread"), member_name: str | None = Field( description="Member name to mention in the thread", default=None ), ) -> TeamsMessage: await ctx.debug(f"update_thread with thread_id={thread_id} and content={content}") client = _get_teams_client(ctx) return await client.update_thread(thread_id, content, member_name)
- Core implementation of update_thread in TeamsClient: initializes service, creates mention if member_name provided, sends reply activity to thread using BotFramework ConversationsOperationsasync def update_thread( self, thread_id: str, content: str, member_name: str | None = None ) -> TeamsMessage: """Add a message to an existing thread, mentioning a user optionally. Args: thread_id: Thread ID to update content: Message content to add member_name: Member name to mention (optional) Returns: Updated thread details """ try: await self._initialize() result = TeamsMessage(thread_id=thread_id, content=content, message_id="") async def update_thread_callback(context: TurnContext): mention_member = None if member_name is not None: members = await TeamsInfo.get_team_members(context, self.team_id) for member in members: if member.name == member_name: mention_member = member mentions = [] if mention_member is not None: result.content = f"<at>{mention_member.name}</at> {content}" mention = Mention( text=f"<at>{mention_member.name}</at>", type="mention", mentioned=ChannelAccount( id=mention_member.id, name=mention_member.name ), ) mentions.append(mention) reply = Activity( type=ActivityTypes.message, text=result.content, from_property=TeamsChannelAccount( id=self.teams_app_id, name="MCP Bot" ), conversation=ConversationAccount(id=thread_id), entities=mentions, ) # # Hack to get the connector client and reply to an existing activity # conversations = TeamsClient._get_conversation_operations(context) # # Hack to reply to conversation https://github.com/microsoft/botframework-sdk/issues/6626 # conversation_id = ( f"{context.activity.conversation.id};messageid={thread_id}" # pyright: ignore ) response = await conversations.send_to_conversation( conversation_id=conversation_id, activity=reply ) if response is not None: result.message_id = response.id # pyright: ignore await self.adapter.continue_conversation( bot_app_id=self.teams_app_id, reference=self._create_conversation_reference(), callback=update_thread_callback, ) return result except Exception as e: LOGGER.error(f"Error updating thread: {str(e)}") raise
- src/mcp_teams_server/teams.py:44-50 (schema)Pydantic model TeamsMessage defining output schema for update_threadclass TeamsMessage(BaseModel): thread_id: str = Field( description="Thread ID as a string in the format '1743086901347'" ) message_id: str = Field(description="Message ID") content: str = Field(description="Message content")
- src/mcp_teams_server/__init__.py:124-139 (registration)Tool registration via @mcp.tool decorator in __init__.py@mcp.tool( name="update_thread", description="Update an existing thread with new content" ) async def update_thread( ctx: Context, thread_id: str = Field( description="The thread ID as a string in the format '1743086901347'" ), content: str = Field(description="The content to update in the thread"), member_name: str | None = Field( description="Member name to mention in the thread", default=None ), ) -> TeamsMessage: await ctx.debug(f"update_thread with thread_id={thread_id} and content={content}") client = _get_teams_client(ctx) return await client.update_thread(thread_id, content, member_name)
- Inner callback function used by TeamsClient.update_thread to send the update message to the threadasync def update_thread_callback(context: TurnContext): mention_member = None if member_name is not None: members = await TeamsInfo.get_team_members(context, self.team_id) for member in members: if member.name == member_name: mention_member = member mentions = [] if mention_member is not None: result.content = f"<at>{mention_member.name}</at> {content}" mention = Mention( text=f"<at>{mention_member.name}</at>", type="mention", mentioned=ChannelAccount( id=mention_member.id, name=mention_member.name ), ) mentions.append(mention) reply = Activity( type=ActivityTypes.message, text=result.content, from_property=TeamsChannelAccount( id=self.teams_app_id, name="MCP Bot" ), conversation=ConversationAccount(id=thread_id), entities=mentions, ) # # Hack to get the connector client and reply to an existing activity # conversations = TeamsClient._get_conversation_operations(context) # # Hack to reply to conversation https://github.com/microsoft/botframework-sdk/issues/6626 # conversation_id = ( f"{context.activity.conversation.id};messageid={thread_id}" # pyright: ignore ) response = await conversations.send_to_conversation( conversation_id=conversation_id, activity=reply ) if response is not None: result.message_id = response.id # pyright: ignore