Skip to content

Commit 2af18bc

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 812a46a commit 2af18bc

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
@@ -1015,7 +1015,7 @@ class GetPromptRequest(Request[GetPromptRequestParams, Literal["prompts/get"]]):
10151015
class TextContent(BaseModel):
10161016
"""Text content for a message."""
10171017

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

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

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

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

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

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

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

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

1192-
type: Literal["resource_link"]
1192+
type: Literal["resource_link"] = "resource_link"
11931193

11941194

11951195
ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource
@@ -1580,7 +1580,7 @@ def content_as_list(self) -> list[SamplingMessageContentBlock]:
15801580
class ResourceTemplateReference(BaseModel):
15811581
"""A reference to a resource or resource template definition."""
15821582

1583-
type: Literal["ref/resource"]
1583+
type: Literal["ref/resource"] = "ref/resource"
15841584
uri: str
15851585
"""The URI or URI template of the resource."""
15861586
model_config = ConfigDict(extra="allow")
@@ -1589,7 +1589,7 @@ class ResourceTemplateReference(BaseModel):
15891589
class PromptReference(BaseModel):
15901590
"""Identifies a prompt."""
15911591

1592-
type: Literal["ref/prompt"]
1592+
type: Literal["ref/prompt"] = "ref/prompt"
15931593
name: str
15941594
"""The name of the prompt or prompt template"""
15951595
model_config = ConfigDict(extra="allow")

0 commit comments

Comments
 (0)