Skip to content

Report UTF-8 bytes in MCP write tool#1708

Open
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:fix/write-reports-bytes
Open

Report UTF-8 bytes in MCP write tool#1708
fallintoplace wants to merge 1 commit into
anthropics:mainfrom
fallintoplace:fix/write-reports-bytes

Conversation

@fallintoplace

Copy link
Copy Markdown

Problem

The agent write tool returns a status string with len(content), which is a character count, while write operations are byte-oriented.

For non-ASCII text this reports a smaller number than the actual persisted bytes, e.g. "é".

Fix

  • In src/anthropic/lib/tools/agent_toolset.py, update the return message to use UTF-8 encoded byte length:
    • len(content.encode("utf-8"))

This keeps the current bytes status wording accurate while preserving behavior of writing with UTF-8 (the same default used by Path.write_text).

Testing

Not run (docs/runtime behavior change only).

@fallintoplace fallintoplace requested a review from a team as a code owner June 25, 2026 19:49
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.

1 participant