Skip to main content
Glama
goklab

guardvibe

export_sarif

Scan a directory and export security results as SARIF v2.1.0 for CI/CD integration with GitHub, GitLab, and Azure DevOps.

Instructions

Scan a directory and export results in SARIF v2.1.0 format for CI/CD integration (GitHub, GitLab, Azure DevOps). Returns JSON string.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesDirectory to scan

Implementation Reference

  • Main handler function that walks a directory, analyzes code with check-code, and builds a SARIF 2.1.0 JSON output string.
    export function exportSarif(path: string, rules?: SecurityRule[]): string {
      const scanRoot = resolve(path);
      const config = loadConfig(scanRoot);
      const excludes = new Set([...DEFAULT_EXCLUDES, ...config.scan.exclude]);
      const filePaths: string[] = [];
      walkDirectory(scanRoot, true, excludes, filePaths);
    
      const allResults: SarifResult[] = [];
    
      for (const filePath of filePaths) {
        try {
          const stat = statSync(filePath);
          if (stat.size > config.scan.maxFileSize) continue;
          const content = readFileSync(filePath, "utf-8");
          const ext = extname(filePath).toLowerCase();
          let language = EXTENSION_MAP[ext];
          if (!language && basename(filePath).startsWith("Dockerfile")) language = "dockerfile";
          if (!language) continue;
    
          const findings = analyzeCode(content, language, undefined, filePath, scanRoot, rules);
    
          for (const f of findings) {
            allResults.push({
              ruleId: f.rule.id,
              level: severityToLevel(f.rule.severity),
              message: {
                text: `${f.rule.name}: ${f.rule.description} Fix: ${f.rule.fix}`,
              },
              locations: [{
                physicalLocation: {
                  artifactLocation: { uri: filePath },
                  region: { startLine: f.line },
                },
              }],
            });
          }
        } catch { /* skip */ }
      }
    
      // Build SARIF rules from all known rules (deduped by what was found)
      const foundRuleIds = new Set(allResults.map(r => r.ruleId));
      const sarifRules = owaspRules
        .filter(r => foundRuleIds.has(r.id))
        .map(r => ({
          id: r.id,
          name: r.name,
          shortDescription: { text: r.name },
          fullDescription: { text: r.description },
          helpUri: `https://guardvibe.dev`,
          properties: {
            tags: [r.owasp],
            ...(r.compliance ? { compliance: r.compliance } : {}),
          },
        }));
    
      const sarif = {
        $schema: "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json",
        version: "2.1.0",
        runs: [{
          tool: {
            driver: {
              name: "GuardVibe",
              version: _pkg.version,
              informationUri: "https://guardvibe.dev",
              rules: sarifRules,
            },
          },
          results: allResults,
        }],
      };
    
      return JSON.stringify(sarif, null, 2);
    }
  • SarifResult interface defining the structure of each SARIF result entry.
    interface SarifResult {
      ruleId: string;
      level: "error" | "warning" | "note";
      message: { text: string };
      locations: Array<{
        physicalLocation: {
          artifactLocation: { uri: string };
          region: { startLine: number };
        };
      }>;
    }
  • src/cli/scan.ts:28-30 (registration)
    First CLI registration: dynamically imports exportSarif when format is 'sarif'.
    if (format === "sarif") {
      const { exportSarif } = await import("../tools/export-sarif.js");
      result = exportSarif(process.cwd());
  • src/cli/scan.ts:60-62 (registration)
    Second CLI registration in runDirectoryScan: dynamically imports exportSarif when format is 'sarif'.
    if (format === "sarif") {
      const { exportSarif } = await import("../tools/export-sarif.js");
      result = exportSarif(scanPath);
  • Helper function that maps severity strings to SARIF level (error/warning/note).
    function severityToLevel(severity: string): "error" | "warning" | "note" {
      if (severity === "critical" || severity === "high") return "error";
      if (severity === "medium") return "warning";
      return "note";
    }
Behavior3/5

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

No annotations are provided, so the description must convey behavioral traits. It mentions the return format (JSON string) but does not state whether the operation is read-only, what side effects occur, or any rate limits. Given the tool's simplicity, the description is adequate but lacks details beyond the basic action.

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 sentence that efficiently conveys the tool's purpose, output format, and context. Every word earns its place with no redundancy.

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

Completeness5/5

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

For a tool with a single input parameter and a simple output (JSON string), the description covers purpose, input, and output. No output schema exists, but the return format is specified. The description is complete for the tool's complexity.

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 coverage is 100% (the only parameter 'path' is described in the schema as 'Directory to scan'). The description does not add additional semantic meaning beyond what the schema provides. Baseline 3 is appropriate since the schema already covers the parameter.

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 verb 'scan and export', the resource 'directory', and the output format 'SARIF v2.1.0'. It also specifies the context (CI/CD integration for GitHub, GitLab, Azure DevOps), which distinguishes it from sibling tools like scan_directory that likely do not produce SARIF format.

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

Usage Guidelines4/5

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

The description indicates the tool is intended for CI/CD integration, providing context for when to use it. However, it does not explicitly exclude alternative tools or mention when not to use it. For a simple tool, this is clear enough but could be more explicit.

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/goklab/guardvibe'

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