Skip to main content
Glama

macroforge-autofixer

Validate TypeScript code with @derive decorators and fix validation issues. Returns structured diagnostics with error locations and suggested fixes.

Instructions

Validates TypeScript code with @derive decorators using Macroforge's native validation.

Returns structured JSON diagnostics with:

  • level: error | warning | info

  • message: What's wrong

  • location: Line and column number (when available)

  • help: Suggested fix (when available)

  • notes: Additional context (when available)

  • summary: Count of errors, warnings, and info messages

This tool MUST be used before sending Macroforge code to the user. If require_another_tool_call_after_fixing is true, fix the issues and validate again.

Detects:

  • Invalid/unknown macro names

  • Malformed @derive decorators

  • @serde validator issues (email, url, length, etc.)

  • Macro expansion failures

  • Syntax errors in generated code

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesTypeScript code with @derive decorators to validate
filenameNoFilename for the code (default: input.ts)

Implementation Reference

  • Implements the core logic for the macroforge-autofixer tool by invoking the native Macroforge expander synchronously, processing diagnostics, and returning structured JSON output.
    async function handleAutofixer(args: { code: string; filename?: string }) {
      const filename = args.filename || 'input.ts';
    
      try {
        const macroforge = await importMacroforge();
    
        if (!macroforge) {
          return {
            content: [
              {
                type: 'text' as const,
                text: JSON.stringify({
                  diagnostics: [{
                    level: 'error',
                    message: 'Native Macroforge bindings not available. Install @macroforge/core.',
                  }],
                  summary: { errors: 1, warnings: 0, info: 0 },
                  require_another_tool_call_after_fixing: false,
                }, null, 2),
              },
            ],
          };
        }
    
        const result = macroforge.expandSync(args.code, filename, {});
        const diagnostics = result.diagnostics || [];
    
        const output: AutofixerResult = {
          diagnostics: diagnostics.map((d) => ({
            level: normalizeLevel(d.level),
            message: d.message,
            location: d.span ? { line: d.span.start.line, column: d.span.start.column } : undefined,
            help: d.help || undefined,
            notes: d.notes && d.notes.length > 0 ? d.notes : undefined,
          })),
          summary: {
            errors: diagnostics.filter((d) => d.level === 'Error').length,
            warnings: diagnostics.filter((d) => d.level === 'Warning').length,
            info: diagnostics.filter((d) => d.level === 'Info').length,
          },
          require_another_tool_call_after_fixing: diagnostics.some((d) => d.level === 'Error'),
        };
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(output, null, 2),
            },
          ],
        };
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify({
                diagnostics: [{
                  level: 'error',
                  message: `Error during analysis: ${message}`,
                }],
                summary: { errors: 1, warnings: 0, info: 0 },
                require_another_tool_call_after_fixing: false,
              }, null, 2),
            },
          ],
        };
      }
    }
  • Registers the macroforge-autofixer tool with the MCP server in the listTools response, providing name, description, and input schema.
            {
              name: 'macroforge-autofixer',
              description: `Validates TypeScript code with @derive decorators using Macroforge's native validation.
    
    Returns structured JSON diagnostics with:
    - level: error | warning | info
    - message: What's wrong
    - location: Line and column number (when available)
    - help: Suggested fix (when available)
    - notes: Additional context (when available)
    - summary: Count of errors, warnings, and info messages
    
    This tool MUST be used before sending Macroforge code to the user.
    If require_another_tool_call_after_fixing is true, fix the issues and validate again.
    
    Detects:
    - Invalid/unknown macro names
    - Malformed @derive decorators
    - @serde validator issues (email, url, length, etc.)
    - Macro expansion failures
    - Syntax errors in generated code`,
              inputSchema: {
                type: 'object',
                properties: {
                  code: {
                    type: 'string',
                    description: 'TypeScript code with @derive decorators to validate',
                  },
                  filename: {
                    type: 'string',
                    description: 'Filename for the code (default: input.ts)',
                  },
                },
                required: ['code'],
              },
            },
  • Dispatches incoming tool calls for macroforge-autofixer to the handleAutofixer function within the main tools/call handler switch statement.
    case 'macroforge-autofixer':
      return handleAutofixer(args as { code: string; filename?: string });
  • Defines the TypeScript interface for the structured JSON output returned by the macroforge-autofixer handler.
    interface AutofixerResult {
      diagnostics: Array<{
        /** Severity level: "error", "warning", or "info" */
        level: string;
        /** Human-readable description of the issue */
        message: string;
        /** Source location (line and column) if available */
        location?: { line: number; column: number };
        /** Suggested fix for the issue */
        help?: string;
        /** Additional context or explanatory notes */
        notes?: string[];
      }>;
      /** Summary counts for quick overview */
      summary: {
        errors: number;
        warnings: number;
        info: number;
      };
      /** If true, client should fix issues and call autofixer again */
      require_another_tool_call_after_fixing: boolean;
    }
  • Helper function that dynamically loads the optional @macroforge/core native module used for code validation and expansion in the handler.
    async function importMacroforge(): Promise<MacroforgeModule | null> {
      try {
        // Dynamic import to avoid build-time errors when @macroforge/core is not installed
        // @ts-expect-error - dynamic import of optional dependency
        const mod = await import('@macroforge/core');
        return mod as MacroforgeModule;
      } catch {
        // Package not installed - return null to indicate unavailability
        return null;
      }
    }
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the tool's behavior: it returns structured JSON diagnostics with specific fields (level, message, location, help, notes, summary) and details what it detects (e.g., invalid macro names, malformed decorators, syntax errors). However, it doesn't mention potential side effects like rate limits, authentication needs, or performance characteristics, leaving some gaps.

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 well-structured and front-loaded, starting with the core purpose and key output details. Most sentences add value, such as listing diagnostic fields and detection capabilities. However, the list of detections is somewhat verbose and could be more concise without losing clarity, slightly reducing efficiency.

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?

Given the tool's complexity (validation with diagnostics) and no output schema, the description is mostly complete: it explains the purpose, usage guidelines, behavioral output (JSON structure), and detection scope. It lacks details on error handling or edge cases, but for a tool with no annotations and 100% schema coverage, it provides sufficient context for an agent to use it effectively.

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 'filename'). The description does not add any specific meaning or usage details beyond what the schema provides, such as examples or constraints on the 'code' parameter. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't enhance parameter understanding.

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: 'Validates TypeScript code with @derive decorators using Macroforge's native validation.' It specifies the verb (validates), resource (TypeScript code with @derive decorators), and method (Macroforge's native validation), distinguishing it from sibling tools like 'expand-code' or 'get-documentation' which serve different functions.

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 guidelines: 'This tool MUST be used before sending Macroforge code to the user' and 'If require_another_tool_call_after_fixing is true, fix the issues and validate again.' It also implies when to use it (for validation before sharing code) and suggests an alternative workflow (re-validation after fixing), though it doesn't name specific sibling alternatives.

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/macroforge-ts/mcp-server'

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