Last active
April 30, 2026 20:27
-
-
Save raine/67dfb38f5fbb3d2f971461a7f8b39caa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { | |
| query, | |
| tool, | |
| createSdkMcpServer, | |
| } from '@anthropic-ai/claude-agent-sdk'; | |
| import { z } from 'zod'; | |
| const rollDice = tool( | |
| 'roll_dice', | |
| 'Roll an N-sided die and return the result as a number', | |
| { sides: z.number().int().min(2).max(1000) }, | |
| async ({ sides }) => ({ | |
| content: [ | |
| { type: 'text', text: String(1 + Math.floor(Math.random() * sides)) }, | |
| ], | |
| }), | |
| { annotations: { readOnlyHint: true } }, | |
| ); | |
| const toyServer = createSdkMcpServer({ | |
| name: 'toy', | |
| version: '0.0.1', | |
| tools: [rollDice], | |
| }); | |
| const result = query({ | |
| prompt: | |
| 'Roll a 20-sided die using the roll_dice tool, then read package.json with the Read tool and tell me the package name. ' + | |
| 'Reply with exactly one line in the format: `<name> rolled <n>`.', | |
| options: { | |
| mcpServers: { | |
| toy: toyServer, | |
| }, | |
| allowedTools: ['Read', 'mcp__toy__roll_dice'], | |
| permissionMode: 'dontAsk', | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment