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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query (name or email) |
Implementation Reference
- src/tools/users.ts:55-102 (handler)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}`, }, ], }; } }
- src/tools/users.ts:52-54 (schema)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)"), },
- src/tools/users.ts:49-103 (registration)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}`, }, ], }; } } );