Skip to content

Add JsonContext to mcp.type.ContentBlock #1161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/mcp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading