start_thread
Create a new thread in Microsoft Teams with a specified title and content, and optionally mention a member.
Instructions
Start a new thread with a given title and content
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | The thread title | |
| content | Yes | The thread content | |
| 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' | |
| title | Yes | Message title | |
| content | Yes | Message content |
Implementation Reference
- src/mcp_teams_server/__init__.py:107-109 (registration)MCP tool registration for 'start_thread' via the @mcp.tool decorator, defining its name and description.
@mcp.tool( name="start_thread", description="Start a new thread with a given title and content" ) - src/mcp_teams_server/__init__.py:110-120 (handler)Handler function that receives the MCP tool call, extracts the TeamsClient from context, and delegates to client.start_thread().
async def start_thread( ctx: Context, title: str = Field(description="The thread title"), content: str = Field(description="The thread content"), member_name: str | None = Field( description="Member name to mention in the thread", default=None ), ) -> TeamsThread: await ctx.debug(f"start_thread with title={title} and content={content}") client = _get_teams_client(ctx) return await client.start_thread(title, content, member_name) - src/mcp_teams_server/teams.py:142-205 (handler)Core business logic of start_thread in TeamsClient. Creates an Activity with topic_name=title, sends it via the bot adapter, and returns the resulting TeamsThread with its ID.
async def start_thread( self, title: str, content: str, member_name: str | None = None ) -> TeamsThread: """Start a new thread in a channel. Args: title: Thread title content: Initial thread content member_name: Member name to mention in content Returns: Created thread details including ID """ try: await self._initialize() result = TeamsThread(title=title, content=content, thread_id="") async def start_thread_callback(context: TurnContext): mention_member = await self._get_mention_member(context, member_name) mentions = [] if mention_member is not None: result.content = ( f"# **{title}**\n<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) try: activity = Activity( type=ActivityTypes.message, from_property=ChannelAccount( id=self.teams_app_id, name=MCP_BOT_NAME), # type: ignore channel_id="msteams", # type: ignore conversation=context.activity.conversation, topic_name=title, text=result.content, text_format=TextFormatTypes.markdown, entities=mentions, ) responses = await self.adapter.send_activities(context, [activity]) response = responses[0] if responses else None if response is not None: result.thread_id = response.id except Exception as ae: LOGGER.exception(ae) await self.adapter.continue_conversation( agent_app_id=self.teams_app_id, continuation_activity=self._create_continuation_activity(), callback=start_thread_callback, ) return result except Exception as e: LOGGER.error(f"Error creating thread: {str(e)}") raise - src/mcp_teams_server/teams.py:39-44 (schema)Return type schema for start_thread - a Pydantic BaseModel with thread_id, title, and content fields.
class TeamsThread(BaseModel): thread_id: str = Field( description="Thread ID as a string in the format '1743086901347'" ) title: str = Field(description="Message title") content: str = Field(description="Message content") - Helper function that extracts the TeamsClient from the FastMCP lifespan context, used by the handler to access the client.
def _get_teams_client(ctx: Context) -> TeamsClient: return ctx.request_context.lifespan_context.client