Skip to main content
Glama

create-random-user

Generate a random user with fake data for testing or simulation. This tool assists in creating sample user profiles to support user management workflows.

Instructions

Create a random user with fake data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for the 'create-random-user' tool. Generates fake user data using LLM sampling request, parses the JSON response, and calls createUser to add it to the database.
    async () => { const res = await server.server.request( { method: "sampling/createMessage", params: { messages: [ { role: "user", content: { type: "text", text: "Generate fake user data. The user should have a realistic name, email, address, age, and phone number. Return this data as a JSON object with no other text or formatter so it can be used with JSON.parse.", }, }, ], maxTokens: 1024, }, }, CreateMessageResultSchema ) if (res.content.type !== "text") { return { content: [{ type: "text", text: "Failed to generate user data" }], } } try { const fakeUser = JSON.parse( res.content.text .trim() .replace(/^```json/, "") .replace(/```$/, "") .trim() ) const id = await createUser(fakeUser) return { content: [{ type: "text", text: `User ${id} created successfully` }], } } catch { return { content: [{ type: "text", text: "Failed to generate user data" }], } } }
  • src/server.ts:123-178 (registration)
    Registration of the 'create-random-user' tool with server.tool, including description, metadata hints, and inline handler function.
    server.tool( "create-random-user", "Create a random user with fake data", { title: "Create Random User", readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true, }, async () => { const res = await server.server.request( { method: "sampling/createMessage", params: { messages: [ { role: "user", content: { type: "text", text: "Generate fake user data. The user should have a realistic name, email, address, age, and phone number. Return this data as a JSON object with no other text or formatter so it can be used with JSON.parse.", }, }, ], maxTokens: 1024, }, }, CreateMessageResultSchema ) if (res.content.type !== "text") { return { content: [{ type: "text", text: "Failed to generate user data" }], } } try { const fakeUser = JSON.parse( res.content.text .trim() .replace(/^```json/, "") .replace(/```$/, "") .trim() ) const id = await createUser(fakeUser) return { content: [{ type: "text", text: `User ${id} created successfully` }], } } catch { return { content: [{ type: "text", text: "Failed to generate user data" }], } } } )
  • Helper function createUser used by the tool handler to persist the new user to users.json file.
    async function createUser(params: { name: string; email: string; address: string; age: number; phone: string }) { const users = await import("./data/users.json", { with: { type: "json" } }).then((m) => m.default); const newId = users.length + 1; const newUsers = [...users, { id: newId, ...params }]; writeFileSync("./src/data/users.json", JSON.stringify(newUsers, null, 2)); return newId; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SufyaanKhateeb/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server