Skip to main content
Glama

get_my_mentions

Retrieve recent Microsoft Teams messages where you were mentioned across channels and chats, with customizable time range and scope filters.

Instructions

Find all recent messages where the current user was mentioned (@mentioned) across Teams channels and chats.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hoursNoGet mentions from the last N hours
limitNoMaximum number of mentions to return
scopeNoScope of searchall

Implementation Reference

  • Registration of the 'get_my_mentions' tool using server.tool(), including description, input schema, and handler function.
    server.tool(
      "get_my_mentions",
      "Find all recent messages where the current user was mentioned (@mentioned) across Teams channels and chats.",
      {
        hours: z
          .number()
          .min(1)
          .max(168)
          .optional()
          .default(24)
          .describe("Get mentions from the last N hours"),
        limit: z
          .number()
          .min(1)
          .max(50)
          .optional()
          .default(20)
          .describe("Maximum number of mentions to return"),
        scope: z
          .enum(["all", "channels", "chats"])
          .optional()
          .default("all")
          .describe("Scope of search"),
      },
      async ({ hours, limit, scope }) => {
        try {
          const client = await graphService.getClient();
    
          // Get current user ID first
          const me = await client.api("/me").get();
          const userId = me?.id;
    
          if (!userId) {
            return {
              content: [
                {
                  type: "text",
                  text: "❌ Error: Could not determine current user ID",
                },
              ],
            };
          }
    
          const since = new Date(Date.now() - hours * 60 * 60 * 1000).toISOString();
    
          // Build query to find mentions of current user
          const queryParts = [
            `sent>=${since.split("T")[0]}`, // Use just the date part to avoid time parsing issues
            `mentions:${userId}`,
          ];
    
          const searchQuery = queryParts.join(" AND ");
    
          const searchRequest: SearchRequest = {
            entityTypes: ["chatMessage"],
            query: {
              queryString: searchQuery,
            },
            from: 0,
            size: Math.min(limit, 50),
            enableTopResults: false,
          };
    
          const response = (await client
            .api("/search/query")
            .post({ requests: [searchRequest] })) as SearchResponse;
    
          if (
            !response?.value?.length ||
            !response.value[0]?.hitsContainers?.length ||
            !response.value[0].hitsContainers[0]?.hits
          ) {
            return {
              content: [
                {
                  type: "text",
                  text: "No recent mentions found.",
                },
              ],
            };
          }
    
          const hits = response.value[0].hitsContainers[0].hits || [];
          if (hits.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: "No recent mentions found.",
                },
              ],
            };
          }
    
          const mentions = hits
            .filter((hit) => {
              // Apply scope filters
              const isChannelMessage = hit.resource.channelIdentity?.channelId;
              const isChatMessage = hit.resource.chatId && !isChannelMessage;
    
              if (scope === "channels" && !isChannelMessage) return false;
              if (scope === "chats" && !isChatMessage) return false;
    
              return true;
            })
            .map((hit: SearchHit) => ({
              id: hit.resource.id,
              content: hit.resource.body?.content || "No content",
              summary: hit.summary,
              from: hit.resource.from?.user?.displayName || "Unknown",
              fromUserId: hit.resource.from?.user?.id,
              createdDateTime: hit.resource.createdDateTime,
              chatId: hit.resource.chatId,
              teamId: hit.resource.channelIdentity?.teamId,
              channelId: hit.resource.channelIdentity?.channelId,
              type: hit.resource.channelIdentity?.channelId ? "channel" : "chat",
            }));
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  {
                    timeRange: `Last ${hours} hours`,
                    mentionedUser: me?.displayName || "Current User",
                    scope,
                    totalMentions: mentions.length,
                    mentions,
                  },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
          return {
            content: [
              {
                type: "text",
                text: `❌ Error getting mentions: ${errorMessage}`,
              },
            ],
          };
        }
      }
    );
  • Handler function that fetches recent messages mentioning the current user using Microsoft Graph Search API with KQL query for mentions, filters by scope and time, and returns formatted results.
    async ({ hours, limit, scope }) => {
      try {
        const client = await graphService.getClient();
    
        // Get current user ID first
        const me = await client.api("/me").get();
        const userId = me?.id;
    
        if (!userId) {
          return {
            content: [
              {
                type: "text",
                text: "❌ Error: Could not determine current user ID",
              },
            ],
          };
        }
    
        const since = new Date(Date.now() - hours * 60 * 60 * 1000).toISOString();
    
        // Build query to find mentions of current user
        const queryParts = [
          `sent>=${since.split("T")[0]}`, // Use just the date part to avoid time parsing issues
          `mentions:${userId}`,
        ];
    
        const searchQuery = queryParts.join(" AND ");
    
        const searchRequest: SearchRequest = {
          entityTypes: ["chatMessage"],
          query: {
            queryString: searchQuery,
          },
          from: 0,
          size: Math.min(limit, 50),
          enableTopResults: false,
        };
    
        const response = (await client
          .api("/search/query")
          .post({ requests: [searchRequest] })) as SearchResponse;
    
        if (
          !response?.value?.length ||
          !response.value[0]?.hitsContainers?.length ||
          !response.value[0].hitsContainers[0]?.hits
        ) {
          return {
            content: [
              {
                type: "text",
                text: "No recent mentions found.",
              },
            ],
          };
        }
    
        const hits = response.value[0].hitsContainers[0].hits || [];
        if (hits.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: "No recent mentions found.",
              },
            ],
          };
        }
    
        const mentions = hits
          .filter((hit) => {
            // Apply scope filters
            const isChannelMessage = hit.resource.channelIdentity?.channelId;
            const isChatMessage = hit.resource.chatId && !isChannelMessage;
    
            if (scope === "channels" && !isChannelMessage) return false;
            if (scope === "chats" && !isChatMessage) return false;
    
            return true;
          })
          .map((hit: SearchHit) => ({
            id: hit.resource.id,
            content: hit.resource.body?.content || "No content",
            summary: hit.summary,
            from: hit.resource.from?.user?.displayName || "Unknown",
            fromUserId: hit.resource.from?.user?.id,
            createdDateTime: hit.resource.createdDateTime,
            chatId: hit.resource.chatId,
            teamId: hit.resource.channelIdentity?.teamId,
            channelId: hit.resource.channelIdentity?.channelId,
            type: hit.resource.channelIdentity?.channelId ? "channel" : "chat",
          }));
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(
                {
                  timeRange: `Last ${hours} hours`,
                  mentionedUser: me?.displayName || "Current User",
                  scope,
                  totalMentions: mentions.length,
                  mentions,
                },
                null,
                2
              ),
            },
          ],
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
        return {
          content: [
            {
              type: "text",
              text: `❌ Error getting mentions: ${errorMessage}`,
            },
          ],
        };
      }
    }
  • Input schema using Zod for validating parameters: hours (time range), limit (max results), scope (channels/chats/all).
      hours: z
        .number()
        .min(1)
        .max(168)
        .optional()
        .default(24)
        .describe("Get mentions from the last N hours"),
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .default(20)
        .describe("Maximum number of mentions to return"),
      scope: z
        .enum(["all", "channels", "chats"])
        .optional()
        .default("all")
        .describe("Scope of search"),
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose whether this is a read-only operation, what permissions are needed, rate limits, pagination behavior, or what the return format looks like. For a tool with 3 parameters and no output schema, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence that efficiently communicates the core purpose with zero wasted words. Front-loaded with the main action and resource, making it immediately clear what the tool does.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 3 parameters, 100% schema coverage, but no annotations and no output schema, the description is minimally adequate. It states what the tool does but lacks behavioral context about permissions, rate limits, and return format. The schema handles parameter documentation well, but the description doesn't compensate for the missing output schema and annotation information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all parameters are documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline of 3 is appropriate since the schema does the heavy lifting, though the description could have added context about how parameters interact.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Find') and resource ('all recent messages where the current user was mentioned') with specific scope ('across Teams channels and chats'). It distinguishes from siblings like get_recent_messages (general messages) and search_messages (broader search) by focusing exclusively on mentions of the current user.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for finding user mentions, but doesn't explicitly state when to use this tool versus alternatives like search_messages or search_users_for_mentions. No guidance on prerequisites or exclusions is provided, leaving the agent to infer context from the tool name and description alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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