Skip to content

Commit e55ae7f

Browse files
fix: add default values to Literal type fields in content types
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
1 parent f2b89ec commit e55ae7f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/mcp/types.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ class GetPromptRequest(Request[GetPromptRequestParams, Literal["prompts/get"]]):
10161016
class TextContent(BaseModel):
10171017
"""Text content for a message."""
10181018

1019-
type: Literal["text"]
1019+
type: Literal["text"] = "text"
10201020
text: str
10211021
"""The text content of the message."""
10221022
annotations: Annotations | None = None
@@ -1031,7 +1031,7 @@ class TextContent(BaseModel):
10311031
class ImageContent(BaseModel):
10321032
"""Image content for a message."""
10331033

1034-
type: Literal["image"]
1034+
type: Literal["image"] = "image"
10351035
data: str
10361036
"""The base64-encoded image data."""
10371037
mimeType: str
@@ -1051,7 +1051,7 @@ class ImageContent(BaseModel):
10511051
class AudioContent(BaseModel):
10521052
"""Audio content for a message."""
10531053

1054-
type: Literal["audio"]
1054+
type: Literal["audio"] = "audio"
10551055
data: str
10561056
"""The base64-encoded audio data."""
10571057
mimeType: str
@@ -1077,7 +1077,7 @@ class ToolUseContent(BaseModel):
10771077
in the next user message.
10781078
"""
10791079

1080-
type: Literal["tool_use"]
1080+
type: Literal["tool_use"] = "tool_use"
10811081
"""Discriminator for tool use content."""
10821082

10831083
name: str
@@ -1105,7 +1105,7 @@ class ToolResultContent(BaseModel):
11051105
from the assistant. It contains the output of executing the requested tool.
11061106
"""
11071107

1108-
type: Literal["tool_result"]
1108+
type: Literal["tool_result"] = "tool_result"
11091109
"""Discriminator for tool result content."""
11101110

11111111
toolUseId: str
@@ -1172,7 +1172,7 @@ class EmbeddedResource(BaseModel):
11721172
of the LLM and/or the user.
11731173
"""
11741174

1175-
type: Literal["resource"]
1175+
type: Literal["resource"] = "resource"
11761176
resource: TextResourceContents | BlobResourceContents
11771177
annotations: Annotations | None = None
11781178
meta: dict[str, Any] | None = Field(alias="_meta", default=None)
@@ -1190,7 +1190,7 @@ class ResourceLink(Resource):
11901190
Note: resource links returned by tools are not guaranteed to appear in the results of `resources/list` requests.
11911191
"""
11921192

1193-
type: Literal["resource_link"]
1193+
type: Literal["resource_link"] = "resource_link"
11941194

11951195

11961196
ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource
@@ -1584,7 +1584,7 @@ def content_as_list(self) -> list[SamplingMessageContentBlock]:
15841584
class ResourceTemplateReference(BaseModel):
15851585
"""A reference to a resource or resource template definition."""
15861586

1587-
type: Literal["ref/resource"]
1587+
type: Literal["ref/resource"] = "ref/resource"
15881588
uri: str
15891589
"""The URI or URI template of the resource."""
15901590
model_config = ConfigDict(extra="allow")
@@ -1598,7 +1598,7 @@ class ResourceReference(ResourceTemplateReference):
15981598
class PromptReference(BaseModel):
15991599
"""Identifies a prompt."""
16001600

1601-
type: Literal["ref/prompt"]
1601+
type: Literal["ref/prompt"] = "ref/prompt"
16021602
name: str
16031603
"""The name of the prompt or prompt template"""
16041604
model_config = ConfigDict(extra="allow")

0 commit comments

Comments
 (0)