get_user_by_id
Retrieve specific user details by providing a unique user ID. This tool is part of the User Info MCP Server, designed for efficient user information management.
Instructions
ID'ye göre belirli bir kullanıcıyı getir
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Kullanıcının ID'si |
Implementation Reference
- src/controllers/user.controller.ts:53-77 (handler)The main handler function for the 'get_user_by_id' tool. It takes an ID, calls the user service, and formats the response as MCP ToolResponse.static async handleGetUserById({ id }: { id: number }): Promise<ToolResponse> { try { const result = await userService.getUserById(id); return { content: [ { type: "text", text: result.success ? JSON.stringify(result.data, null, 2) : result.error || "Kullanıcı bulunamadı", }, ], }; } catch (error) { return { content: [ { type: "text", text: "Kullanıcı getirme işleminde hata oluştu", }, ], }; } }
- src/types/user.ts:15-17 (schema)Zod schema defining the input for the tool: requires a positive integer ID.export const GetUserByIdInputSchema = { id: z.number().int().positive().describe("Kullanıcının ID'si") };
- src/tools/user-tools.ts:30-38 (registration)Registration of the 'get_user_by_id' tool on the MCP server, linking name, schema, and handler.server.registerTool( "get_user_by_id", { title: "Kullanıcı Getir", description: "ID'ye göre belirli bir kullanıcıyı getir", inputSchema: GetUserByIdInputSchema, }, UserController.handleGetUserById );
- src/services/user.service.ts:46-76 (helper)Service layer method providing business logic for fetching user by ID, including validation and repository call.async getUserById(id: number): Promise<ServiceResult<User>> { try { // Business rule: ID must be positive if (id <= 0) { return { success: false, error: "Geçersiz kullanıcı ID'si. ID pozitif bir sayı olmalıdır." }; } const user = await userRepository.findById(id); if (!user) { return { success: false, error: `ID ${id} ile kullanıcı bulunamadı` }; } return { success: true, data: user, message: "Kullanıcı başarıyla bulundu" }; } catch (error) { return { success: false, error: "Kullanıcı getirilirken hata oluştu" }; } }