Skip to main content
Glama

search_users_for_mentions

Find users to mention in Microsoft Teams messages by searching names or email addresses. Returns display names, emails, and mention IDs for quick tagging.

Instructions

Search for users to mention in messages. Returns users with their display names, email addresses, and mention IDs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (name or email)
limitNoMaximum number of results to return

Implementation Reference

  • The main handler function for the 'search_users_for_mentions' tool. It calls the searchUsers helper, processes the results by adding a mentionText field, and returns a formatted JSON response or error.
      async ({ query, limit }) => {
        try {
          const users = await searchUsers(graphService, query, limit);
    
          if (users.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: `No users found matching "${query}".`,
                },
              ],
            };
          }
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(
                  {
                    query,
                    totalResults: users.length,
                    users: users.map((user: UserInfo) => ({
                      id: user.id,
                      displayName: user.displayName,
                      userPrincipalName: user.userPrincipalName,
                      mentionText:
                        user.userPrincipalName?.split("@")[0] ||
                        user.displayName.toLowerCase().replace(/\s+/g, ""),
                    })),
                  },
                  null,
                  2
                ),
              },
            ],
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
          return {
            content: [
              {
                type: "text",
                text: `❌ Error: ${errorMessage}`,
              },
            ],
          };
        }
      }
    );
  • Zod input schema defining the parameters for the tool: required 'query' string and optional 'limit' number (default 10, max 50).
    {
      query: z.string().describe("Search query (name or email)"),
      limit: z
        .number()
        .min(1)
        .max(50)
        .optional()
        .default(10)
        .describe("Maximum number of results to return"),
    },
  • Registration of the 'search_users_for_mentions' tool with the MCP server, including name, description, schema, and handler reference.
      // Search users for @mentions
      server.tool(
        "search_users_for_mentions",
        "Search for users to mention in messages. Returns users with their display names, email addresses, and mention IDs.",
        {
          query: z.string().describe("Search query (name or email)"),
          limit: z
            .number()
            .min(1)
            .max(50)
            .optional()
            .default(10)
            .describe("Maximum number of results to return"),
        },
        async ({ query, limit }) => {
          try {
            const users = await searchUsers(graphService, query, limit);
    
            if (users.length === 0) {
              return {
                content: [
                  {
                    type: "text",
                    text: `No users found matching "${query}".`,
                  },
                ],
              };
            }
    
            return {
              content: [
                {
                  type: "text",
                  text: JSON.stringify(
                    {
                      query,
                      totalResults: users.length,
                      users: users.map((user: UserInfo) => ({
                        id: user.id,
                        displayName: user.displayName,
                        userPrincipalName: user.userPrincipalName,
                        mentionText:
                          user.userPrincipalName?.split("@")[0] ||
                          user.displayName.toLowerCase().replace(/\s+/g, ""),
                      })),
                    },
                    null,
                    2
                  ),
                },
              ],
            };
          } catch (error: unknown) {
            const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
            return {
              content: [
                {
                  type: "text",
                  text: `❌ Error: ${errorMessage}`,
                },
              ],
            };
          }
        }
      );
    }
  • The core helper function that performs the actual user search via Microsoft Graph API using startswith filter on displayName or userPrincipalName, returning UserInfo array.
    export async function searchUsers(
      graphService: GraphService,
      query: string,
      limit = 10
    ): Promise<UserInfo[]> {
      try {
        const client = await graphService.getClient();
    
        // Use filter query to search users by displayName or userPrincipalName
        const searchQuery = `$filter=startswith(displayName,'${query}') or startswith(userPrincipalName,'${query}')&$top=${limit}&$select=id,displayName,userPrincipalName`;
    
        const response = await client.api(`/users?${searchQuery}`).get();
    
        if (!response?.value?.length) {
          return [];
        }
    
        return response.value.map((user: User) => ({
          id: user.id || "",
          displayName: user.displayName || "Unknown User",
          userPrincipalName: user.userPrincipalName || undefined,
        }));
      } catch (error) {
        console.error("Error searching users:", error);
        return [];
      }
    }
  • TypeScript interface defining the UserInfo type used by searchUsers and returned by the tool handler.
    export interface UserInfo {
      id: string;
      displayName: string;
      userPrincipalName?: string;
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool returns users with display names, email addresses, and mention IDs, which is useful. However, it doesn't mention important behaviors like whether it's a read-only operation (implied but not stated), if it requires authentication, rate limits, or how results are ordered. It adds some context but misses key operational details.

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?

The description is two sentences, front-loaded with the core purpose and followed by return details. Every sentence earns its place by clarifying the tool's function and output without redundancy. It's appropriately sized and efficiently structured.

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?

Given no annotations and no output schema, the description provides basic purpose and output format, but it's incomplete for a search tool. It lacks details on authentication needs, error handling, pagination (beyond the 'limit' param), or whether the search is case-sensitive. For a tool with 2 parameters and no structured safety hints, more context would be beneficial.

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 the schema already fully documents both parameters ('query' and 'limit'). The description does not add any meaning beyond what the schema provides—it doesn't explain parameter interactions, formatting nuances, or search logic. Baseline 3 is appropriate as the schema does the heavy lifting.

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 specific action ('Search for users to mention in messages') and resource ('users'), distinguishing it from sibling tools like 'search_users' (which likely has broader scope) and 'get_user' (which retrieves a specific user). It explicitly mentions the intended use case (mentioning in messages), making the purpose unambiguous.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('to mention in messages'), but it does not explicitly state when not to use it or name alternatives. For example, it doesn't clarify if 'search_users' should be used for non-mention searches or if 'list_team_members' is better for team-specific mentions. The guidance is helpful but lacks explicit exclusions.

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