랜덤 숫자 생성
get_random_numberGenerate a random number between 1 and 50, or customize the range from 1 to 100 for applications requiring random numeric values.
Instructions
1부터 50 사이의 랜덤한 숫자를 하나 뽑아주는 도구입니다.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_random_number"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| min | No | 최소값 (기본값: 1) | |
| max | No | 최대값 (기본값: 50) |
Implementation Reference
- src/index.ts:87-95 (handler)The MCP tool handler that calls the random number generator helper and formats the response as text content.
async ({ min = 1, max = 50 }) => { const randomNumber = getRandomNumber(min, max); return { content: [{ type: "text", text: `랜덤 숫자 (${min}~${max}): ${randomNumber}` }] }; } - src/index.ts:82-85 (schema)Input schema using Zod for validating min and max parameters with descriptions.
inputSchema: { min: z.number().min(1).max(100).optional().describe("최소값 (기본값: 1)"), max: z.number().min(1).max(100).optional().describe("최대값 (기본값: 50)") } - src/index.ts:77-96 (registration)Registration of the 'get_random_number' tool using server.registerTool, including title, description, input schema, and handler.
server.registerTool( "get_random_number", { title: "랜덤 숫자 생성", description: "1부터 50 사이의 랜덤한 숫자를 하나 뽑아주는 도구입니다.", inputSchema: { min: z.number().min(1).max(100).optional().describe("최소값 (기본값: 1)"), max: z.number().min(1).max(100).optional().describe("최대값 (기본값: 50)") } }, async ({ min = 1, max = 50 }) => { const randomNumber = getRandomNumber(min, max); return { content: [{ type: "text", text: `랜덤 숫자 (${min}~${max}): ${randomNumber}` }] }; } ); - src/index.ts:35-46 (helper)Utility function that generates a random integer between min and max (clamped to 1-100), used by the tool handler.
function getRandomNumber(min: number = 1, max: number = 50): number { // Ensure min and max are within bounds min = Math.max(1, Math.min(min, 100)); max = Math.max(1, Math.min(max, 100)); // Ensure min <= max if (min > max) { [min, max] = [max, min]; } return Math.floor(Math.random() * (max - min + 1)) + min; }