Skip to main content
Glama

Tree-Hugger-JS MCP Server

by qckfx

get_node_at_position

Retrieve detailed AST node information at a specific cursor position for debugging, refactoring, and code analysis. Use line and column inputs to identify node type, debug syntax errors, or assist 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

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

Input Schema (JSON Schema)

{ "properties": { "column": { "description": "Column number (0-based) - the character position within the line", "type": "number" }, "line": { "description": "Line number (1-based) - the line where cursor is positioned", "type": "number" } }, "required": [ "line", "column" ], "type": "object" }

Implementation Reference

  • The primary handler function for the 'get_node_at_position' tool. It retrieves the AST node at the specified line and column using tree.nodeAt(), constructs detailed node information including type, text, positions, parent, and children count, and returns it formatted as MCP content.
    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, }; } }
  • src/index.ts:440-441 (registration)
    Dispatch case in the central tool request handler (switch statement) that routes calls to the specific getNodeAtPosition handler method.
    case "get_node_at_position": return await this.getNodeAtPosition(args as { line: number; column: number });
  • Input schema definition specifying required 'line' (1-based number) and 'column' (0-based number) parameters for the tool.
    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:348-365 (registration)
    Tool registration object added to the MCP server's tools array, including name, detailed description with usage examples, 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"], }, },

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

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