search-users
Find users in Zulip workspaces by partial name or email. Returns matching results with basic details like name, email, and ID. Useful for locating users before direct messaging.
Instructions
🔍 DISCOVERY: Search for users by partial name or email when you don't know exact details. Use this first to explore and find users before sending direct messages. Returns multiple matching results with basic info (name, email, ID).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Maximum number of results to return (default: 10) | |
| query | Yes | Name, email, or partial match to search for users |
Implementation Reference
- src/server.ts:337-366 (handler)The core handler function for the 'search-users' tool. It fetches all users from Zulip, performs client-side filtering based on partial matches in name or email (case-insensitive), limits the results, and returns a formatted JSON response with matching users including name, email, ID, and active status.async ({ query, limit }) => { try { const usersResponse = await zulipClient.getUsers(); const lowerQuery = query.toLowerCase(); const filtered = usersResponse.members.filter((user: any) => user.full_name.toLowerCase().includes(lowerQuery) || user.email.toLowerCase().includes(lowerQuery) ).slice(0, limit); if (filtered.length === 0) { return createSuccessResponse(`No users found matching "${query}". Try a shorter search term or check spelling.`); } const results = filtered.map((user: any) => ({ name: user.full_name, email: user.email, id: user.id, active: user.is_active })); return createSuccessResponse(JSON.stringify({ query, found: filtered.length, users: results }, null, 2)); } catch (error) { return createErrorResponse(`Error searching users: ${error instanceof Error ? error.message : 'Unknown error'}`); } }
- src/server.ts:333-336 (schema)Input schema for the 'search-users' tool using Zod validation. Defines 'query' as required string for search term and optional 'limit' defaulting to 10.{ query: z.string().describe("Name, email, or partial match to search for users"), limit: z.number().default(10).describe("Maximum number of results to return (default: 10)") },
- src/server.ts:330-367 (registration)Registration of the 'search-users' tool with MCP server, including name, description, input schema, and handler reference.server.tool( "search-users", "🔍 DISCOVERY: Search for users by partial name or email when you don't know exact details. Use this first to explore and find users before sending direct messages. Returns multiple matching results with basic info (name, email, ID).", { query: z.string().describe("Name, email, or partial match to search for users"), limit: z.number().default(10).describe("Maximum number of results to return (default: 10)") }, async ({ query, limit }) => { try { const usersResponse = await zulipClient.getUsers(); const lowerQuery = query.toLowerCase(); const filtered = usersResponse.members.filter((user: any) => user.full_name.toLowerCase().includes(lowerQuery) || user.email.toLowerCase().includes(lowerQuery) ).slice(0, limit); if (filtered.length === 0) { return createSuccessResponse(`No users found matching "${query}". Try a shorter search term or check spelling.`); } const results = filtered.map((user: any) => ({ name: user.full_name, email: user.email, id: user.id, active: user.is_active })); return createSuccessResponse(JSON.stringify({ query, found: filtered.length, users: results }, null, 2)); } catch (error) { return createErrorResponse(`Error searching users: ${error instanceof Error ? error.message : 'Unknown error'}`); } } );
- src/zulip/client.ts:374-384 (helper)ZulipClient.getUsers() helper method called by the search-users handler to fetch the complete list of users from the Zulip API endpoint '/users', which is then filtered client-side.async getUsers(params: { client_gravatar?: boolean; include_custom_profile_fields?: boolean; } = {}): Promise<{ members: ZulipUser[] }> { // Filter out undefined values const filteredParams = Object.fromEntries( Object.entries(params).filter(([, value]) => value !== undefined) ); const response = await this.client.get('/users', { params: filteredParams }); return response.data; }