Skip to main content
Glama

check_file

Lint a file against Vale style rules to identify grammar and style issues with location and severity details. Provides installation guidance if Vale is not available.

Instructions

Lint a file at a specific path against Vale style rules. Returns issues found with their locations and severity. If Vale is not installed, returns error with installation guidance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute or relative path to the file to check

Implementation Reference

  • The core handler function that implements the check_file tool logic. It validates the file path, executes 'vale --output=JSON' on the file, handles output parsing, normalizes issues, generates a summary, and formats a Markdown response with structured data.
    export async function checkFile(
      filePath: string,
      configPath?: string
    ): Promise<CheckFileResult> {
      // Verify file exists and is readable (Fix #9: async file operations)
      try {
        await fs.access(filePath, fsSync.constants.R_OK);
      } catch {
        throw new Error(`File not found or not readable: ${filePath}`);
      }
    
      // Resolve to absolute path
      const absolutePath = path.isAbsolute(filePath)
        ? filePath
        : path.resolve(process.cwd(), filePath);
    
      // Build Vale command
      let command = `vale --output=JSON`;
      
      // Only use --config if explicitly provided (e.g., from VALE_CONFIG_PATH env var)
      // Otherwise let Vale do its natural upward search from the file's location
      if (configPath) {
        command += ` --config="${configPath}"`;
        console.error(`Using explicit config: ${configPath}`);
      } else {
        console.error(`Letting Vale search for config from: ${path.dirname(absolutePath)}`);
      }
      
      command += ` "${absolutePath}"`;
    
      // Run Vale from the file's directory so it searches upward from there
      const execOptions: any = { 
        encoding: 'utf-8',
        cwd: path.dirname(absolutePath)
      };
    
      // Execute Vale
      let stdout = "";
      try {
        const result = await execAsync(command, execOptions);
        stdout = typeof result.stdout === 'string' ? result.stdout : result.stdout.toString('utf-8');
      } catch (error: any) {
        // Vale returns non-zero exit code when there are issues
        // But it still outputs JSON to stdout
        if (error.stdout) {
          stdout = error.stdout;
        } else {
          const errorMessage = error.stderr || error.message || "Unknown error";
          throw new Error(
            `Vale execution failed: ${errorMessage}`
          );
        }
      }
    
      // Parse output
      const rawOutput = parseValeOutput(stdout);
      const issues = normalizeIssues(rawOutput);
      const summary = generateSummary(issues);
      const formatted = formatValeResults(issues, summary, absolutePath);
    
      return {
        formatted,
        file: absolutePath,
        issues,
        summary,
      };
    }
  • src/index.ts:227-240 (registration)
    Registration of the 'check_file' tool in the MCP server's TOOLS array, including name, description, and input schema.
      name: "check_file",
      description:
        "Lint a file at a specific path against Vale style rules. Returns issues found with their locations and severity. If Vale is not installed, returns error with installation guidance.",
      inputSchema: {
        type: "object",
        properties: {
          path: {
            type: "string",
            description: "Absolute or relative path to the file to check",
          },
        },
        required: ["path"],
      },
    },
  • The MCP protocol request handler (switch case) for executing the 'check_file' tool: parameter validation, Vale availability check, delegates to checkFile implementation, and response formatting.
    case "check_file": {
      const { path: filePath } = args as { path: string };
    
      debug(`check_file called - path: ${filePath}`);
    
      if (!filePath) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                error: "Missing required parameter: path",
              }),
            },
          ],
        };
      }
    
      // Check if Vale is available
      const valeCheck = await checkValeInstalled();
      if (!valeCheck.installed) {
        return createValeNotInstalledResponse();
      }
    
      const result = await checkFile(filePath, valeConfigPath);
    
      debug(`check_file result - file: ${result.file}, issues found: ${result.issues.length}, errors: ${result.summary.errors}, warnings: ${result.summary.warnings}, suggestions: ${result.summary.suggestions}`);
    
      return {
        content: [
          {
            type: "text",
            text: result.formatted,
          },
        ],
        _meta: {
          structured_data: {
            file: result.file,
            issues: result.issues,
            summary: result.summary,
          },
        },
      };
    }
  • TypeScript interface defining the return type of the checkFile function, used for input/output structure of the check_file tool.
     * Result structure for check_file tool
     */
    export interface CheckFileResult {
      formatted: string;
      file: string;
      issues: NormalizedValeIssue[];
      summary: ValeSummary;
    }
  • JSON Schema for input validation of the check_file tool (path parameter).
    inputSchema: {
      type: "object",
      properties: {
        path: {
          type: "string",
          description: "Absolute or relative path to the file to check",
        },
      },
      required: ["path"],
    },
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 disclosing key behaviors: it returns issues with locations/severity, and handles the error case when Vale is not installed with guidance. It doesn't mention rate limits, authentication needs, or whether this is read-only vs destructive, but provides useful operational context.

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?

Two efficient sentences with zero waste. First sentence states purpose and output, second handles error case. Every sentence earns its place with important operational information.

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 single-parameter tool with no annotations and no output schema, the description provides good completeness: purpose, behavior, error handling. It could benefit from more detail about the return format (structure of issues) and whether this is a read-only operation, but covers the essential context well.

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% with the single 'path' parameter well-documented in the schema. The description adds minimal value beyond the schema by mentioning 'specific path' and 'file to check', but doesn't provide additional syntax, format details, or constraints beyond what's already in the schema.

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 specific action ('lint a file'), target resource ('file at a specific path'), and purpose ('against Vale style rules'). It distinguishes from sibling tools by focusing on file checking rather than status or synchronization operations.

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

Usage Guidelines3/5

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

The description implies usage context through the mention of Vale style rules and installation requirements, but doesn't explicitly state when to use this tool versus the 'vale_status' or 'vale_sync' siblings. No explicit alternatives or exclusions are provided.

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/theletterf/vale-mcp-server'

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