Skip to main content
Glama

list_chats

Retrieve recent Microsoft Teams conversations including 1:1 chats and group discussions with participant details and chat topics.

Instructions

List all recent chats (1:1 conversations and group chats) that the current user participates in. Returns chat topics, types, and participant information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_chats' tool. Fetches the user's chats from Microsoft Graph API using /me/chats?$expand=members, maps to ChatSummary with id, topic, type, members, and returns as JSON string in MCP content format. Handles no chats and errors.
        try {
          // Build query parameters
          const queryParams: string[] = ["$expand=members"];
    
          const queryString = queryParams.join("&");
    
          const client = await graphService.getClient();
          const response = (await client
            .api(`/me/chats?${queryString}`)
            .get()) as GraphApiResponse<Chat>;
    
          if (!response?.value?.length) {
            return {
              content: [
                {
                  type: "text",
                  text: "No chats found.",
                },
              ],
            };
          }
    
          const chatList: ChatSummary[] = response.value.map((chat: Chat) => ({
            id: chat.id,
            topic: chat.topic || "No topic",
            chatType: chat.chatType,
            members:
              chat.members?.map((member: ConversationMember) => member.displayName).join(", ") ||
              "No members",
          }));
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(chatList, null, 2),
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
          return {
            content: [
              {
                type: "text",
                text: `❌ Error: ${errorMessage}`,
              },
            ],
          };
        }
      }
    );
  • MCP server.tool registration for 'list_chats' tool within registerChatTools function. Includes description, empty input schema ({}), and inline handler.
      "list_chats",
      "List all recent chats (1:1 conversations and group chats) that the current user participates in. Returns chat topics, types, and participant information.",
      {},
      async () => {
        try {
          // Build query parameters
          const queryParams: string[] = ["$expand=members"];
    
          const queryString = queryParams.join("&");
    
          const client = await graphService.getClient();
          const response = (await client
            .api(`/me/chats?${queryString}`)
            .get()) as GraphApiResponse<Chat>;
    
          if (!response?.value?.length) {
            return {
              content: [
                {
                  type: "text",
                  text: "No chats found.",
                },
              ],
            };
          }
    
          const chatList: ChatSummary[] = response.value.map((chat: Chat) => ({
            id: chat.id,
            topic: chat.topic || "No topic",
            chatType: chat.chatType,
            members:
              chat.members?.map((member: ConversationMember) => member.displayName).join(", ") ||
              "No members",
          }));
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(chatList, null, 2),
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
          return {
            content: [
              {
                type: "text",
                text: `❌ Error: ${errorMessage}`,
              },
            ],
          };
        }
      }
    );
  • src/index.ts:135-136 (registration)
    Top-level call to registerChatTools(server, graphService) in main MCP server setup, which registers the list_chats tool among others.
    registerChatTools(server, graphService);
    registerSearchTools(server, graphService);
  • ChatSummary interface used in the list_chats handler to type the returned chat list. Defined with optional id, topic, chatType, memberCount.
    export interface ChatSummary {
      id?: string | undefined;
      topic?: NullableOption<string> | undefined;
      chatType?: ChatType | undefined;
      memberCount?: number | undefined;
    }

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