create-user
Add a new user to the database by providing name, email, address, phone, and password. Designed for the MCP Personal Tools Server to manage user accounts efficiently.
Instructions
Create a new user in the database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | ||
| Yes | |||
| name | Yes | ||
| password | Yes | ||
| phone | Yes |
Implementation Reference
- src/server.ts:76-87 (handler)The handler function for the 'create-user' tool. It calls the createUser helper function and returns a success or error message.}, 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:65-70 (schema)Input schema using Zod for validating parameters: name, email, address, phone, password.name: z.string(), email: z.string().email(), address: z.string(), phone: z.string(), password: z.string(), }, {
- src/server.ts:64-87 (registration)Registration of the 'create-user' tool with the MCP server, including description, input schema, hints, and handler.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 (helper)Helper function that loads users from JSON, appends a new user with incremented ID, writes back to file, and returns the 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; }