Skip to main content
Glama
SufyaanKhateeb

User Management MCP Server

create-random-user

Generate fake user data for testing user management systems. This tool creates random user profiles with realistic information to simulate real users in development or testing environments.

Instructions

Create a random user with fake data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function that generates random user data using LLM sampling, parses the JSON response, and creates the user via the createUser helper function.
    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 on the MCP server, specifying description, metadata, and inline handler.
    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 used by create-random-user (and create-user) to persist new user data 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;
    }
Install Server

Other 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