Skip to content

Conversation

@felixweinberger
Copy link
Contributor

@felixweinberger felixweinberger commented Jan 15, 2026

Summary

Add default values to single-value Literal type fields in content types so users don't have to pass them explicitly.

Motivation and Context

Content types like TextContent and ImageContent have single-value Literal type fields (e.g., type: Literal["text"]) that should default automatically since there's only one valid value.

Before:

TextContent(type="text", text="hello")
ImageContent(type="image", data="...", mimeType="image/png")

After:

TextContent(text="hello")
ImageContent(data="...", mimeType="image/png")

Fixes #1731

How Has This Been Tested?

Added regression test test_content_type_literal_defaults in tests/test_types.py covering representative types (TextContent, ImageContent, PromptReference).

Breaking Changes

None. Existing code that explicitly passes the type field will continue to work.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Affected types:

  • TextContent
  • ImageContent
  • AudioContent
  • ToolUseContent
  • ToolResultContent
  • EmbeddedResource
  • ResourceLink
  • ResourceTemplateReference
  • PromptReference

This follows the same pattern as PR #1292 which added defaults for method: Literal fields on request/notification types.

@felixweinberger felixweinberger force-pushed the fweinberger/content-type-defaults branch from 2cd7cab to e55ae7f Compare January 15, 2026 16:30
Content types like TextContent and ImageContent have single-value Literal type
fields (e.g., type: Literal["text"]) that now default automatically so users
don't have to pass them explicitly.

Before: TextContent(type="text", text="hello")
After: TextContent(text="hello")

Github-Issue: #1731
@felixweinberger felixweinberger force-pushed the fweinberger/content-type-defaults branch from e55ae7f to 2af18bc Compare January 16, 2026 08:21
@felixweinberger felixweinberger marked this pull request as ready for review January 16, 2026 09:45
Kludex
Kludex previously approved these changes Jan 16, 2026
@felixweinberger felixweinberger merged commit 9f427f3 into main Jan 16, 2026
25 checks passed
@felixweinberger felixweinberger deleted the fweinberger/content-type-defaults branch January 16, 2026 10:01
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.

Content types should have default values for Literal type fields

3 participants