UNPKG

random-tables-mcp

Version:

An MCP (Model Context Protocol) server for managing and rolling on random-table assets used in tabletop RPGs. Create, update, and roll on random tables with support for nested tables, weighted entries, and range-based results.

73 lines 2.3 kB
import { z } from 'zod'; import { BaseTool } from './tool.js'; /** * Tool for rolling on tables. */ export class RollOnTableTool extends BaseTool { /** * Creates a new RollOnTableTool instance. * @param rollService The roll service to use. */ constructor(rollService) { super(); this.rollService = rollService; } /** * Gets the name of the tool. * @returns The tool name. */ getToolName() { return 'roll_on_table'; } /** * Gets the description of the tool. * @returns The tool description. */ getToolDescription() { return 'Roll on a specific table'; } /** * Gets the input schema for the tool. * @returns The input schema. */ getInputSchema() { return z.object({ tableId: z.string().describe('ID of the table to roll on'), count: z.number().optional().default(1).describe('Number of rolls to perform (default: 1)'), }); } /** * Gets the output schema for the tool. * @returns The output schema. */ getOutputSchema() { return z.object({ results: z .array(z.object({ tableId: z.string().describe('ID of the table rolled on'), entryId: z.string().describe('ID of the resulting entry'), content: z.string().describe('Content of the resulting entry'), timestamp: z.string().describe('When the roll occurred'), })) .describe('Array of roll results'), }); } /** * Implements the tool execution logic. * @param args The validated tool arguments. * @returns The tool result. */ async executeImpl(args) { // Call the roll service to roll on the table const results = await this.rollService.rollOnTable(args.tableId, args.count); // Convert results to a serializable format const serializedResults = results.map(result => ({ tableId: result.tableId, entryId: result.entryId, content: result.content, timestamp: result.timestamp.toISOString(), })); return { results: serializedResults }; } } //# sourceMappingURL=roll-on-table-tool.js.map