Skip to content

feat: add raw parameter to get_file_contents tool #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

ko1ynnky
Copy link

Summary

Adds an optional raw boolean parameter to the get_file_contents tool to return plain text content instead of base64 encoded content, addressing issue #372.

Changes

  • ✅ Added raw boolean parameter to get_file_contents tool schema
  • ✅ When raw=true, fetches file content via GitHub's download URL and returns plain text
  • ✅ When raw=false or unset, maintains existing base64 encoded behavior
  • ✅ Returns appropriate error for directories when raw=true
  • ✅ Handles files without download URLs gracefully
  • ✅ Added comprehensive test coverage for edge cases

Benefits

  • Reduces token consumption for LLM interactions by avoiding base64 decoding
  • Improves model performance by providing direct access to file content
  • Maintains backward compatibility with existing implementations
  • Provides interface consistency with other tools like create_or_update_file

Test Coverage

  • Schema validation includes raw parameter
  • Directory handling with raw=true returns appropriate error
  • Files without download URL return appropriate error
  • All existing tests continue to pass

Example Usage

# Get base64 encoded content (existing behavior)
get_file_contents --owner github --repo docs --path README.md

# Get raw text content (new feature)  
get_file_contents --owner github --repo docs --path README.md --raw true

Closes #372

🤖 Generated with Claude Code

Add optional `raw` boolean parameter to get_file_contents tool to return
plain text content instead of base64 encoded content. This reduces token
consumption for LLM interactions by avoiding the need to decode base64.

- When `raw=true`, fetches file content via GitHub's download URL
- When `raw=false` or unset, returns base64 encoded content (existing behavior)
- Returns appropriate error for directories when raw=true
- Includes comprehensive test coverage for edge cases

Fixes github#372

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@SamMorrowDrums
Copy link
Collaborator

Thank you for the contribution. The file API just doesn't work well for this, so I've made this: #505

I'm going to close out this one in favour of mine, as I think it is simpler, and was much needed. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_file_contents tool should have non-base64 option
2 participants