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.
100 lines (99 loc) • 3.06 kB
TypeScript
import { TableEntry } from './table-entry.js';
import { RollResult } from './roll-result.js';
/**
* Represents a random table with entries that can be rolled on.
*/
export declare class RandomTable {
readonly id: string;
readonly name: string;
readonly description: string;
private _entries;
/**
* Creates a new RandomTable instance.
* @param id Unique identifier for the table.
* @param name Table name.
* @param description Optional description.
* @param entries Optional initial entries.
*/
constructor(id: string, name: string, description?: string, entries?: TableEntry[]);
/**
* Gets all entries in this table.
* @returns An array of TableEntry objects.
*/
get entries(): TableEntry[];
/**
* Gets the total weight of all entries in this table.
* @returns The sum of all entry weights.
*/
get totalWeight(): number;
/**
* Adds a new entry to the table.
* @param entry The entry to add.
* @throws Error if an entry with the same ID already exists.
*/
addEntry(entry: TableEntry): void;
/**
* Removes an entry from the table.
* @param entryId The ID of the entry to remove.
* @throws Error if the entry does not exist.
*/
removeEntry(entryId: string): void;
/**
* Updates an existing entry in the table.
* @param entryId The ID of the entry to update.
* @param updates Object containing the properties to update.
* @throws Error if the entry does not exist.
*/
updateEntry(entryId: string, updates: Partial<Omit<TableEntry, 'id'>>): void;
/**
* Gets an entry by ID.
* @param entryId The ID of the entry to get.
* @returns The entry, or undefined if it does not exist.
*/
getEntry(entryId: string): TableEntry | undefined;
/**
* Performs a roll on the table using a random number generator.
* @param rng A function that returns a random number between 0 and 1.
* @returns A RollResult object.
* @throws Error if the table has no entries.
*/
roll(rng?: () => number): RollResult;
/**
* Creates a RandomTable from a plain object.
* @param obj The object to create the table from.
* @returns A new RandomTable instance.
*/
static fromObject(obj: {
id: string;
name: string;
description?: string;
entries?: Array<{
id: string;
content: string;
weight?: number;
range?: {
min: number;
max: number;
};
}>;
}): RandomTable;
/**
* Converts this table to a plain object.
* @returns A plain object representation of this table.
*/
toObject(): RandomTableDTO;
}
export interface RandomTableDTO {
id: string;
name: string;
description: string;
entries: Array<{
id: string;
content: string;
weight: number;
range?: {
min: number;
max: number;
};
}>;
}