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.

85 lines 2.73 kB
import { z } from 'zod'; import { BaseTool } from './tool.js'; /** * Tool for getting a specific table. */ export class GetTableTool extends BaseTool { /** * Creates a new GetTableTool instance. * @param tableService The table service to use. */ constructor(tableService) { super(); this.tableService = tableService; } /** * Gets the name of the tool. * @returns The tool name. */ getToolName() { return 'get_table'; } /** * Gets the description of the tool. * @returns The tool description. */ getToolDescription() { return 'Get a specific random table by ID'; } /** * Gets the input schema for the tool. * @returns The input schema. */ getInputSchema() { return z.object({ tableId: z.string().describe('ID of the table to retrieve'), }); } /** * Gets the output schema for the tool. * @returns The output schema. */ getOutputSchema() { // Define a schema that matches the PlainRandomTable interface structure return z .object({ table: z .object({ id: z.string().describe('Table ID'), name: z.string().describe('Table name'), description: z.string().describe('Table description'), entries: z .array(z.object({ id: z.string().describe('Entry ID'), content: z.string().describe('Entry content'), weight: z.number().describe('Entry weight'), range: z .object({ min: z.number().describe('Minimum value (inclusive)'), max: z.number().describe('Maximum value (inclusive)'), }) .optional() .describe('Optional range of values this entry corresponds to'), })) .describe('Array of table entries'), }) .describe('The retrieved table'), }) .strict(); } /** * Implements the tool execution logic. * @param args The validated tool arguments. * @returns The tool result. */ async executeImpl(args) { // Call the table service to get the table const table = await this.tableService.getTable(args.tableId); if (!table) { throw new Error(`Table with ID ${args.tableId} not found`); } // Return the table in a serializable format return { table: table.toObject() }; } } //# sourceMappingURL=get-table-tool.js.map