Skip to content

Commit 6cd9551

Browse files
author
chenzailong
committed
Add JsonContext to mcp.type.ContentBlock
1 parent e975d05 commit 6cd9551

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/mcp/types.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -712,13 +712,28 @@ class AudioContent(BaseModel):
712712
for notes on _meta usage.
713713
"""
714714
model_config = ConfigDict(extra="allow")
715+
716+
717+
class JsonContent(BaseModel):
718+
"""Json content for a message."""
719+
720+
type: Literal["json"]
721+
data: dict[str, Any]
722+
"""The json content of the message."""
723+
annotations: Annotations | None = None
724+
meta: dict[str, Any] | None = Field(alias="_meta", default=None)
725+
"""
726+
See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields)
727+
for notes on _meta usage.
728+
"""
729+
model_config = ConfigDict(extra="allow")
715730

716731

717732
class SamplingMessage(BaseModel):
718733
"""Describes a message issued to or received from an LLM API."""
719734

720735
role: Role
721-
content: TextContent | ImageContent | AudioContent
736+
content: TextContent | ImageContent | AudioContent | JsonContent
722737
model_config = ConfigDict(extra="allow")
723738

724739

@@ -751,7 +766,7 @@ class ResourceLink(Resource):
751766
type: Literal["resource_link"]
752767

753768

754-
ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource
769+
ContentBlock = TextContent | ImageContent | AudioContent | JsonContent | ResourceLink | EmbeddedResource
755770
"""A content block that can be used in prompts and tool results."""
756771

757772
Content: TypeAlias = ContentBlock
@@ -1044,7 +1059,7 @@ class CreateMessageResult(Result):
10441059
"""The client's response to a sampling/create_message request from the server."""
10451060

10461061
role: Role
1047-
content: TextContent | ImageContent | AudioContent
1062+
content: TextContent | ImageContent | AudioContent | JsonContent
10481063
model: str
10491064
"""The name of the model that generated the message."""
10501065
stopReason: StopReason | None = None

0 commit comments

Comments
 (0)