mirror of
https://github.com/jwadow/kiro-gateway.git
synced 2026-04-25 01:15:57 +03:00
[GH-ISSUE #41] BUG: 400 Improperly formed request with Claude Code v2.1.6 #26
Labels
No labels
bug
bug
enhancement
enhancement
fixed
fixed
invalid
needs-info
needs-testing
pull-request
question
upstream
wontfix
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/kiro-gateway-jwadow#26
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @myheisenberg on GitHub (Jan 17, 2026).
Original GitHub issue: https://github.com/jwadow/kiro-gateway/issues/41
Kiro Gateway Version
v2.0.0
What happened?
I am using Claude Code v2.1.6. I get "400 Improperly formed request" error especially when using MCP tools or in long conversations.
Debug Logs
error_info.json
response_stream_raw.txt
@jwadow commented on GitHub (Jan 18, 2026):
Hi @myheisenberg, thanks for the report. But I can't do anything because two key files (
request_body.jsonandkiro_request_body.json) are missing from the issue.It also seems strange to me that the
error_info.jsonandresponse_stream_raw.txtfiles can exist simultaneously with a 400 Improperly formed request error. As far as I remember, in the entire history of the project, I've never seenresponse_stream_raw.txteven created with this error.Are you sure you enabled
DEBUG_MODE=errorsand uploaded the files simultaneously, and not from different requests?@uratmangun commented on GitHub (Jan 18, 2026):
also got this in opencode i've fixed it myself tho dont know if this works for you but this is what i've done with the help of kiro-cli himself basically the i log all the request inside my sqlite database then i ask ai why is the request from opencode got error and he fix it this the summary:
Fix: Tool Results Lost During Message Merge
Problem
When using the
/v1/chat/completionsendpoint with conversations containing tool calls, requests were failing with:Root Cause
The
merge_adjacent_messagesfunction inkiro_gateway/converters.pywas losingtool_resultblocks when merging adjacent user messages.Scenario That Failed
tool_resultblocksextract_text_contentwas called which discarded thetool_resultblockstoolUsesexist without correspondingtoolResultsExample from Debug Logs
Request ID
2e96b235showed:toolUsestoolResults(should have had 3!)The tool results were lost during merge.
Solution
1. Added
_extract_tool_result_blocksHelper (converters.py:226-247)2. Modified
merge_adjacent_messages(converters.py:340-390)Added preservation of
tool_resultblocks during merge, similar to existing image preservation:Files Changed
kiro_gateway/converters.py_extract_tool_result_blocksfunctionmerge_adjacent_messagesto preserve tool_result blocksTesting
Test Request
Verification
Check database logs:
Verify
toolResultsin kiro_payload:Rebuild & Deploy
im putting it inside a container
Related Context
_extract_images_from_content)toolResultsto matchtoolUses- orphaned tool uses cause 400 errorstoolUsesfrom the last assistant message (lines 1019-1040 in converters.py)i dont have improperly formatted request because of this
@myheisenberg commented on GitHub (Jan 18, 2026):
@jwadow
Sorry, I think the first one didn’t work. I ran it again and all the files came through.
kiro_request_body.json
request_body.json
response_stream_raw.txt
app_logs.txt
error_info.json
@uratmangun Thanks, I’ll give it a try.
@jwadow commented on GitHub (Jan 19, 2026):
Hey @myheisenberg, figured out what's going on with your setup. Your MCP tools have super long names that go over Kiro API's 64 character limit. Like
mcp__GitHub__check_if_a_person_is_followed_by_the_authenticated_useris 68 chars,mcp__GitHub__check_if_a_repository_is_starred_by_the_authenticated_useris 71 chars, etc.I added validation so now instead of that cryptic "400 Improperly formed request" you'll get a clear error listing exactly which tools are too long and by how much.
Can't auto-shorten them though because that would break everything. The MCP server expects exact tool names, if we change them the tools won't work at all. You'll need to configure your MCP server to use shorter names, most of them let you customize the prefix or format.
@uratmangun your issue sounds different, that was about tool_results getting lost during message merge. That's already handled in the current code by the merge_adjacent_messages function which preserves tool_results properly.