github/github-mcp-server · warning

failed to read README.md: %w

Error message

failed to read README.md: %w

What it means

Returned by generateReadmeDocs when os.ReadFile(readmePath) fails while regenerating README toolset/tool sections. readmePath defaults to README.md (relative to the working directory) or comes from a command-line flag; the read fails when the file is absent at that path or unreadable.

Source

Thrown at cmd/github-mcp-server/generate_docs.go:83

	// keeps the legacy variants of tools gated by FeatureFlagDisable, so
	// flag-gated duplicates don't appear twice.
	// Build() can only fail if WithTools specifies invalid tools - not used here
	r, _ := github.NewInventory(t).
		WithToolsets([]string{"all"}).
		WithFeatureChecker(noFeatureFlagsChecker).
		Build()

	// Generate toolsets documentation
	toolsetsDoc := generateToolsetsDoc(r)

	// Generate tools documentation
	toolsDoc := generateToolsDoc(r)

	// Read the current README.md
	// #nosec G304 - readmePath is controlled by command line flag, not user input
	content, err := os.ReadFile(readmePath)
	if err != nil {
		return fmt.Errorf("failed to read README.md: %w", err)
	}

	// Replace toolsets section
	updatedContent, err := replaceSection(string(content), "START AUTOMATED TOOLSETS", "END AUTOMATED TOOLSETS", toolsetsDoc)
	if err != nil {
		return err
	}

	// Replace tools section
	updatedContent, err = replaceSection(updatedContent, "START AUTOMATED TOOLS", "END AUTOMATED TOOLS", toolsDoc)
	if err != nil {
		return err
	}

	// Write back to file
	err = os.WriteFile(readmePath, []byte(updatedContent), 0600)
	if err != nil {
		return fmt.Errorf("failed to write README.md: %w", err)

View on GitHub (pinned to 0ea1f775a7)

Solutions

  1. cd to the repository root before running the docs generation command
  2. Pass an absolute path via the command's path flag if running elsewhere
  3. Confirm README.md exists and is readable (ls -l README.md)
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := os.Stat(readmePath); err != nil {
    log.Fatalf("README not found at %s — run from the repo root or pass --readme", readmePath)
}

Try / catch

if err := generateReadmeDocs(readmePath); err != nil {
    if os.IsNotExist(errors.Unwrap(err)) {
        log.Fatalf("README.md missing at %q", readmePath)
    }
    return err
}

Prevention

When it happens

Trigger: Running generate-docs from any directory other than the repo root (README.md not found); passing a --readme flag pointing to a nonexistent file; README.md deleted in a stripped checkout; permission denial.

Common situations: Executing the generator via `go run ./cmd/github-mcp-server` from a subdirectory; CI checkouts that exclude README; typo'd custom path flag.

Related errors


AI-assisted analysis of github/github-mcp-server@0ea1f775a7 (2026-08-15). Data as JSON: /api/errors/ae968e7954391929. Report an issue: GitHub.