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.
61 lines (60 loc) • 2.35 kB
TypeScript
import { RandomNumberGenerator, TableRepository } from '../ports/index.js';
import { RollTemplateRepository } from '../ports/secondary/roll-template-repository.js';
/**
* Result of a template evaluation.
*/
export interface TemplateEvaluationResult {
/**
* The original template string.
*/
originalTemplate: string;
/**
* The evaluated template string.
*/
evaluatedTemplate: string;
}
/**
* Use case for evaluating a roll template.
*/
export declare class EvaluateTemplateUseCase {
private readonly templateRepository;
private readonly tableRepository;
private readonly rng;
/**
* Creates a new EvaluateTemplateUseCase instance.
* @param templateRepository The template repository to use.
* @param tableRepository The table repository to use.
* @param rng The random number generator to use.
*/
constructor(templateRepository: RollTemplateRepository, tableRepository: TableRepository, rng: RandomNumberGenerator);
/**
* Executes the use case.
* @param templateId The ID of the template to evaluate.
* @param count The number of evaluations to perform (default: 1).
* @returns An array of template evaluation results.
*/
execute(templateId: string, count?: number): Promise<TemplateEvaluationResult[]>;
/**
* Evaluates a template by resolving all references.
* @param template The template to evaluate.
* @param maxDepth Maximum resolution depth to prevent infinite loops.
* @param visitedTables Set of table IDs and names that have been visited in this resolution chain.
* @returns The evaluated template string.
*/
private evaluateTemplate;
/**
* Finds a table referenced by a template reference.
* @param reference The template reference
* @returns The referenced table, or null if not found
*/
private findReferencedTable;
/**
* Rolls on a referenced table multiple times and resolves any nested templates.
* @param table The table to roll on
* @param count Number of times to roll
* @param maxDepth Maximum resolution depth for nested templates
* @param visitedTables Set of table IDs and names that have been visited in this resolution chain
* @returns Array of roll result contents
*/
private rollOnReferencedTable;
}