Skip to main content
Glama
angrysky56

Narrative Graph MCP

rtm_find_optimal_depth

Determine the optimal traversal depth to achieve a target number of recall clauses for narrative text analysis using the Random Tree Model.

Instructions

Find the optimal traversal depth to achieve a target recall length

Input Schema

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

Implementation Reference

  • The main handler function that implements the rtm_find_optimal_depth tool logic: builds RTM tree from narrative, finds optimal traversal depth for target recall length, computes neighboring depths comparison, and returns structured results.
    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: 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)
    Tool registry mapping 'rtm_find_optimal_depth' to the findOptimalDepth handler function for execution.
    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 providing name, description, and input schema for ListTools response.
    {
      name: 'rtm_find_optimal_depth',
      description: 'Find the optimal traversal depth to achieve a target recall length',
      inputSchema: findOptimalDepthSchema,
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'optimal traversal depth' and 'target recall length', implying a computational or analytical operation, but fails to describe key behaviors such as what 'optimal' means (e.g., based on efficiency, accuracy), whether it's a read-only or mutative process, performance characteristics, or error handling. This leaves significant gaps for an agent to understand how the tool behaves beyond its basic function.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that directly states the tool's purpose without any fluff or redundancy. It's front-loaded and efficiently communicates the core function, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity implied by terms like 'optimal traversal depth' and 'recall length', and with no annotations or output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a depth value, a report), how 'optimal' is determined, or the computational context. For a tool with 5 parameters and analytical nature, more detail is needed to guide an agent effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional meaning beyond what the schema provides (e.g., it doesn't explain how parameters like 'maxBranchingFactor' or 'maxRecallDepth' relate to finding the optimal depth). Baseline 3 is appropriate as the schema does the heavy lifting, but the description doesn't compensate with extra insights.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Find') and the goal ('optimal traversal depth to achieve a target recall length'), which is specific and actionable. However, it doesn't explicitly differentiate from sibling tools like 'rtm_traverse_narrative' or 'rtm_create_narrative_tree', leaving some ambiguity about when to use this versus those alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus its siblings (e.g., 'rtm_traverse_narrative', 'rtm_create_narrative_tree', 'rtm_generate_ensemble'). It lacks context about prerequisites, alternatives, or exclusions, leaving the agent to infer usage based on the purpose alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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