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.04 kB
JavaScript
import { z } from 'zod';
import { BaseTool } from './tool.js';
/**
* Tool for getting a roll template by ID.
*/
export class GetTemplateTool extends BaseTool {
/**
* Creates a new GetTemplateTool 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 'get_template';
}
/**
* Gets the description of the tool.
* @returns The tool description.
*/
getToolDescription() {
return 'Get a roll template by ID.';
}
/**
* 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 get'),
});
}
/**
* Gets the output schema for the tool.
* @returns The output schema.
*/
getOutputSchema() {
return z
.object({
id: z.string().describe('The ID of the template'),
name: z.string().describe('The name of the template'),
description: z.string().describe('The description of the template'),
template: z.string().describe('The template string'),
})
.nullable();
}
/**
* Implements the tool execution logic.
* @param args The validated tool arguments.
* @returns The tool result.
*/
async executeImpl(args) {
const { id } = args;
// Call the template service to get the template
const template = await this.templateService.getTemplate(id);
if (!template) {
return null;
}
return {
id: template.id,
name: template.name,
description: template.description,
template: template.template.toString(),
};
}
}
//# sourceMappingURL=get-template-tool.js.map