fakestore_update_user
Modify user details in a simulated e-commerce environment by providing user ID and updated information like email, address, or username for testing and development purposes.
Instructions
Update an existing user (simulation - does not persist)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | User ID to update | |
| No | New email address | ||
| username | No | New username | |
| password | No | New password | |
| firstname | No | New first name | |
| lastname | No | New last name | |
| city | No | New city | |
| street | No | New street name | |
| number | No | New street number | |
| zipcode | No | New ZIP code | |
| lat | No | New latitude | |
| long | No | New longitude | |
| phone | No | New phone number |
Implementation Reference
- src/tools/users.ts:112-180 (handler)Core execution logic for updating a user. Validates input, constructs partial update object for name and address fields, and sends PUT request to `/users/${id}`.export async function updateUser(args: { id: number; email?: string; username?: string; password?: string; firstname?: string; lastname?: string; city?: string; street?: string; number?: number; zipcode?: string; lat?: string; long?: string; phone?: string; }): Promise<User> { const { id, email, username, password, firstname, lastname, city, street, number, zipcode, lat, long, phone, } = args; validatePositiveInteger(id, 'User ID'); const updateData: Record<string, unknown> = {}; if (email !== undefined) { validateEmail(email); updateData.email = email; } if (username !== undefined) updateData.username = username; if (password !== undefined) updateData.password = password; if (phone !== undefined) { validatePhone(phone); updateData.phone = phone; } // Handle name updates if (firstname !== undefined || lastname !== undefined) { updateData.name = {}; if (firstname !== undefined) (updateData.name as Record<string, unknown>).firstname = firstname; if (lastname !== undefined) (updateData.name as Record<string, unknown>).lastname = lastname; } // Handle address updates if (city !== undefined || street !== undefined || number !== undefined || zipcode !== undefined || lat !== undefined || long !== undefined) { updateData.address = {}; if (city !== undefined) (updateData.address as Record<string, unknown>).city = city; if (street !== undefined) (updateData.address as Record<string, unknown>).street = street; if (number !== undefined) (updateData.address as Record<string, unknown>).number = number; if (zipcode !== undefined) (updateData.address as Record<string, unknown>).zipcode = zipcode; if (lat !== undefined || long !== undefined) { (updateData.address as Record<string, unknown>).geolocation = {}; if (lat !== undefined) ((updateData.address as Record<string, unknown>).geolocation as Record<string, unknown>).lat = lat; if (long !== undefined) ((updateData.address as Record<string, unknown>).geolocation as Record<string, unknown>).long = long; } } return put<User>(`/users/${id}`, updateData); }
- src/tools/users.ts:285-346 (schema)Input schema and metadata for the fakestore_update_user tool, part of the userTools array.{ name: 'fakestore_update_user', description: 'Update an existing user (simulation - does not persist)', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'User ID to update', }, email: { type: 'string', description: 'New email address', }, username: { type: 'string', description: 'New username', }, password: { type: 'string', description: 'New password', }, firstname: { type: 'string', description: 'New first name', }, lastname: { type: 'string', description: 'New last name', }, city: { type: 'string', description: 'New city', }, street: { type: 'string', description: 'New street name', }, number: { type: 'number', description: 'New street number', }, zipcode: { type: 'string', description: 'New ZIP code', }, lat: { type: 'string', description: 'New latitude', }, long: { type: 'string', description: 'New longitude', }, phone: { type: 'string', description: 'New phone number', }, }, required: ['id'], }, },
- src/index.ts:40-44 (registration)Tool registration via ListToolsRequestSchema handler, including userTools which defines fakestore_update_user.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [...productTools, ...cartTools, ...userTools], }; });
- src/index.ts:203-222 (handler)Dispatch logic in CallToolRequestSchema handler that calls the updateUser function for this tool.if (name === 'fakestore_update_user') { const result = await updateUser(args as { id: number; email?: string; username?: string; password?: string; firstname?: string; lastname?: string; city?: string; street?: string; number?: number; zipcode?: string; lat?: string; long?: string; phone?: string; }); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; }
- src/types/fakestore.ts:46-54 (schema)User type definition used as return type for the updateUser handler.export interface User { id: number; email: string; username: string; password: string; name: UserName; address: Address; phone: string; }