Skip to content

fix: omit empty task result fields#2736

Closed
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/task-results-exclude-none
Closed

fix: omit empty task result fields#2736
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/task-results-exclude-none

Conversation

@he-yufeng
Copy link
Copy Markdown

Summary

  • serialize completed task results with exclude_none=True and JSON mode before adding related-task metadata
  • keep empty optional content fields out of the task result payload, matching normal session response serialization
  • add a regression assertion for TextContent task results so annotations and _meta are omitted instead of serialized as null

Fixes #2539.

To verify

  • python -m py_compile src/mcp/server/experimental/task_result_handler.py tests/experimental/tasks/server/test_task_result_handler.py
  • uv run python -m pytest tests/experimental/tasks/server/test_task_result_handler.py -q
  • uv run ruff check src/mcp/server/experimental/task_result_handler.py tests/experimental/tasks/server/test_task_result_handler.py
  • git diff --check

@Kludex
Copy link
Copy Markdown
Member

Kludex commented Jun 2, 2026

We are dropping the tasks from the experimental. Thanks for the PR anyway.

@Kludex Kludex closed this Jun 2, 2026
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.

Bug: task_result_handler.py serializes None optional fields as JSON null, breaking Node SDK Zod validation

2 participants