create_chat
Start new 1:1 or group conversations in Microsoft Teams by specifying participant email addresses, with optional topics for group chats.
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 |
|---|---|---|---|
| userEmails | Yes | Array of user email addresses to add to chat | |
| topic | No | Chat topic (for group chats) |
Implementation Reference
- src/tools/chats.ts:347-407 (handler)Executes the creation of a new 1:1 or group chat by resolving user emails to AAD members, constructing the payload, and posting to Microsoft Graph /chats endpoint.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 validation schema for the 'create_chat' tool inputs.{ 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/types/graph.ts:101-105 (schema)TypeScript interface defining the payload structure for creating a chat via Microsoft Graph API, used in the handler.export interface CreateChatPayload { chatType: "oneOnOne" | "group"; members: ConversationMember[]; topic?: string; }
- src/tools/chats.ts:339-408 (registration)MCP server.tool registration for the 'create_chat' tool, including name, description, schema, and handler.// Create new chat (1:1 or group) server.tool( "create_chat", "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.", { 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)"), }, 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/index.ts:135-135 (registration)Top-level call to registerChatTools function which includes the 'create_chat' tool registration.registerChatTools(server, graphService);