Skip to main content
Glama

search_users

Locate users within an organization by searching for names or email addresses, retrieving their basic profile details using Microsoft Teams integration.

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 handler function for the 'search_users' tool. It takes a query parameter, searches the Microsoft Graph API for users whose displayName, mail, or userPrincipalName starts with the query, maps the results to UserSummary objects, and returns them as JSON or an 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 for the 'search_users' tool using Zod: requires a 'query' string parameter described as 'Search query (name or email)'.
    { query: z.string().describe("Search query (name or email)"), },
  • Registration of the 'search_users' MCP tool using server.tool(), including name, description, schema, and inline handler.
    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}`, }, ], }; } } );

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