rtm_create_narrative_tree
Convert narrative text into a structured tree model with configurable branching and depth parameters for efficient encoding and recall of information in the Narrative Graph MCP.
Instructions
Create a Random Tree Model encoding of a narrative text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxBranchingFactor | No | Maximum number of child nodes (K parameter) | |
| maxRecallDepth | No | Maximum depth for recall (D parameter) | |
| text | Yes | The narrative text to encode | |
| title | Yes | Title of the narrative | |
| type | No | Type of narrative | other |
Implementation Reference
- src/tools/createNarrativeTree.ts:15-66 (handler)The handler function that executes the tool logic: creates a narrative from input text, builds an RTM tree using RTMTreeBuilder, computes statistics, and returns the result in MCP content format.export default async function createNarrativeTree(params: CreateNarrativeTreeParams) { try { // Create narrative from text const narrative = createNarrative( params.text, params.title, params.type || 'other' ); // Create RTM parameters const parameters = { ...createDefaultParameters(), maxBranchingFactor: params.maxBranchingFactor || 4, maxRecallDepth: params.maxRecallDepth || 6 }; // Build the tree const builder = new RTMTreeBuilder(parameters); const tree = builder.buildTree(narrative); // Get tree statistics const stats = { totalNodes: tree.nodes.size, totalClauses: narrative.clauses.length, maxDepth: Math.max(...Array.from(tree.nodes.values()).map(n => n.level)), parameters: parameters }; return { content: [{ type: "text", text: JSON.stringify({ success: true, treeId: tree.id, narrativeId: narrative.id, statistics: stats, message: `Created RTM tree with ${stats.totalNodes} nodes from ${stats.totalClauses} clauses` }, null, 2) }], }; } catch (error) { return { content: [{ type: "text", text: JSON.stringify({ success: false, error: error instanceof Error ? error.message : "Unknown error occurred" }, null, 2) }], }; } }
- Zod schema defining the input parameters for the rtm_create_narrative_tree tool.export const createNarrativeTreeSchema = z.object({ text: z.string().describe('The narrative text to encode'), title: z.string().describe('Title of the narrative'), type: z.enum(['story', 'article', 'dialogue', 'technical', 'other']).default('other').describe('Type of narrative'), maxBranchingFactor: z.number().default(4).describe('Maximum number of child nodes (K parameter)'), maxRecallDepth: z.number().default(6).describe('Maximum depth for recall (D parameter)'), });
- src/index.ts:47-52 (registration)Maps the tool name 'rtm_create_narrative_tree' to its handler function createNarrativeTree.const tools = { rtm_create_narrative_tree: createNarrativeTree, rtm_generate_ensemble: generateEnsemble, rtm_traverse_narrative: traverseNarrative, rtm_find_optimal_depth: findOptimalDepth, };
- src/index.ts:56-60 (registration)Registers the tool definition including name, description, and input schema for the MCP server.{ name: 'rtm_create_narrative_tree', description: 'Create a Random Tree Model encoding of a narrative text', inputSchema: createNarrativeTreeSchema, },