Skip to main content
Glama
qckfx

Tree-Hugger-JS MCP Server

by qckfx

get_imports

Analyze JavaScript/TypeScript code to extract import statements for dependency tracking, security audits, bundle optimization, and refactoring preparation.

Instructions

Get all import statements with detailed module and specifier information. Essential for dependency analysis.

Examples: • Dependency audit: get_imports() to see all external dependencies • Bundle analysis: get_imports() to identify heavy imports • Security audit: get_imports() to check for suspicious packages • TypeScript analysis: get_imports({includeTypeImports: false}) to focus on runtime imports • Refactoring prep: get_imports() to understand module structure before changes • License compliance: get_imports() to generate dependency list

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeTypeImportsNoInclude TypeScript type-only imports (default: true). Set false for runtime dependency analysis.

Implementation Reference

  • The primary handler function implementing the get_imports tool. It retrieves import statements from the parsed AST using tree-hugger-js, filters type-only imports if specified, extracts module names and specifiers using helper functions, and formats the results.
    private async getImports(args: { includeTypeImports?: boolean }) {
      if (!this.currentAST) {
        return {
          content: [{
            type: "text",
            text: "No AST loaded. Please use parse_code first.",
          }],
          isError: true,
        };
      }
    
      try {
        let imports = this.currentAST.tree.imports();
        
        if (args.includeTypeImports === false) {
          imports = imports.filter(imp => !imp.text.includes('type '));
        }
    
        const importData = imports.map(imp => ({
          module: this.extractModuleName(imp.text),
          specifiers: this.extractImportSpecifiers(imp.text),
          line: imp.line,
          column: imp.column,
          isTypeOnly: imp.text.includes('type '),
          text: imp.text,
        }));
    
        this.lastAnalysis = {
          ...this.lastAnalysis,
          imports: importData,
          timestamp: new Date(),
        } as AnalysisResult;
    
        return {
          content: [{
            type: "text",
            text: `Found ${importData.length} imports:\n${JSON.stringify(importData, null, 2)}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error getting imports: ${error instanceof Error ? error.message : String(error)}`,
          }],
          isError: true,
        };
      }
    }
  • The schema definition for the get_imports tool, including name, detailed description, and inputSchema specifying the optional includeTypeImports parameter.
    {
      name: "get_imports",
      description: "Get all import statements with detailed module and specifier information. Essential for dependency analysis.\n\nExamples:\n• Dependency audit: get_imports() to see all external dependencies\n• Bundle analysis: get_imports() to identify heavy imports\n• Security audit: get_imports() to check for suspicious packages\n• TypeScript analysis: get_imports({includeTypeImports: false}) to focus on runtime imports\n• Refactoring prep: get_imports() to understand module structure before changes\n• License compliance: get_imports() to generate dependency list",
      inputSchema: {
        type: "object",
        properties: {
          includeTypeImports: {
            type: "boolean",
            description: "Include TypeScript type-only imports (default: true). Set false for runtime dependency analysis."
          }
        },
      },
    },
  • src/index.ts:428-429 (registration)
    The registration of the get_imports tool handler in the main tool dispatcher switch statement within the CallToolRequestSchema handler.
    case "get_imports":
      return await this.getImports(args as { includeTypeImports?: boolean });
  • Helper function that extracts the module specifier from an import statement text using regex.
    private extractModuleName(importText: string): string {
      const match = importText.match(/from\s+['"]([^'"]+)['"]/);
      return match ? match[1] : 'unknown';
    }
  • Helper function that parses various import specifier formats (default, named, namespace) from the import statement text.
    private extractImportSpecifiers(importText: string): string[] {
      const defaultMatch = importText.match(/import\s+(\w+)(?=\s*[,{]|\s+from)/);
      const namedMatch = importText.match(/import\s*(?:\w+\s*,\s*)?{([^}]+)}/);
      const namespaceMatch = importText.match(/import\s*\*\s*as\s+(\w+)/);
      
      const specifiers: string[] = [];
      
      if (defaultMatch) {
        specifiers.push(defaultMatch[1]);
      }
      
      if (namedMatch) {
        const named = namedMatch[1].split(',').map(s => s.trim().split(' as ')[0].trim());
        specifiers.push(...named);
      }
      
      if (namespaceMatch) {
        specifiers.push(`* as ${namespaceMatch[1]}`);
      }
      
      return specifiers;
    }
Behavior4/5

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

With no annotations provided, the description carries full burden of behavioral disclosure. It effectively describes the tool's purpose and use cases, though it doesn't explicitly mention performance characteristics, rate limits, or authentication requirements. The examples provide good context about what kind of analysis the tool enables.

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

Conciseness3/5

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

The description is front-loaded with the core purpose statement, but the extensive examples section (6 bullet points) adds significant length. While the examples are helpful for usage guidelines, they make the description less concise than ideal. Each example earns its place by illustrating different use cases.

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

Completeness4/5

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

For a single-parameter tool with no annotations and no output schema, the description provides substantial context through purpose statement and detailed examples. It adequately explains what the tool does and when to use it, though it doesn't describe the return format or structure of the import data.

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 fully documents the single parameter. The description adds minimal parameter-specific information beyond what's in the schema (only mentioning includeTypeImports in one example). This meets the baseline expectation when schema coverage is complete.

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') and resource ('all import statements with detailed module and specifier information'). It distinguishes from siblings like 'remove_unused_imports' or 'parse_code' by focusing specifically on import analysis rather than modification or general parsing.

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 scenarios through six detailed examples (dependency audit, bundle analysis, security audit, TypeScript analysis, refactoring prep, license compliance), clearly indicating when to use this tool. It also distinguishes from alternatives by showing how parameter configuration (includeTypeImports) enables specific use cases.

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