Skip to main content
Glama

search_users

Find organization members by name or email to retrieve their basic profile details for collaboration and communication.

Instructions

Search for users in the organization by name or email address. Returns matching users with their basic profile information.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (name or email)

Implementation Reference

  • The core handler function for the 'search_users' tool. It uses the GraphService client to query the Microsoft Graph /users endpoint with a filter for displayName, mail, or userPrincipalName starting with the input query. Maps results to UserSummary and returns as JSON text content or error message.
    async ({ query }) => {
      try {
        const client = await graphService.getClient();
        const response = (await client
          .api("/users")
          .filter(
            `startswith(displayName,'${query}') or startswith(mail,'${query}') or startswith(userPrincipalName,'${query}')`
          )
          .get()) as GraphApiResponse<User>;
    
        if (!response?.value?.length) {
          return {
            content: [
              {
                type: "text",
                text: "No users found matching your search.",
              },
            ],
          };
        }
    
        const userList: UserSummary[] = response.value.map((user: User) => ({
          displayName: user.displayName,
          userPrincipalName: user.userPrincipalName,
          mail: user.mail,
          id: user.id,
        }));
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(userList, null, 2),
            },
          ],
        };
      } catch (error: unknown) {
        const errorMessage = error instanceof Error ? error.message : "Unknown error occurred";
        return {
          content: [
            {
              type: "text",
              text: `❌ Error: ${errorMessage}`,
            },
          ],
        };
      }
    }
  • Input schema using Zod, defining a single required 'query' parameter as string for the search term.
    {
      query: z.string().describe("Search query (name or email)"),
    },
  • Registers the 'search_users' tool on the MCP server with name, description, input schema, and handler function within the registerUsersTools function.
    server.tool(
      "search_users",
      "Search for users in the organization by name or email address. Returns matching users with their basic profile information.",
      {
        query: z.string().describe("Search query (name or email)"),
      },
      async ({ query }) => {
        try {
          const client = await graphService.getClient();
          const response = (await client
            .api("/users")
            .filter(
              `startswith(displayName,'${query}') or startswith(mail,'${query}') or startswith(userPrincipalName,'${query}')`
            )
            .get()) as GraphApiResponse<User>;
    
          if (!response?.value?.length) {
            return {
              content: [
                {
                  type: "text",
                  text: "No users found matching your search.",
                },
              ],
            };
          }
    
          const userList: UserSummary[] = response.value.map((user: User) => ({
            displayName: user.displayName,
            userPrincipalName: user.userPrincipalName,
            mail: user.mail,
            id: user.id,
          }));
    
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(userList, 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:133-133 (registration)
    Top-level call to register all user tools (including search_users) during MCP server initialization.
    registerUsersTools(server, graphService);
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the action ('Search') and return type ('basic profile information'), but lacks details on permissions required, rate limits, pagination behavior, or what constitutes 'basic profile information'. For a search tool with no annotation coverage, this is insufficient.

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 concise sentences that are front-loaded with the core purpose and efficiently cover the search criteria and return value. There is no wasted language, making it easy for an agent to parse quickly.

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 the tool's moderate complexity (search function with one parameter) and no annotations or output schema, the description is adequate but incomplete. It covers the purpose and parameters but lacks behavioral details like error handling or output format specifics, which are important for a search tool.

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?

The schema description coverage is 100%, with the parameter 'query' fully documented in the schema. The description adds minimal value by restating that the query is for 'name or email address', which is already implied in the schema. This meets the baseline of 3 when schema coverage is high.

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 tool's purpose with a specific verb ('Search') and resource ('users in the organization'), and distinguishes it from siblings by specifying the search criteria ('by name or email address') and what it returns ('basic profile information'). This differentiates it from tools like 'get_user' or 'list_team_members'.

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 when searching for users by name or email, but does not explicitly state when to use this tool versus alternatives like 'get_user' (which likely retrieves a specific user) or 'list_team_members' (which might list all members without search). No exclusions or prerequisites are mentioned, leaving some ambiguity.

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