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.21 kB
import { z } from 'zod'; import { BaseTool } from './tool.js'; /** * Tool for evaluating a roll template. */ export class EvaluateTemplateTool extends BaseTool { /** * Creates a new EvaluateTemplateTool instance. * @param templateService The template service to use. */ constructor(templateService) { super(); this.templateService = templateService; } /** * Gets the name of the tool. * @returns The tool name. */ getToolName() { return 'evaluate_template'; } /** * Gets the description of the tool. * @returns The tool description. */ getToolDescription() { return 'Evaluate a roll template by resolving all references to tables.'; } /** * Gets the input schema for the tool. * @returns The input schema. */ getInputSchema() { return z.object({ id: z.string().describe('The ID of the template to evaluate'), count: z .number() .int() .positive() .optional() .describe('The number of evaluations to perform (default: 1)'), }); } /** * Gets the output schema for the tool. * @returns The output schema. */ getOutputSchema() { return z.object({ results: z.array(z.object({ originalTemplate: z.string().describe('The original template string'), evaluatedTemplate: z.string().describe('The evaluated template string'), })), }); } /** * Implements the tool execution logic. * @param args The validated tool arguments. * @returns The tool result. */ async executeImpl(args) { const { id, count } = args; try { // Call the template service to evaluate the template const results = await this.templateService.evaluateTemplate(id, count); return { results }; } catch (error) { throw new Error(`Failed to evaluate template: ${error instanceof Error ? error.message : String(error)}`); } } } //# sourceMappingURL=evaluate-template-tool.js.map