Skip to main content
Glama
rodhayl
by rodhayl

formatter

Format code or apply LLM-powered syntax fixes to files locally. Choose between standard formatting and AI-assisted corrections for improved code quality.

Instructions

Run formatter or LLM-assisted syntax fixes.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionNoAction: run (format code), fix (LLM-powered syntax fixes)
filesNoSpecific files to process
commandNoCustom format command
checkNoCheck only, do not modify (for run action)
difficultyNoLLM fix difficulty (for fix action)
dryRunNoPreview fixes without applying (for fix action)
maxFixesNoMaximum fixes to apply (for fix action)
timeoutNoTimeout in milliseconds

Implementation Reference

  • The runFormatter method in ExecutionTools class which serves as the handler for the formatter tool, capable of detecting the formatter and executing the formatting command.
    async runFormatter(options?: {
      command?: string;
      files?: string[];
      check?: boolean; // Just check, don't modify
      timeout?: number;
    }): Promise<ExecutionResult> {
      let command = options?.command;
    
      if (!command) {
        command = await this.detectFormatCommand(options?.check);
        if (!command) {
          return {
            success: false,
            exitCode: -1,
            stdout: '',
            stderr: 'Could not detect formatter. Please provide a format command.',
            duration: 0,
            command: '',
          };
        }
      }
    
      // Append specific files if provided
      if (options?.files && options.files.length > 0) {
        // For prettier, replace glob pattern with specific files
        if (command.includes('prettier')) {
          command = command.replace(/"[^"]*"/, options.files.join(' '));
        } else {
          command = `${command} ${options.files.join(' ')}`;
        }
      }
    
      return this.executeCommand(
        command,
        this.workspaceRoot,
        options?.timeout ?? this.defaultTimeout
      );
    }
  • Helper method to automatically detect the appropriate formatter command based on the workspace files (package.json, pyproject.toml, etc.).
    private async detectFormatCommand(check: boolean = false): Promise<string | undefined> {
      const packageJsonPath = join(this.workspaceRoot, 'package.json');
    
      if (existsSync(packageJsonPath)) {
        try {
          const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
    
          // Check scripts
          const scriptName = check ? 'format:check' : 'format';
          if (pkg.scripts?.[scriptName]) {
            return `npm run ${scriptName}`;
          }
    
          // Check for Prettier config
          const prettierConfigs = [
            '.prettierrc',
            '.prettierrc.js',
            '.prettierrc.json',
            'prettier.config.js',
            'prettier.config.mjs',
            'prettier.config.cjs',
          ];
          for (const config of prettierConfigs) {
            if (existsSync(join(this.workspaceRoot, config))) {
              return check
                ? 'npx prettier --check "**/*.{ts,js,tsx,jsx,json,css,md}"'
                : 'npx prettier --write "**/*.{ts,js,tsx,jsx,json,css,md}"';
            }
          }
    
          // Check devDependencies
          const deps = { ...pkg.dependencies, ...pkg.devDependencies };
          if (deps.prettier) {
            return check ? 'npx prettier --check .' : 'npx prettier --write .';
          }
        } catch {
          // Ignore parse errors
        }
      }
    
      // Python projects
      if (existsSync(join(this.workspaceRoot, 'pyproject.toml'))) {
        return check ? 'black --check .' : 'black .';
      }
    
      // Go projects
      if (existsSync(join(this.workspaceRoot, 'go.mod'))) {
        return 'go fmt ./...';
      }
    
      // Rust projects
      if (existsSync(join(this.workspaceRoot, 'Cargo.toml'))) {
        return check ? 'cargo fmt -- --check' : 'cargo fmt';
      }
    
      return undefined;
    }
Behavior2/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 mentions 'run' and 'fixes' but does not clarify whether files are modified in-place, if the operations are reversible, what LLM provider is used, or safety considerations. Minimal behavioral context beyond the obvious.

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

Conciseness3/5

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

Single sentence of six words is efficient with no waste, but underspecified for a tool with 8 parameters and two distinct operating modes. The brevity crosses into insufficient territory given the complexity, preventing a higher score.

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?

With 8 parameters, dual operating modes (standard formatting vs LLM-assisted), no output schema, and no annotations, the tool requires substantial contextual support. The 6-word description is inadequate for this complexity level, leaving significant gaps in understanding tool capabilities and risks.

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%, establishing a baseline of 3. The description implies the dual-mode nature (formatting vs fixing) which aligns with the 'action' parameter enum, but adds no syntax details, format examples, or clarifying constraints beyond what the schema already provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

States the tool runs a formatter and performs LLM-assisted syntax fixes, providing some specific verbs. However, 'formatter' largely restates the tool name, and it fails to differentiate from siblings like 'linter', 'find_and_fix', or 'refactor_helper' which likely overlap in 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?

Provides no guidance on when to use this tool versus alternatives, when to choose 'run' versus 'fix' actions, or prerequisites for execution. The description offers no 'when-not' exclusions or comparative context.

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/rodhayl/mcpLocalHelper'

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