create-user
Add new user records to the database with required personal details including name, email, address, phone, and password.
Instructions
Create a new user in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| Yes | |||
| address | Yes | ||
| phone | Yes | ||
| password | Yes |
Implementation Reference
- src/server.ts:64-87 (registration)Registration of the 'create-user' tool, including input schema, hints, and inline handler function.server.tool("create-user","Create a new user in the database", { name: z.string(), email: z.string().email(), address: z.string(), phone: z.string(), password: z.string(), }, { title: "Create User", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, }, async (params) => { try { const id = await createUser(params); return { content: [{ type: "text", text: `User ${params.name} with id ${id} created successfully` }] } } catch (error) { return { content: [{ type: "text", text: `User ${params.name} creation failed` }] } } })
- src/server.ts:116-125 (handler)Core handler logic for creating a user: loads users from JSON, appends new user, writes back to file, returns new ID.async function createUser(user: {name: string, email: string, address: string, phone: string, password: string }) { const users = await import("./data/users.json", { with: {type: "json" }, }).then((module) => module.default); const id = users.length + 1; users.push({ id, ...user }); await fs.writeFile("./src/data/users.json", JSON.stringify(users, null, 2)); return id; }
- src/server.ts:65-70 (schema)Input schema for the create-user tool, validated with Zod.name: z.string(), email: z.string().email(), address: z.string(), phone: z.string(), password: z.string(), }, {
- src/server.ts:76-87 (handler)Inline handler function passed to server.tool for create-user, handles error and success responses.}, async (params) => { try { const id = await createUser(params); return { content: [{ type: "text", text: `User ${params.name} with id ${id} created successfully` }] } } catch (error) { return { content: [{ type: "text", text: `User ${params.name} creation failed` }] } } })