create_chat
Generate new chat conversations in Microsoft Teams by specifying user emails for 1:1 chats or group discussions. Optionally set a topic for group chats to enhance organization and context.
Instructions
Create a new chat conversation. Can be a 1:1 chat (with one other user) or a group chat (with multiple users). Group chats can optionally have a topic.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic | No | Chat topic (for group chats) | |
| userEmails | Yes | Array of user email addresses to add to chat |
Implementation Reference
- src/tools/chats.ts:347-407 (handler)The handler function that implements the create_chat tool logic: resolves users by email, builds the chat payload using CreateChatPayload type, and creates the chat via Microsoft Graph API.async ({ userEmails, topic }) => { try { const client = await graphService.getClient(); // Get current user ID const me = (await client.api("/me").get()) as User; // Create members array const members: ConversationMember[] = [ { "@odata.type": "#microsoft.graph.aadUserConversationMember", user: { id: me?.id, }, roles: ["owner"], } as ConversationMember, ]; // Add other users as members for (const email of userEmails) { const user = (await client.api(`/users/${email}`).get()) as User; members.push({ "@odata.type": "#microsoft.graph.aadUserConversationMember", user: { id: user?.id, }, roles: ["member"], } as ConversationMember); } const chatData: CreateChatPayload = { chatType: userEmails.length === 1 ? "oneOnOne" : "group", members, }; if (topic && userEmails.length > 1) { chatData.topic = topic; } const newChat = (await client.api("/chats").post(chatData)) as Chat; return { content: [ { type: "text", text: `✅ Chat created successfully. Chat ID: ${newChat?.id}`, }, ], }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : "Unknown error occurred"; return { content: [ { type: "text", text: `❌ Error: ${errorMessage}`, }, ], }; } }
- src/tools/chats.ts:343-346 (schema)Zod schema defining the input parameters for the create_chat tool.{ userEmails: z.array(z.string()).describe("Array of user email addresses to add to chat"), topic: z.string().optional().describe("Chat topic (for group chats)"), },
- src/tools/chats.ts:340-341 (registration)Registration of the create_chat tool using server.tool.server.tool( "create_chat",
- src/types/graph.ts:101-105 (schema)TypeScript interface defining the payload structure for creating a chat, used in the handler.export interface CreateChatPayload { chatType: "oneOnOne" | "group"; members: ConversationMember[]; topic?: string; }