Skip to main content
Glama

analyze_file

Analyze code to identify legacy imports, components, props, hooks, and Tailwind patterns for migration to HeroUI v3.

Instructions

Analyze code and return detailed findings about legacy imports, components, props, hooks and Tailwind patterns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes
filenameNo

Implementation Reference

  • The main handler function for the `analyze_file` MCP tool. It orchestrates compatibility checks, Tailwind analysis, and AST traversal.
    export async function analyzeFile(code: string, filename?: string): Promise<AnalyzeFileResult> {
      const findings: any[] = [];
      const manualSteps: string[] = [];
    
      // run compatibility helpers first (imports/hooks/props that weren't captured by AST)
      const issues = checkV3Compatibility(code);
      for (const msg of issues) {
        findings.push({ type: "doc", severity: "warning", message: msg, autoFixable: false, confidence: 0.5 });
      }
    
      // tailwind plugin check
      const tw = analyzeTailwindConfig(code);
      for (const iss of tw.issues) {
        findings.push({ type: "tailwind", severity: "warning", message: iss, autoFixable: false, confidence: 0.6 });
      }
    
      // AST-based scanning for more precise locations and types
      try {
        const ast = parse(code, { sourceType: "module", plugins: ["jsx", "typescript"], locations: true });
        traverse(ast, {
          ImportDeclaration(path: any) {
            const src = path.node.source.value;
            if (src.includes("@nextui-org/react")) {
              const loc = path.node.loc?.start;
              findings.push({
                type: "import",
                severity: "warning",
                message: `Legacy import source ${src}`,
                autoFixable: true,
                confidence: 0.8,
                location: loc ? { line: loc.line, column: loc.column } : undefined,
              });
            }
            path.node.specifiers.forEach((spec: any) => {
              if (t.isImportSpecifier(spec)) {
                const name = spec.imported.name;
                if (KNOWN_V2_IMPORTS[name]) {
                  const loc = spec.loc?.start;
                  findings.push({
                    type: "import",
                    severity: "info",
                    message: `Legacy component import ${name}`,
                    component: name,
                    autoFixable: true,
                    confidence: 0.7,
                    location: loc ? { line: loc.line, column: loc.column } : undefined,
                  });
                }
              }
            });
          },
          JSXOpeningElement(path: any) {
            const nameNode = path.node.name;
            if (t.isJSXIdentifier(nameNode)) {
              const name = nameNode.name;
              if (KNOWN_V2_IMPORTS[name]) {
                const loc = nameNode.loc?.start;
  • src/server.ts:419-432 (registration)
    Tool registration for `analyze_file` in the MCP server setup. It handles input parsing and invokes the core migration logic.
    server.registerTool(
      "analyze_file",
      {
        title: "Analyze file",
        description: "Analyze code and return detailed findings about legacy imports, components, props, hooks and Tailwind patterns.",
        inputSchema: { code: z.string(), filename: z.string().optional() }
      },
      async ({ code, filename }) => {
        const { analyzeFile } = await import("./core/migration.js");
        const result = await analyzeFile(code, filename);
        AnalyzeFileResultSchema.parse(result);
        return { content: [], structuredContent: result as any };
      }
    );

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/sctg-development/heroui-migration-mcp'

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