search_users_by_name
Search for users by their name using this tool from the User Info MCP Server. Input a name to retrieve matching user data stored in JSON format for efficient information management.
Instructions
İsme göre kullanıcı ara
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Aranacak kullanıcı ismi |
Implementation Reference
- The main handler function for the 'search_users_by_name' tool. It receives the input name, delegates to userService.searchUsersByName, formats the result as MCP ToolResponse with JSON users or error message.static async handleSearchUsersByName({ name }: { name: string }): Promise<ToolResponse> { try { const result = await userService.searchUsersByName(name); return { content: [ { type: "text", text: result.success && result.data && result.data.length > 0 ? JSON.stringify(result.data, null, 2) : result.message || result.error || "Kullanıcı bulunamadı", }, ], }; } catch (error) { return { content: [ { type: "text", text: "Kullanıcı arama işleminde hata oluştu", }, ], }; } }
- src/types/user.ts:19-21 (schema)Zod input schema for the tool, defining 'name' as a non-empty string.export const SearchUsersByNameInputSchema = { name: z.string().min(1).describe("Aranacak kullanıcı ismi") };
- src/tools/user-tools.ts:41-49 (registration)Registers the tool named 'search_users_by_name' on the MCP server with title, description, input schema, and handler reference.server.registerTool( "search_users_by_name", { title: "Kullanıcı Ara", description: "İsme göre kullanıcı ara", inputSchema: SearchUsersByNameInputSchema, }, UserController.handleSearchUsersByName );
- src/services/user.service.ts:83-110 (helper)Business logic helper in user service that validates input (min 2 chars), queries repository by name, and returns structured ServiceResult<User[]>.async searchUsersByName(name: string): Promise<ServiceResult<User[]>> { try { // Business rule: Name must be at least 2 characters if (name.trim().length < 2) { return { success: false, error: "Arama terimi en az 2 karakter olmalıdır", data: [] }; } const users = await userRepository.findByName(name); return { success: true, data: users, message: users.length > 0 ? `"${name}" için ${users.length} kullanıcı bulundu` : `"${name}" ismiyle kullanıcı bulunamadı` }; } catch (error) { return { success: false, error: "Kullanıcı arama işleminde hata oluştu", data: [] }; } }