Skip to content

Commit a6b5f34

Browse files
Python: fix parsing of types in mcp server (#12871)
### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> The parsing of tool call output was not working correctly, this fixes that. Solves #12850 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
1 parent fe30769 commit a6b5f34

File tree

1 file changed

+15
-13
lines changed
  • python/semantic_kernel/connectors

1 file changed

+15
-13
lines changed

python/semantic_kernel/connectors/mcp.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -949,21 +949,23 @@ async def _call_tool(
949949
] = []
950950
if isinstance(value, list):
951951
for item in value:
952-
if isinstance(
953-
value, (TextContent, ImageContent, BinaryContent, AudioContent, ChatMessageContent)
954-
):
955-
messages.extend(_kernel_content_to_mcp_content_types(item))
956-
else:
952+
match item:
953+
case (
954+
TextContent() | ImageContent() | BinaryContent() | AudioContent() | ChatMessageContent()
955+
):
956+
messages.extend(_kernel_content_to_mcp_content_types(item))
957+
case _:
958+
messages.append(
959+
types.TextContent(type="text", text=str(item)),
960+
)
961+
else:
962+
match value:
963+
case TextContent() | ImageContent() | BinaryContent() | AudioContent() | ChatMessageContent():
964+
messages.extend(_kernel_content_to_mcp_content_types(value))
965+
case _:
957966
messages.append(
958-
types.TextContent(type="text", text=str(item)),
967+
types.TextContent(type="text", text=str(value)),
959968
)
960-
else:
961-
if isinstance(value, (TextContent, ImageContent, BinaryContent, AudioContent, ChatMessageContent)):
962-
messages.extend(_kernel_content_to_mcp_content_types(value))
963-
else:
964-
messages.append(
965-
types.TextContent(type="text", text=str(value)),
966-
)
967969
return messages
968970
raise McpError(
969971
error=types.ErrorData(

0 commit comments

Comments
 (0)