create-user
Adds new user profiles to the MCP User Management Server with required details like name, email, password, address, and phone for streamlined user provisioning.
Instructions
Create a new user
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | ||
| Yes | |||
| name | Yes | ||
| password | Yes | ||
| phone | Yes |
Implementation Reference
- src/server.ts:51-62 (handler)The handler function for the 'create-user' tool. It calls the createUser helper function with the input parameters and returns a success or failure message.async (params) => { try { await createUser(params); return { content: [{ type: "text", text: "User created" }], }; } catch { return { content: [{ type: "text", text: "Failed to save user" }], }; } }
- src/server.ts:36-42 (schema)Zod schema defining the input parameters for the 'create-user' tool: name, email, password, address, phone.{ name: z.string(), email: z.string(), password: z.string(), address: z.string(), phone: z.string(), },
- src/server.ts:33-63 (registration)Registration of the 'create-user' tool with McpServer, including name, description, input schema, metadata, and handler function.server.tool( "create-user", "Create a new user", { name: z.string(), email: z.string(), password: z.string(), address: z.string(), phone: z.string(), }, { title: "Create User", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, description: "Create a new user", }, async (params) => { try { await createUser(params); return { content: [{ type: "text", text: "User created" }], }; } catch { return { content: [{ type: "text", text: "Failed to save user" }], }; } } );
- src/server.ts:70-80 (helper)Helper function that implements the core logic: loads users from JSON, appends new user with generated ID, writes back to file.async function createUser(user: { name: string; email: string; password: string; address: string; phone: string }) { const users = await import("./data/users.json", { with: { type: "json" } }).then((m) => m.default); const id = users.length + 1; users.push({ id, ...user }); await fs.writeFile("./src/data/users.json", JSON.stringify(users, null, 2)); return id; }