Skip to main content
Glama
dh1789

My First MCP

by dh1789

get_random_number

Generate random integers within a specified range for applications requiring unpredictable values, such as simulations, games, or data sampling.

Instructions

지정한 범위 내에서 랜덤 정수를 생성합니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
minYes최소값 (정수)
maxYes최대값 (정수)
countNo생성할 숫자 개수 (1-10). 기본값: 1

Implementation Reference

  • The MCP tool handler function that receives validated inputs, calls the core generateRandomNumbers helper, handles errors, and returns formatted text response.
    async ({ min, max, count }) => { const result = generateRandomNumbers(min, max, count || 1); if (result.isError) { return { content: [ { type: "text", text: result.errorMessage!, }, ], isError: true, }; } const n = result.numbers.length; const resultText = n === 1 ? `랜덤 숫자 (${result.min}~${result.max}): ${result.numbers[0]}` : `랜덤 숫자 ${n}개 (${result.min}~${result.max}): ${result.numbers.join(", ")}`; return { content: [ { type: "text", text: resultText, }, ], }; }
  • Core pure function generateRandomNumbers that implements the random number generation logic using Math.random(). Validates min <= max, generates up to 10 random integers inclusive.
    export function generateRandomNumbers( min: number, max: number, count: number = 1 ): RandomResult { if (min > max) { return { numbers: [], min, max, isError: true, errorMessage: "오류: 최소값이 최대값보다 큽니다.", }; } const numbers: number[] = []; for (let i = 0; i < count; i++) { const randomNum = Math.floor(Math.random() * (max - min + 1)) + min; numbers.push(randomNum); } return { numbers, min, max, isError: false, }; }
  • Zod schema for tool parameters: min (int), max (int), count (int 1-10 optional).
    { min: z.number().int().describe("최소값 (정수)"), max: z.number().int().describe("최대값 (정수)"), count: z .number() .int() .min(1) .max(10) .optional() .describe("생성할 숫자 개수 (1-10). 기본값: 1"), },
  • src/index.ts:165-209 (registration)
    server.tool call that registers 'get_random_number' with name, description, input schema, and handler function.
    server.tool( "get_random_number", "지정한 범위 내에서 랜덤 정수를 생성합니다.", { min: z.number().int().describe("최소값 (정수)"), max: z.number().int().describe("최대값 (정수)"), count: z .number() .int() .min(1) .max(10) .optional() .describe("생성할 숫자 개수 (1-10). 기본값: 1"), }, async ({ min, max, count }) => { const result = generateRandomNumbers(min, max, count || 1); if (result.isError) { return { content: [ { type: "text", text: result.errorMessage!, }, ], isError: true, }; } const n = result.numbers.length; const resultText = n === 1 ? `랜덤 숫자 (${result.min}~${result.max}): ${result.numbers[0]}` : `랜덤 숫자 ${n}개 (${result.min}~${result.max}): ${result.numbers.join(", ")}`; return { content: [ { type: "text", text: resultText, }, ], }; } );
  • TypeScript interface defining the return type RandomResult for the helper function.
    export interface RandomResult { numbers: number[]; min: number; max: number; isError: boolean; errorMessage?: string; }

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/dh1789/my-first-mcp'

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