Skip to main content
Glama
qckfx

Tree-Hugger-JS MCP Server

by qckfx

analyze_scopes

Analyzes JavaScript/TypeScript code to detect variable scope issues, identify naming conflicts, and find unused variables for improved code quality.

Instructions

Analyze variable scopes, bindings, and potential naming conflicts. Advanced tool for code quality analysis.

Examples: • Variable shadowing detection: analyze_scopes() to find naming conflicts • Closure analysis: analyze_scopes() to understand variable capture • Refactoring safety: analyze_scopes() before variable renames • Code review: analyze_scopes() to identify scope-related issues • Learning aid: analyze_scopes({includeBuiltins: true}) to see all identifiers • Dead code detection: analyze_scopes() to find unused variables

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeBuiltinsNoInclude built-in identifiers (default: false). Set true for comprehensive analysis including globals.

Implementation Reference

  • The primary handler function for the 'analyze_scopes' tool. It checks if an AST is loaded, calls the tree-hugger library's analyzeScopes method, and returns a placeholder scope analysis result.
    private async analyzeScopes(args: { includeBuiltins?: boolean }) {
      if (!this.currentAST) {
        return {
          content: [{
            type: "text",
            text: "No AST loaded. Please use parse_code first.",
          }],
          isError: true,
        };
      }
    
      try {
        const scopes = this.currentAST.tree.analyzeScopes();
        
        // Note: This is a simplified scope analysis implementation
        // The actual tree-hugger-js library may have more sophisticated scope analysis
        const scopeInfo = {
          message: "Scope analysis completed",
          scopeCount: "Scope analysis functionality depends on tree-hugger-js implementation",
          note: "This is a placeholder - actual implementation would use tree-hugger-js scope analysis features",
        };
    
        return {
          content: [{
            type: "text",
            text: `Scope Analysis Results:\n${JSON.stringify(scopeInfo, null, 2)}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error analyzing scopes: ${error instanceof Error ? error.message : String(error)}`,
          }],
          isError: true,
        };
      }
    }
  • src/index.ts:443-444 (registration)
    Dispatch registration in the tool request handler switch statement that maps 'analyze_scopes' calls to the analyzeScopes method.
    case "analyze_scopes":
      return await this.analyzeScopes(args as { includeBuiltins?: boolean });
  • Tool registration object in the listTools array, defining the name, description, and input schema (optional includeBuiltins boolean) for the analyze_scopes tool.
    {
      name: "analyze_scopes",
      description: "Analyze variable scopes, bindings, and potential naming conflicts. Advanced tool for code quality analysis.\n\nExamples:\n• Variable shadowing detection: analyze_scopes() to find naming conflicts\n• Closure analysis: analyze_scopes() to understand variable capture\n• Refactoring safety: analyze_scopes() before variable renames\n• Code review: analyze_scopes() to identify scope-related issues\n• Learning aid: analyze_scopes({includeBuiltins: true}) to see all identifiers\n• Dead code detection: analyze_scopes() to find unused variables",
      inputSchema: {
        type: "object",
        properties: {
          includeBuiltins: {
            type: "boolean",
            description: "Include built-in identifiers (default: false). Set true for comprehensive analysis including globals."
          }
        },
      },
    },
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 describes the tool's purpose and use cases but lacks details on behavioral traits like whether it modifies code (likely read-only based on 'analyze'), performance considerations, error handling, or output format. The examples hint at functionality but don't fully compensate for the missing annotations.

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 appropriately sized and front-loaded with a clear purpose statement followed by a bulleted list of examples. Each example earns its place by illustrating specific use cases, though the repetition of 'analyze_scopes()' in each bullet is slightly redundant. Overall, it's efficient and well-structured.

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 complexity (advanced code analysis), lack of annotations, and no output schema, the description is moderately complete. It covers purpose and usage well but lacks details on behavioral traits and output format, which are important for an analysis tool. The examples help but don't fully address these gaps, making it adequate but with clear room for improvement.

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% for the single parameter (includeBuiltins), so the schema already documents it thoroughly. The description adds minimal value by mentioning includeBuiltins in one example ('Learning aid'), but doesn't provide additional semantics beyond what the schema states. This meets the baseline of 3 when schema coverage is high.

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 tool analyzes 'variable scopes, bindings, and potential naming conflicts' for 'code quality analysis', providing a specific verb and resource. However, it doesn't explicitly differentiate from sibling tools like get_functions or get_classes, which might also analyze code structure but with different focuses.

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

Usage Guidelines4/5

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

The description provides clear context through six example use cases (e.g., variable shadowing detection, closure analysis, refactoring safety), which implicitly guide when to use this tool. However, it doesn't explicitly state when NOT to use it or name alternatives among sibling tools, such as when to use find_pattern instead for different analysis needs.

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