Skip to content

Tool calls error resolved by environment configuration changes - MCP conflicts and Python environment affect message serialization #184

@hammerhoundai

Description

@hammerhoundai

What happened?

I was experiencing the "tool_call_ids did not have response messages" error in qwen-code v0.0.2, but discovered that the issue is environment-dependent and can be resolved through specific configuration changes.
Initial Problem

I consistently encountered this error when using tool-based operations:

1
✕ [API Error: OpenAI API error: 400 Invalid request: an assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: brave-search__brave_web_search:1]

The error occurred with various operations that trigger tool calls, particularly:

 File reading operations
 Directory listing
 Code analysis tasks

Discovery: Environment-Dependent Fix

Through systematic testing, I found that the issue could be resolved by making three specific changes to my environment:

Changes that fixed the issue:

 Removed filesystem MCP server - I had been using an external MCP for filesystem operations, but qwen-code has native filesystem tools
 Added SQLite MCP via uvx - Installed uvx sqlite-mcp-server for database operations (no conflicts with native tools)
 Activated Python 3.12 virtual environment - Created and activated a Python 3.12 venv before running qwen

Working vs Non-Working Configurations

Non-Working Configuration (triggers error):

 qwen-code v0.0.2
 Filesystem MCP server installed and active
 No specific Python virtual environment
 Mixed MCP tools + native tools

Working Configuration (no error):

 qwen-code v0.0.2  
 No filesystem MCP server (using native qwen-code tools)
 SQLite MCP via uvx (non-conflicting tool type)
 Python 3.12 virtual environment activated

Technical Analysis

The issue appears to be caused by:

 Tool namespace conflicts between qwen-code's native filesystem tools and external MCP filesystem tools
 Message serialization problems when multiple systems try to handle the same tool type
 Environment-dependent behavior related to Python version and isolation

Reproduction Steps (for the error)

 Install and activate a filesystem MCP server alongside qwen-code
 Run qwen without a clean Python virtual environment
 Try to perform file operations: > Read a file and analyze it
 Observe the tool_call_ids error

Error Pattern

 Intermittent but frequent
 Affects token usage (excessive consumption from failed retries)
 Occurs with any model that supports tool calling (Kimi K2, Qwen models, etc.)

What did you expect to happen?

Expected Behavior

 Seamless Tool Integration: qwen-code should handle tool calls correctly regardless of MCP configuration, with proper error handling for conflicting tools
 Consistent Message Serialization: Tool responses should always be serialized with the correct role: "tool" format, not role: "user"
 Graceful Conflict Resolution: When multiple systems (native + MCP) can handle the same tool type, qwen-code should either:
     Prioritize native tools over MCP tools
     Provide clear error messages about tool conflicts
     Automatically disable conflicting MCP tools
     
 Environment Independence: The tool calls functionality should work consistently across different Python environments and configurations
 Proper Error Handling: If tool calls fail, the error messages should be more descriptive and help users identify configuration issues

Specific Expected Outcomes

 File reading operations should complete successfully without API errors
 Tool response messages should have the correct role: "tool" format
 MCP integration should not interfere with native qwen-code functionality
 Users should not need to manually manage Python environments or MCP configurations to avoid basic tool usage
 The system should provide clear guidance when tool conflicts are detected

Ideal User Experience

A user should be able to:

 Install qwen-code
 Add any MCP servers they need
 Use tool-based features without encountering serialization errors
 Receive helpful error messages if configuration issues arise

Client information

  • CLI Version: 0.0.2
  • Git Commit: 2786f10 (local modifications)
  • Operating System: linux v20.19.4
  • Sandbox Environment: no sandbox
  • Model Version: kimi-k2-turbo-preview
  • Memory Usage: 161.6 MB

Login information

No response

Anything else we need to know?

Steps to Reproduce the Bug

  1. Install qwen-code v0.0.2

  2. Install and activate a filesystem MCP server

  3. (details)
    "notes": {
    "command": "npx",
    "args": [
    "-y",
    "@modelcontextprotocol/server-filesystem",
    "/home/dex/base/qwen"
    ],
    "env": {}
    },

  4. Run qwen without activating a Python virtual environment -- the global default env does have some packages installed by mistake

  5. Execute: qwen --model kimi-k2-0711-preview

  6. In the session, type: > Read any file in the directory and then some other call, usually when multiple tools are called recursively in a single convo turn the issue was observed

  7. Observe the tool_call_ids error

Steps to Reproduce the Working Configuration

  1. Install qwen-code v0.0.2
  2. Do NOT install filesystem MCP (use native tools)
  3. Create Python 3.12 venv: python3.12 -m venv qwen-env
  4. Activate venv: source qwen-env/bin/activate
  5. Install SQLite MCP via uvx: uvx install sqlite-mcp-server
  6. Run: qwen --model kimi-k2-0711-preview
  7. Test file operations - they should work without errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions