Skip to main content
Glama
qckfx

Tree-Hugger-JS MCP Server

by qckfx

remove_unused_imports

Automatically remove unused import statements to clean up JavaScript/TypeScript code. Detects unused imports safely to reduce bundle size and improve code quality.

Instructions

Automatically remove unused import statements to clean up code. Safely detects which imports are actually used.

Examples: • Bundle size optimization: remove_unused_imports() to reduce bundle size • Code cleanup: remove_unused_imports() after refactoring • Linting compliance: remove_unused_imports() to fix ESLint warnings • Before deployment: remove_unused_imports({preview: true}) to see what will be removed • Legacy cleanup: remove_unused_imports() after removing old code • Development workflow: remove_unused_imports() during feature development

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
previewNoReturn preview only without applying changes (default: false). Use to see what will be removed.

Implementation Reference

  • The core handler function that executes the remove_unused_imports tool logic. It uses the tree-hugger-js library's transform().removeUnusedImports() method to safely remove unused imports from the current AST, with optional preview mode and state updates.
    private async removeUnusedImports(args: { preview?: boolean }) {
      if (!this.currentAST) {
        return {
          content: [{
            type: "text",
            text: "No AST loaded. Please use parse_code first.",
          }],
          isError: true,
        };
      }
    
      try {
        const transformed = this.currentAST.tree.transform()
          .removeUnusedImports();
    
        const result = transformed.toString();
        
        if (!args.preview) {
          this.currentAST.sourceCode = result;
          this.currentAST.tree = parse(result);
          this.currentAST.timestamp = new Date();
        }
    
        const transformResult: TransformResult = {
          operation: "remove_unused_imports",
          parameters: {},
          preview: result.slice(0, 500) + (result.length > 500 ? '...' : ''),
          timestamp: new Date(),
        };
        
        this.transformHistory.push(transformResult);
    
        return {
          content: [{
            type: "text",
            text: `${args.preview ? 'Preview: ' : ''}Removed unused imports\n\n${args.preview ? 'Preview:\n' : 'Result:\n'}${result}`,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error removing unused imports: ${error instanceof Error ? error.message : String(error)}`,
          }],
          isError: true,
        };
      }
    }
  • src/index.ts:434-435 (registration)
    Registration of the tool in the CallToolRequestSchema switch statement, dispatching to the handler method.
    case "remove_unused_imports":
      return await this.removeUnusedImports(args as { preview?: boolean });
  • Tool registration in ListToolsRequestSchema including name, description, and input schema for validation.
    {
      name: "remove_unused_imports",
      description: "Automatically remove unused import statements to clean up code. Safely detects which imports are actually used.\n\nExamples:\n• Bundle size optimization: remove_unused_imports() to reduce bundle size\n• Code cleanup: remove_unused_imports() after refactoring\n• Linting compliance: remove_unused_imports() to fix ESLint warnings\n• Before deployment: remove_unused_imports({preview: true}) to see what will be removed\n• Legacy cleanup: remove_unused_imports() after removing old code\n• Development workflow: remove_unused_imports() during feature development",
      inputSchema: {
        type: "object",
        properties: {
          preview: {
            type: "boolean",
            description: "Return preview only without applying changes (default: false). Use to see what will be removed."
          }
        },
      },
  • Helper usage of removeUnusedImports transformer method within the composite transform_code tool.
    case "removeUnusedImports":
      transformer = transformer.removeUnusedImports();
  • Direct call to the tree-hugger-js library's removeUnusedImports() method in the handler.
    .removeUnusedImports();
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by stating the tool 'automatically' removes imports and 'safely detects' which are used. It also explains the preview parameter behavior. However, it doesn't mention potential side effects like breaking code if detection fails or whether changes are reversible.

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 with a clear purpose statement followed by six bullet-point examples. Every sentence earns its place by providing concrete usage scenarios. It could be slightly more front-loaded by moving the examples after the core description.

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 tool with one parameter, 100% schema coverage, and no output schema, the description is quite complete. It explains what the tool does, when to use it, and provides examples. The main gap is lack of output format information, but given the simplicity of the tool, this is acceptable.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% with one parameter documented in the schema. The description adds value by explaining the preview parameter's purpose in the examples ('to see what will be removed'), providing practical context beyond the schema's technical description.

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 ('remove') and resource ('unused import statements'), plus the method ('automatically' and 'safely detects'). It distinguishes from siblings like get_imports (which lists imports) and transform_code (which is more general) by focusing specifically on removal of unused imports.

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 with six concrete examples (e.g., bundle size optimization, code cleanup, linting compliance), giving clear guidance on when to use this tool. It also distinguishes from alternatives by focusing on import removal rather than analysis or other transformations.

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