Skip to content

fix(mcp_server): coerce integer progressToken before slicing in debug log - #32183

Open
juancarlosm wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
juancarlosm:fix/mcp-int-progress-token
Open

fix(mcp_server): coerce integer progressToken before slicing in debug log#32183
juancarlosm wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
juancarlosm:fix/mcp-int-progress-token

Conversation

@juancarlosm

Copy link
Copy Markdown
Contributor

Summary

MCP tools/call through the proxy crashes with TypeError: 'int' object is not subscriptable when the client sends an integer progressToken. The MCP spec allows progressToken to be string | integer, but _capture_host_progress_callback logged host_token[:8], which only works for strings. Because the f-string is built before verbose_logger.debug(...) runs, it raises even with debug logging disabled, and the exception aborts the whole tool call before the backend server is dispatched (backend logs stay clean, so it looks like a gateway/auth fault).

Fixes #32181.

Changes

  • Extract the token formatting into _format_progress_token_for_log(), coercing the token to str before slicing.
  • Add a parametrized regression test covering integer and string tokens.

Reproduce

Call any tool with an integer _meta.progressToken (e.g. {"progressToken": 1}). Clients such as Claude Code send monotonically increasing integer tokens by default. A string or absent token does not trigger it.

Testing

_format_progress_token_for_log(123456789)"12345678..." (previously raised); "abcdefghij""abcdefgh..." unchanged.

@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a crash in _capture_host_progress_callback where logging host_token[:8] raised TypeError: 'int' object is not subscriptable when the MCP client sends an integer progressToken (e.g. Claude Code's monotonically-increasing tokens). The fix extracts a tiny helper that coerces the token to str before slicing.

  • server.py: New _format_progress_token_for_log() function converts the token via str() before slicing to 8 characters; the debug log call is updated to use it.
  • test_mcp_server.py: Parametrized regression test verifies both integer (123456789 → "12345678...") and string ("abcdefghij" → "abcdefgh...") tokens are handled correctly.

Confidence Score: 5/5

Safe to merge — the change is a minimal, targeted fix to a debug log line with no impact on request routing or auth logic.

The only changed production code is a single helper function and one updated call site in a debug log path. The fix is correct: str() before slicing handles both str and int tokens as the MCP spec requires. A parametrized regression test is included and covers both cases. No behaviour beyond the log formatting is altered.

No files require special attention.

Important Files Changed

Filename Overview
litellm/proxy/_experimental/mcp_server/server.py Extracts _format_progress_token_for_log() to coerce progressToken to str before slicing, fixing the TypeError when an integer token is received. The surrounding call site is updated accordingly.
tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_server.py Adds a parametrized regression test covering both integer and string progressToken values — pure unit test, no network calls.

Reviews (1): Last reviewed commit: "fix(mcp_server): coerce integer progress..." | Re-trigger Greptile

@codecov

codecov Bot commented Jul 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

… log

An MCP progressToken may be a string or an integer per spec. The host
progress-capture path logged host_token[:8], which raised
'TypeError: int object is not subscriptable' for integer tokens and
aborted the entire tool call before the backend was dispatched.

Extract the token formatting into _format_progress_token_for_log(), which
coerces to str before slicing, and cover it with a regression test.

Fixes BerriAI#32181
@juancarlosm
juancarlosm force-pushed the fix/mcp-int-progress-token branch from dbe7db3 to c4eb936 Compare July 5, 2026 10:08
@Geod24

Geod24 commented Jul 16, 2026

Copy link
Copy Markdown

The related issue has been closed by another PR (#32402), I assume this can be safely closed ?

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.

MCP tool calls fail with 'int' object is not subscriptable when client sends an integer progressToken

2 participants