update_thread
Update an existing Microsoft Teams thread with new content to keep conversations current. Optionally mention a member to notify them.
Instructions
Update an existing thread with new content
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| thread_id | Yes | The thread ID as a string in the format '1743086901347' | |
| content | Yes | The content to update in the thread | |
| member_name | No | Member name to mention in the thread |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| thread_id | Yes | Thread ID as a string in the format '1743086901347' | |
| message_id | Yes | Message ID | |
| content | Yes | Message content |
Implementation Reference
- src/mcp_teams_server/__init__.py:123-138 (handler)MCP tool handler for 'update_thread' - receives thread_id, content, and optional member_name, then 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) - src/mcp_teams_server/__init__.py:123-125 (registration)Registration of the 'update_thread' tool via @mcp.tool decorator with name and description
@mcp.tool( name="update_thread", description="Update an existing thread with new content" ) - src/mcp_teams_server/teams.py:47-53 (schema)Return type schema (TeamsMessage) for the update_thread tool
class 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 | None = Field(description="Message content") - src/mcp_teams_server/teams.py:213-278 (handler)Core logic of update_thread: initializes the client, creates a message with optional mention, sends it to the thread conversation via the Teams connector API, and returns the result with thread_id/message_id
async 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 = await self._get_mention_member(context, member_name) 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>", mentioned=ChannelAccount( id=mention_member.id, name=mention_member.name ), ) mentions.append(mention) reply = Activity( type=ActivityTypes.message, text=result.content, from_property=ChannelAccount(id=self.teams_app_id, name=MCP_BOT_NAME), # type: ignore 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, body=reply ) if response is not None: result.message_id = response.id # pyright: ignore await self.adapter.continue_conversation( agent_app_id=self.teams_app_id, continuation_activity=self._create_continuation_activity(), callback=update_thread_callback, ) return result except Exception as e: LOGGER.error(f"Error updating thread: {str(e)}") raise - Helper used by update_thread to get the ConversationsOperations from the TurnContext for sending messages
@staticmethod def _get_conversation_operations(context: TurnContext) -> ConversationsOperations: # Hack to get the connector client and reply to an existing activity connector_client = context.turn_state["ConnectorClient"] return connector_client.conversations # type: ignore