read_thread
Retrieve all replies in a Microsoft Teams thread by providing the thread ID.
Instructions
Read replies in a thread
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| thread_id | Yes | The thread ID as a string in the format '1743086901347' |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cursor | Yes | Cursor to retrieve the next page of messages. | |
| limit | Yes | Page limit, maximum number of items to retrieve | |
| total | Yes | Total items available for retrieval | |
| items | Yes | List of channel messages or threads |
Implementation Reference
- src/mcp_teams_server/__init__.py:141-150 (handler)MCP tool handler for 'read_thread'. Decorated with @mcp.tool, takes a thread_id parameter, calls client.read_thread_replies(thread_id, 50).
@mcp.tool(name="read_thread", description="Read replies in a thread") async def read_thread( ctx: Context, thread_id: str = Field( description="The thread ID as a string in the format '1743086901347'" ), ) -> PagedTeamsMessages: await ctx.debug(f"read_thread with thread_id={thread_id}") client = _get_teams_client(ctx) return await client.read_thread_replies(thread_id, 50) - The actual implementation in TeamsClient.read_thread_replies(). Makes a Microsoft Graph API call to fetch replies for a given thread_id, with optional pagination via cursor. Returns PagedTeamsMessages.
async def read_thread_replies( self, thread_id: str, limit: int = 50, cursor: str | None = None ) -> PagedTeamsMessages: """Read all replies in a thread. Args: thread_id: Thread ID to read cursor: The pagination cursor limit: The pagination page size Returns: List of thread messages """ try: params = RepliesRequestBuilder.RepliesRequestBuilderGetQueryParameters( top=limit ) request = RequestConfiguration(query_parameters=params) if cursor is not None: replies = ( await self.graph_client.teams.by_team_id(self.team_id) .channels.by_channel_id(self.teams_channel_id) .messages.by_chat_message_id(thread_id) .replies.with_url(cursor) .get(request_configuration=request) ) else: replies = ( await self.graph_client.teams.by_team_id(self.team_id) .channels.by_channel_id(self.teams_channel_id) .messages.by_chat_message_id(thread_id) .replies.get(request_configuration=request) ) result = PagedTeamsMessages( cursor=cursor, limit=limit, total=replies.odata_count, # pyright: ignore items=[], ) if replies is not None and replies.value is not None: for reply in replies.value: result.items.append( TeamsMessage( message_id=reply.id, # pyright: ignore content=reply.body.content, # pyright: ignore thread_id=reply.reply_to_id, # pyright: ignore ) ) return result except Exception as e: LOGGER.error(f"Error reading thread: {str(e)}") - src/mcp_teams_server/teams.py:62-68 (schema)PagedTeamsMessages response model: contains cursor, limit, total, and items (list of TeamsMessage).
class PagedTeamsMessages(BaseModel): cursor: str | None = Field( description="Cursor to retrieve the next page of messages." ) limit: int = Field(description="Page limit, maximum number of items to retrieve") total: int = Field(description="Total items available for retrieval") items: list[TeamsMessage] = Field(description="List of channel messages or threads") - src/mcp_teams_server/teams.py:47-52 (schema)TeamsMessage model used in PagedTeamsMessages: contains thread_id, message_id, and content.
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/__init__.py:141-141 (registration)The @mcp.tool decorator registers 'read_thread' as an MCP tool with the description 'Read replies in a thread'.
@mcp.tool(name="read_thread", description="Read replies in a thread")