Skip to main content
Glama

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
NameRequiredDescriptionDefault
userEmailsYesArray of user email addresses to add to chat
topicNoChat topic (for group chats)

Implementation Reference

  • 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}`,
            },
          ],
        };
      }
    }
  • 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)"),
    },
  • 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;
    }
  • 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);

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/floriscornel/teams-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server