Skip to main content
Glama
angrysky56

Narrative Graph MCP

rtm_create_narrative_tree

Encode narrative text into a structured tree model for information compression and recall using configurable cognitive parameters.

Instructions

Create a Random Tree Model encoding of a narrative text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesThe narrative text to encode
titleYesTitle of the narrative
typeNoType of narrativeother
maxBranchingFactorNoMaximum number of child nodes (K parameter)
maxRecallDepthNoMaximum depth for recall (D parameter)

Implementation Reference

  • The exported default handler function implementing the core logic of rtm_create_narrative_tree: parses input, builds RTM narrative tree using core builders, computes stats, and returns JSON-formatted result.
    interface CreateNarrativeTreeParams { text: string; title: string; type?: 'story' | 'article' | 'dialogue' | 'technical' | 'other'; maxBranchingFactor?: number; maxRecallDepth?: number; } // Tool implementation 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 input schema for validating tool parameters: text, title, type, maxBranchingFactor, maxRecallDepth.
    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)
    Tool registry mapping the 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)
    Tool definition registration including name, description, and input schema for listTools response and validation.
    { name: 'rtm_create_narrative_tree', description: 'Create a Random Tree Model encoding of a narrative text', inputSchema: createNarrativeTreeSchema, },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/angrysky56/narrative-graph-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server