Skip to content

Fix TypeError: unhashable type: 'list' when using MCP Adapter with malformed schemas #6753

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 6, 2025

Problem

MCP (Model Context Protocol) adapters were failing with TypeError: unhashable type: 'list' when processing tool schemas from MCP servers that returned malformed JSON schemas with non-hashable items in the required field.

The error occurred when trying to use MCP servers like the PowerPoint MCP with configuration:

{
  "powerpoint": {
    "command": "uv",
    "args": ["--directory", "/path/to/powerpoint", "run", "powerpoint", "--folder-path", "/path/to/decks_folder"]
  }
}

Root Cause

The issue was in autogen_core.utils._json_to_pydantic.py where set() operations were used to deduplicate required field names. When MCP servers returned schemas with malformed required fields containing lists or dictionaries, these operations would fail:

# This would crash if required contained unhashable items
merged["required"] = list(set(merged["required"]))  # Line 159, 267, 297
required_fields = set(schema.get("required", []))   # Line 271

Example problematic schema:

{
    "type": "object",
    "properties": {
        "folder_path": {"type": "string"},
        "options": {"type": "array", "items": {"type": "string"}}
    },
    "required": ["folder_path", ["options"]]  # <- List in required causes error
}

Solution

  1. Added safe deduplication function that filters out non-hashable items:

    def _safe_deduplicate_required(required_list: List[Any]) -> List[str]:
        """Safely deduplicate required list by filtering out non-hashable items."""
        hashable_items = []
        for item in required_list:
            if isinstance(item, str):
                hashable_items.append(item)
            elif isinstance(item, (int, float, bool)):
                hashable_items.append(str(item))
            # Skip unhashable items like lists, dicts, etc.
        return list(set(hashable_items))
  2. Updated all problematic locations to use the safe deduplication function

  3. Added comprehensive test coverage for various malformed schema scenarios

Behavior

  • Before: MCP adapters crashed with unhashable type error
  • After: Malformed schemas are processed gracefully, only valid string field names are preserved as required
  • Backward compatibility: All existing valid schemas continue to work exactly as before

Testing

Added test_unhashable_required_fields_handling() test case covering:

  • Direct schemas with lists in required fields
  • allOf schemas with unhashable required items
  • Nested schemas with mixed types in required fields

All tests pass and the PowerPoint MCP scenario from the issue now works correctly.

Fixes #6723.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: ekzhu <320302+ekzhu@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] TypeError: unhashable type: 'list' when using MCP Adapter Fix TypeError: unhashable type: 'list' when using MCP Adapter with malformed schemas Jul 6, 2025
Copilot finished work on behalf of ekzhu July 6, 2025 21:11
@Copilot Copilot AI requested a review from ekzhu July 6, 2025 21:11
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.

TypeError: unhashable type: 'list' when using MCP Adapter
2 participants