googleapis/mcp-toolbox · error
error writing script %s: %w
Error message
error writing script %s: %w
What it means
This error wraps a failure from os.WriteFile when persisting a generated per-tool wrapper script (<toolName>.js) into the skill's scripts directory. The content was generated successfully, but writing it to disk failed — typically a filesystem-level problem such as permissions, a missing parent directory, or a path conflict.
Source
Thrown at cmd/internal/skills/command.go:221
// Iterate over keys to ensure deterministic order
var toolNames []string
for name := range allTools {
toolNames = append(toolNames, name)
}
sort.Strings(toolNames)
for _, toolName := range toolNames {
// Generate wrapper script in scripts directory
scriptContent, err := generateScriptContent(toolName, configArgsStr, cmd.licenseHeader, cmd.invocationMode, cmd.toolboxVersion, parser.OptionalEnvVars)
if err != nil {
errMsg := fmt.Errorf("error generating script content for %s: %w", toolName, err)
opts.Logger.ErrorContext(ctx, errMsg.Error())
return errMsg
}
scriptFilename := filepath.Join(scriptsPath, fmt.Sprintf("%s.js", toolName))
if err := os.WriteFile(scriptFilename, []byte(scriptContent), 0755); err != nil {
errMsg := fmt.Errorf("error writing script %s: %w", scriptFilename, err)
opts.Logger.ErrorContext(ctx, errMsg.Error())
return errMsg
}
}
// Generate SKILL.md
skillContent, err := generateSkillMarkdown(skillName, content.description, cmd.additionalNotes, allTools, parser.EnvVars)
if err != nil {
errMsg := fmt.Errorf("error generating SKILL.md content: %w", err)
opts.Logger.ErrorContext(ctx, errMsg.Error())
return errMsg
}
skillMdPath := filepath.Join(skillPath, "SKILL.md")
if err := os.WriteFile(skillMdPath, []byte(skillContent), 0644); err != nil {
errMsg := fmt.Errorf("error writing SKILL.md: %w", err)
opts.Logger.ErrorContext(ctx, errMsg.Error())
return errMsg
}View on GitHub (pinned to 8cc6e09de2)
Solutions
- Check permissions on the output directory and its scripts/ subdirectory (ls -ld) and chmod/chown as needed
- Verify the scripts path exists as a directory and is not a regular file (rm or move the conflicting entry)
- Re-run with a different --output location you have write access to
- Free disk space or remount the volume read-write if the filesystem is full or read-only
Example fix
// before mkdir -p ~/.claude/skills/my-skill/scripts && toolbox skills --output ~/.claude/skills/my-skill ... # scripts/ owned by root -> write fails // after sudo chown -R $USER ~/.claude/skills/my-skill && toolbox skills --output ~/.claude/skills/my-skill ...
Defensive patterns
Strategy: validation
Validate before calling
# Verify the target scripts dir is a writable directory before running if [ ! -d "$OUT/skills/my-skill/scripts" ] || [ ! -w "$OUT/skills/my-skill/scripts" ]; then mkdir -p "$OUT/skills/my-skill/scripts" || exit 1 fi
Try / catch
try {
execSync("toolbox skills --name my-skill", { stdio: "inherit" });
} catch (e) {
if (String(e.stderr).includes("error writing script")) {
console.error("Filesystem write failed; check permissions on the output directory:", e.stderr);
} else { throw e; }
} Prevention
- Pre-create the output directory with mkdir -p and correct ownership
- Run the CLI as a user with write access to the output path
- Check free disk space before bulk generation
- Don't pre-create scripts/<tool>.js as a file or mount the output read-only
When it happens
Trigger: Running `toolbox skills` when os.WriteFile(scriptFilename, ...) fails — the target scripts directory does not exist or is not writable, the path is not a directory, or the filesystem is full/read-only.
Common situations: Writing a skill into a directory owned by another user or without write permission; the scripts/ path was pre-created as a file; generating into a read-only mounted volume or a path with restrictive umask; disk quota exceeded.
Understand the failure class
Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.
Related errors
- error writing SKILL.md: %w
- failed to rename file: %w
- error finding YAML files in %q: %w
- error finding YML files in %q: %w
- failed to initialize resources: %w
AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05).
Data as JSON: /api/errors/478181cbfe0b3158.
Report an issue: GitHub.