Kullanıcı Ara
search_users_by_nameFind users by name in the User Info MCP Server to retrieve and manage user data stored in JSON files.
Instructions
İsme göre kullanıcı ara
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"name": "<name>"
},
"name": "search_users_by_name"
}
}Input 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, calls the user service to perform the search, handles errors, and returns a formatted MCP ToolResponse.
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-based input schema defining the expected 'name' parameter for the tool.
export const SearchUsersByNameInputSchema = { name: z.string().min(1).describe("Aranacak kullanıcı ismi") }; - src/tools/user-tools.ts:41-49 (registration)Tool registration using server.registerTool, specifying name, metadata, 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 the service layer that validates input, queries the repository, and returns structured results used by the handler.
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: [] }; } }