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.

72 lines 2.15 kB
import { z } from 'zod'; import { BaseTool } from './tool.js'; /** * Tool for listing tables. */ export class ListTablesTool extends BaseTool { /** * Creates a new ListTablesTool 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 'list_tables'; } /** * Gets the description of the tool. * @returns The tool description. */ getToolDescription() { return 'List available random tables'; } /** * Gets the input schema for the tool. * @returns The input schema. */ getInputSchema() { return z.object({ filter: z.record(z.unknown()).optional().describe('Optional filter criteria'), }); } /** * Gets the output schema for the tool. * @returns The output schema. */ getOutputSchema() { return z.object({ tables: z .array(z.object({ id: z.string().describe('Table ID'), name: z.string().describe('Table name'), description: z.string().optional().describe('Table description'), entryCount: z.number().describe('Number of entries in the table'), })) .describe('Array of tables matching the filter'), }); } /** * Implements the tool execution logic. * @param args The validated tool arguments. * @returns The tool result. */ async executeImpl(args) { // Call the table service to list tables const tables = await this.tableService.listTables(args.filter); // Convert tables to a serializable format const serializedTables = tables.map(table => ({ id: table.id, name: table.name, description: table.description, entryCount: table.entries.length, })); return { tables: serializedTables }; } } //# sourceMappingURL=list-tables-tool.js.map