Fix TypeError: unhashable type: 'list' when using MCP Adapter with malformed schemas #6753
+124
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 therequired
field.The error occurred when trying to use MCP servers like the PowerPoint MCP with configuration:
Root Cause
The issue was in
autogen_core.utils._json_to_pydantic.py
whereset()
operations were used to deduplicate required field names. When MCP servers returned schemas with malformedrequired
fields containing lists or dictionaries, these operations would fail:Example problematic schema:
Solution
Added safe deduplication function that filters out non-hashable items:
Updated all problematic locations to use the safe deduplication function
Added comprehensive test coverage for various malformed schema scenarios
Behavior
Testing
Added
test_unhashable_required_fields_handling()
test case covering: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.