fix(mcpserver): serialize empty list and tuple returns into TextContent

Closed
MA
3mo ago
+44-0

Description

Fixes #3307

When a @mcp.tool() function returns an empty list [] or tuple (), _convert_to_content previously collapsed the return value into an empty list of content blocks (content: []). This caused downstream clients (such as Claude Desktop, LangGraph, and IDE integrations) to treat valid empty results as errored executions due to zero content blocks.

Changes Made

  • Updated _convert_to_content in src/mcp/server/mcpserver/utilities/func_metadata.py to return [TextContent(type="text", text="[]")] for empty lists (and "()" for empty tuples).
  • Added unit test in tests/server/mcpserver/test_func_metadata.py.
  • Added end-to-end client/server interaction test in tests/interaction/mcpserver/test_tools.py.

Checklist

  • Linked existing issue #3307.
  • Unit and interaction tests added.