Skip to main content
Glama

check_imports

Analyzes code import statements to identify circular dependencies, unused imports, and missing modules for cleaner, more maintainable code.

Instructions

Checks import statements in code for common issues like circular dependencies, unused imports, and missing modules.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesThe code to check imports for
languageYesProgramming language (javascript, typescript, python)

Implementation Reference

  • The core handler function for the 'check_imports' tool. It parses code lines, extracts imports based on language (JavaScript/TypeScript/Python), checks for issues like invalid syntax, deep relative imports, and wildcards, then generates a markdown report with found imports, issues, and recommendations.
    export function checkImportsHandler(args: any) {
        const { code, language } = args;
        const lines = code.split("\n");
        const issues: string[] = [];
        const imports: string[] = [];
    
        // Extract imports based on language
        if (language === "javascript" || language === "typescript") {
            lines.forEach((line: string, i: number) => {
                if (line.includes("import ") || line.includes("require(")) {
                    imports.push(line.trim());
                    // Check for common issues
                    if (line.includes("* as") && !line.includes("from")) {
                        issues.push(`Line ${i + 1}: Invalid wildcard import syntax`);
                    }
                    if (line.includes("..")) {
                        // Potentially deep relative import
                        const depth = (line.match(/\.\.\//g) || []).length;
                        if (depth > 3) {
                            issues.push(`Line ${i + 1}: Deep relative import (${depth} levels) - consider absolute imports`);
                        }
                    }
                }
            });
        } else if (language === "python") {
            lines.forEach((line: string, i: number) => {
                if (line.startsWith("import ") || line.startsWith("from ")) {
                    imports.push(line.trim());
                    if (line.includes("import *")) {
                        issues.push(`Line ${i + 1}: Wildcard import detected - avoid 'import *'`);
                    }
                }
            });
        }
    
        const result = `# Import Analysis: ${language}
    
    ## Imports Found (${imports.length})
    ${imports.map(i => `- \`${i}\``).join("\n") || "No imports found"}
    
    ## Issues Detected (${issues.length})
    ${issues.length > 0 ? issues.map(i => `- ⚠️ ${i}`).join("\n") : "✅ No issues detected"}
    
    ## Recommendations
    - Keep imports organized (external, internal, relative)
    - Remove unused imports
    - Prefer named imports over wildcards
    - Use absolute imports for clarity
    `;
    
        return { content: [{ type: "text", text: result }] };
    }
  • The schema definition for the 'check_imports' tool, specifying the tool name, description, and input schema using Zod for validation (code string and language string).
    export const checkImportsSchema = {
        name: "check_imports",
        description: "Checks import statements in code for common issues like circular dependencies, unused imports, and missing modules.",
        inputSchema: z.object({
            code: z.string().describe("The code to check imports for"),
            language: z.string().describe("Programming language (javascript, typescript, python)")
        })
    };
  • src/index.ts:103-103 (registration)
    Registration of the 'check_imports' tool in the main stdio server toolRegistry Map, linking schema and handler.
    ["check_imports", { schema: checkImportsSchema, handler: checkImportsHandler }],
  • src/server.ts:103-103 (registration)
    Registration of the 'check_imports' tool in the HTTP server toolRegistry Map, linking schema and handler.
    ["check_imports", { schema: checkImportsSchema, handler: checkImportsHandler }],
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions what issues are checked, it doesn't describe the tool's behavior: what format the results come in, whether it's a read-only analysis or modifies code, what happens with invalid input, or any performance characteristics. For a tool with no annotation coverage, this leaves significant gaps in understanding how it operates.

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

Conciseness5/5

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

The description is a single, efficient sentence that communicates the core functionality without unnecessary words. It's front-loaded with the main purpose and provides specific examples of what's checked. Every part of the sentence serves a clear informational purpose with zero waste.

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

Completeness2/5

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

For a tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the tool returns (analysis results, error messages, structured data), how results are formatted, or what happens when issues are found. Given the complexity of code analysis and the lack of structured output information, the description should provide more context about the tool's behavior and results.

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 documents both parameters ('code' and 'language') with their types and requirements. The description doesn't add any parameter-specific information beyond what's in the schema. It doesn't explain parameter relationships, constraints, or usage patterns. With complete schema coverage, the baseline of 3 is appropriate.

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's purpose: 'Checks import statements in code for common issues like circular dependencies, unused imports, and missing modules.' It specifies the verb ('checks'), resource ('import statements in code'), and provides concrete examples of issues detected. However, it doesn't explicitly differentiate from sibling tools like 'check_dependencies' or 'validate_code', which might have overlapping functionality.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'check_dependencies', 'lint_code', and 'validate_code' available, there's no indication of how this tool differs or when it's the appropriate choice. The description only states what the tool does, not when it should be selected.

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/millsydotdev/Code-MCP'

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