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; }

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