Skip to main content
Glama
angrysky56

Narrative Graph MCP

rtm_find_optimal_depth

Determine the optimal traversal depth for narrative analysis to reach a target recall length, using configurable branching and depth parameters for efficient information retrieval.

Instructions

Find the optimal traversal depth to achieve a target recall length

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxBranchingFactorNoMaximum number of child nodes (K parameter)
maxRecallDepthNoMaximum depth for recall (D parameter)
targetRecallLengthYesTarget number of clauses to recall
textYesThe narrative text to analyze
titleYesTitle of the narrative

Implementation Reference

  • The main handler function that implements the core logic for the 'rtm_find_optimal_depth' tool. It builds an RTM tree from the input narrative, finds the optimal traversal depth to match the target recall length, computes accuracy, and provides depth comparisons.
    export default async function findOptimalDepth(params: FindOptimalDepthParams) { try { // Create narrative and build tree const narrative = createNarrative(params.text, params.title); const parameters = { ...createDefaultParameters(), maxBranchingFactor: params.maxBranchingFactor || 4, maxRecallDepth: params.maxRecallDepth || 6 }; const builder = new RTMTreeBuilder(parameters); const tree = builder.buildTree(narrative); // Create clause map for traversal const clauseMap = new Map( narrative.clauses.map(c => [c.id, c]) ); // Find optimal depth const traversal = createTraversal(tree, clauseMap); const optimalDepth = traversal.findOptimalDepth(params.targetRecallLength); // Get results at optimal depth const optimalResult = traversal.traverseToDepth(optimalDepth); // Also get results at neighboring depths for comparison const depthComparison = []; for (let d = Math.max(1, optimalDepth - 1); d <= Math.min(optimalDepth + 1, parameters.maxRecallDepth); d++) { const result = traversal.traverseToDepth(d); depthComparison.push({ depth: d, recallLength: result.totalClauses, compressionRatio: result.compressionRatio, nodeCount: result.nodes.length }); } const accuracy = (1 - Math.abs(optimalResult.totalClauses - params.targetRecallLength) / params.targetRecallLength) * 100; return { content: [{ type: "text", text: JSON.stringify({ success: true, treeId: tree.id, targetRecallLength: params.targetRecallLength, optimalDepth: optimalDepth, actualRecallLength: optimalResult.totalClauses, accuracy: accuracy, depthComparison: depthComparison, message: `Found optimal depth ${optimalDepth} yielding ${optimalResult.totalClauses} clauses (${accuracy.toFixed(1)}% accuracy)` }, 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 defining parameters for the 'rtm_find_optimal_depth' tool: text, title, targetRecallLength, optional maxBranchingFactor and maxRecallDepth.
    export const findOptimalDepthSchema = z.object({ text: z.string().describe('The narrative text to analyze'), title: z.string().describe('Title of the narrative'), targetRecallLength: z.number().min(1).describe('Target number of clauses to recall'), 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)
    Registration of tool handlers in the tools object, mapping 'rtm_find_optimal_depth' to the findOptimalDepth handler function.
    const tools = { rtm_create_narrative_tree: createNarrativeTree, rtm_generate_ensemble: generateEnsemble, rtm_traverse_narrative: traverseNarrative, rtm_find_optimal_depth: findOptimalDepth, };
  • src/index.ts:71-75 (registration)
    Tool definition registration in toolDefinitions array, specifying name, description, and input schema for 'rtm_find_optimal_depth'.
    { name: 'rtm_find_optimal_depth', description: 'Find the optimal traversal depth to achieve a target recall length', inputSchema: findOptimalDepthSchema, },

Other Tools

Related Tools

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