Skip to main content
Glama
qckfx

Tree-Hugger-JS MCP Server

by qckfx

get_node_at_position

Retrieve detailed AST node information at a specific cursor position for debugging, code analysis, refactoring, and IDE integration.

Instructions

Get detailed AST node information at a specific cursor position. Perfect for debugging and precise analysis.

Examples: • Debug syntax errors: get_node_at_position(15, 23) to understand what's at error location • Understand code structure: get_node_at_position(line, col) to see AST node type at cursor • Refactoring assistance: get_node_at_position(line, col) to identify exact node before transformation • IDE integration: get_node_at_position(line, col) for hover information • Pattern development: get_node_at_position(line, col) to understand node structure for pattern writing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lineYesLine number (1-based) - the line where cursor is positioned
columnYesColumn number (0-based) - the character position within the line

Implementation Reference

  • The primary handler function that executes the tool logic: checks for loaded AST, uses tree.nodeAt(line, column) to find the node, builds a detailed nodeInfo object, and returns formatted text response.
    private async getNodeAtPosition(args: { line: number; column: number }) {
      if (!this.currentAST) {
        return {
          content: [{
            type: "text",
            text: "No AST loaded. Please use parse_code first.",
          }],
          isError: true,
        };
      }
    
      try {
        const node = this.currentAST.tree.nodeAt(args.line, args.column);
        
        if (!node) {
          return {
            content: [{
              type: "text",
              text: `No node found at position ${args.line}:${args.column}`,
            }],
          };
        }
    
        const nodeInfo = {
          type: node.type,
          text: node.text.length > 200 ? node.text.slice(0, 200) + '...' : node.text,
          line: node.line,
          column: node.column,
          name: node.name,
          startPosition: node.startPosition,
          endPosition: node.endPosition,
          parent: node.parent ? {
            type: node.parent.type,
            name: node.parent.name,
          } : null,
          childrenCount: node.children.length,
        };
    
        return {
          content: [{
            type: "text",
            text: `Node at position ${args.line}:${args.column}:\n${JSON.stringify(nodeInfo, null, 2)}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error getting node at position: ${error instanceof Error ? error.message : String(error)}`,
          }],
          isError: true,
        };
      }
    }
  • Input schema defining the required parameters: line (1-based number) and column (0-based number).
    inputSchema: {
      type: "object",
      properties: {
        line: {
          type: "number",
          description: "Line number (1-based) - the line where cursor is positioned"
        },
        column: {
          type: "number", 
          description: "Column number (0-based) - the character position within the line"
        }
      },
      required: ["line", "column"],
    },
  • src/index.ts:349-365 (registration)
    Tool registration entry in the MCP server's tools list, including name, description, and input schema.
      name: "get_node_at_position",
      description: "Get detailed AST node information at a specific cursor position. Perfect for debugging and precise analysis.\n\nExamples:\n• Debug syntax errors: get_node_at_position(15, 23) to understand what's at error location\n• Understand code structure: get_node_at_position(line, col) to see AST node type at cursor\n• Refactoring assistance: get_node_at_position(line, col) to identify exact node before transformation\n• IDE integration: get_node_at_position(line, col) for hover information\n• Pattern development: get_node_at_position(line, col) to understand node structure for pattern writing",
      inputSchema: {
        type: "object",
        properties: {
          line: {
            type: "number",
            description: "Line number (1-based) - the line where cursor is positioned"
          },
          column: {
            type: "number", 
            description: "Column number (0-based) - the character position within the line"
          }
        },
        required: ["line", "column"],
      },
    },
  • src/index.ts:440-441 (registration)
    Dispatch case in the central request handler switch that routes tool calls to the getNodeAtPosition method.
    case "get_node_at_position":
      return await this.getNodeAtPosition(args as { line: number; column: number });
Behavior3/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 clearly indicates this is a read operation for 'detailed AST node information' and 'debugging and precise analysis,' which implies non-destructive behavior. However, it doesn't disclose potential limitations like what happens with invalid positions, error formats, or performance characteristics. The description adds value but doesn't provide comprehensive behavioral context.

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

Conciseness4/5

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

The description is well-structured with a clear purpose statement followed by bullet-point examples. Each example sentence earns its place by illustrating different use cases. While slightly verbose due to repeated parameter examples, the structure is effective and front-loaded with the core purpose. No wasted sentences, but could be slightly more concise.

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

Completeness3/5

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

Given the tool's moderate complexity (position-based AST query), no annotations, and no output schema, the description provides good usage context but lacks details about return values, error conditions, or performance. The examples help compensate, but for a debugging/analysis tool without output schema, more information about what 'detailed AST node information' includes would improve completeness.

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%, providing clear documentation for both parameters (line and column). The description doesn't add significant semantic information beyond what's in the schema, though it reinforces the parameters through repeated examples. With high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting for parameter documentation.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verb ('Get detailed AST node information') and resource ('at a specific cursor position'). It distinguishes from siblings by focusing on position-based node retrieval rather than broader analysis (analyze_scopes), pattern matching (find_pattern), or code transformation (transform_code). The title being null doesn't affect this clarity.

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

Usage Guidelines5/5

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

The description provides explicit usage guidance through five concrete examples (debugging syntax errors, understanding code structure, refactoring assistance, IDE integration, pattern development). These examples clearly illustrate when to use this tool versus alternatives like get_classes (for class-level analysis) or transform_code (for modifications). The examples serve as effective when-to-use guidance.

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/qckfx/tree-hugger-js-mcp'

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