Skip to content

fix(rmcp): add Audio variant to PromptMessageContent#865

Open
bricef wants to merge 1 commit into
modelcontextprotocol:mainfrom
bricef:fix/prompt-message-audio-variant
Open

fix(rmcp): add Audio variant to PromptMessageContent#865
bricef wants to merge 1 commit into
modelcontextprotocol:mainfrom
bricef:fix/prompt-message-audio-variant

Conversation

@bricef
Copy link
Copy Markdown

@bricef bricef commented May 31, 2026

What

Adds the missing Audio variant to PromptMessageContent, bringing it in line with the MCP spec's prompt-message ContentBlock union (text | image | audio | resource_link | resource).

Why

PromptMessageContent had no Audio variant, and since it is #[serde(tag = "type")] with no catch-all, a spec-conformant {"type":"audio",...} content block fails to deserialize:

unknown variant `audio`, expected one of `text`, `image`, `resource`, `resource_link`

This breaks prompts/get end-to-end for any server that returns audio prompt content. It is the audio analogue of #842 / #843 (the embedded-resource variant). The supporting AudioContent type already exists, and Audio is already a variant of the general RawContent enum (tool results, sampling) — only PromptMessageContent omitted it.

Fixes #864.

Changes

  • Add the flattened Audio { #[serde(flatten)] audio: AudioContent } variant (mirrors Image).
  • Add PromptMessage::new_audio constructor (mirrors new_image).
  • Add serialization (flat shape, camelCase mimeType) + deserialization regression tests, in the style of fix(rmcp): flatten Resource variant of PromptMessageContent #843's test_prompt_message_resource_serialization_is_flat.
  • Regenerate the ServerJsonRpcMessage schema snapshot (UPDATE_SCHEMA=1) to include the new audio content block.

Verification

  • just check (clippy, --all-features --all-targets -- -D warnings): clean.
  • just test (cargo test --all-features): passing, including the regenerated schema snapshot and the two new prompt tests. (tests/test_with_python.rs requires an external Python MCP server unavailable in my environment; unrelated to this change.)
  • cargo +nightly fmt --check: clean.

The spec's prompt-message ContentBlock union is
`text | image | audio | resource_link | resource`, but
PromptMessageContent omitted `Audio`. Because the enum is
`#[serde(tag = "type")]` with no catch-all, a spec-conformant
`{"type":"audio",...}` content block failed to deserialize with
"unknown variant `audio`", breaking prompts/get for any server that
returns audio prompt content (the audio analogue of modelcontextprotocol#842 / modelcontextprotocol#843).

The supporting AudioContent type already existed, and Audio was
already a variant of the general RawContent enum (tool results,
sampling) -- only PromptMessageContent lacked it.

Add the flattened Audio variant (mirroring Image), a
PromptMessage::new_audio constructor (mirroring new_image), and
serialization + deserialization regression tests.

Fixes modelcontextprotocol#864.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bricef bricef requested a review from a team as a code owner May 31, 2026 18:43
@github-actions github-actions Bot added T-test Testing related changes T-config Configuration file changes T-core Core library changes T-model Model/data structure changes labels May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-model Model/data structure changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: PromptMessageContent is missing the Audio variant (diverges from MCP spec ContentBlock)

1 participant