From 6cd95518a099e4014df0115e18c0c6d221749c92 Mon Sep 17 00:00:00 2001 From: chenzailong Date: Thu, 17 Jul 2025 11:35:09 +0800 Subject: [PATCH 1/3] Add JsonContext to mcp.type.ContentBlock --- src/mcp/types.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/mcp/types.py b/src/mcp/types.py index 91432d69c5..a5f03dda04 100644 --- a/src/mcp/types.py +++ b/src/mcp/types.py @@ -712,13 +712,28 @@ class AudioContent(BaseModel): for notes on _meta usage. """ model_config = ConfigDict(extra="allow") + + +class JsonContent(BaseModel): + """Json content for a message.""" + + type: Literal["json"] + data: dict[str, Any] + """The json content of the message.""" + annotations: Annotations | None = None + meta: dict[str, Any] | None = Field(alias="_meta", default=None) + """ + See [MCP specification](https://github.com/modelcontextprotocol/modelcontextprotocol/blob/47339c03c143bb4ec01a26e721a1b8fe66634ebe/docs/specification/draft/basic/index.mdx#general-fields) + for notes on _meta usage. + """ + model_config = ConfigDict(extra="allow") class SamplingMessage(BaseModel): """Describes a message issued to or received from an LLM API.""" role: Role - content: TextContent | ImageContent | AudioContent + content: TextContent | ImageContent | AudioContent | JsonContent model_config = ConfigDict(extra="allow") @@ -751,7 +766,7 @@ class ResourceLink(Resource): type: Literal["resource_link"] -ContentBlock = TextContent | ImageContent | AudioContent | ResourceLink | EmbeddedResource +ContentBlock = TextContent | ImageContent | AudioContent | JsonContent | ResourceLink | EmbeddedResource """A content block that can be used in prompts and tool results.""" Content: TypeAlias = ContentBlock @@ -1044,7 +1059,7 @@ class CreateMessageResult(Result): """The client's response to a sampling/create_message request from the server.""" role: Role - content: TextContent | ImageContent | AudioContent + content: TextContent | ImageContent | AudioContent | JsonContent model: str """The name of the model that generated the message.""" stopReason: StopReason | None = None From ea7ddd6cfda35720b86775067628b57b4b682e17 Mon Sep 17 00:00:00 2001 From: chenzailong Date: Thu, 17 Jul 2025 11:54:55 +0800 Subject: [PATCH 2/3] Add DictContext to mcp.type.ContentBlock --- src/mcp/types.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mcp/types.py b/src/mcp/types.py index a5f03dda04..1dd2405c59 100644 --- a/src/mcp/types.py +++ b/src/mcp/types.py @@ -714,12 +714,12 @@ class AudioContent(BaseModel): model_config = ConfigDict(extra="allow") -class JsonContent(BaseModel): - """Json content for a message.""" +class DictContent(BaseModel): + """Dict content for a message.""" - type: Literal["json"] + type: Literal["dict"] data: dict[str, Any] - """The json content of the message.""" + """The dict content of the message.""" annotations: Annotations | None = None meta: dict[str, Any] | None = Field(alias="_meta", default=None) """ @@ -733,7 +733,7 @@ class SamplingMessage(BaseModel): """Describes a message issued to or received from an LLM API.""" role: Role - content: TextContent | ImageContent | AudioContent | JsonContent + content: TextContent | ImageContent | AudioContent | DictContent model_config = ConfigDict(extra="allow") @@ -766,7 +766,7 @@ class ResourceLink(Resource): type: Literal["resource_link"] -ContentBlock = TextContent | ImageContent | AudioContent | JsonContent | ResourceLink | EmbeddedResource +ContentBlock = TextContent | ImageContent | AudioContent | DictContent | ResourceLink | EmbeddedResource """A content block that can be used in prompts and tool results.""" Content: TypeAlias = ContentBlock @@ -1059,7 +1059,7 @@ class CreateMessageResult(Result): """The client's response to a sampling/create_message request from the server.""" role: Role - content: TextContent | ImageContent | AudioContent | JsonContent + content: TextContent | ImageContent | AudioContent | DictContent model: str """The name of the model that generated the message.""" stopReason: StopReason | None = None From 031b65d0b7c9e0298a163ac6fb79ee1048759baf Mon Sep 17 00:00:00 2001 From: chenzailong Date: Thu, 17 Jul 2025 12:06:51 +0800 Subject: [PATCH 3/3] style: format code with ruff --- src/mcp/types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mcp/types.py b/src/mcp/types.py index 1dd2405c59..0cf72a5412 100644 --- a/src/mcp/types.py +++ b/src/mcp/types.py @@ -712,7 +712,7 @@ class AudioContent(BaseModel): for notes on _meta usage. """ model_config = ConfigDict(extra="allow") - + class DictContent(BaseModel): """Dict content for a message."""