Skip to content

fix(mcp): handle EmbeddedResource, AudioContent, and ResourceLink in get_prompt#21364

Open
Yanhu007 wants to merge 1 commit intorun-llama:mainfrom
Yanhu007:fix/mcp-get-prompt-content-types
Open

fix(mcp): handle EmbeddedResource, AudioContent, and ResourceLink in get_prompt#21364
Yanhu007 wants to merge 1 commit intorun-llama:mainfrom
Yanhu007:fix/mcp-get-prompt-content-types

Conversation

@Yanhu007
Copy link
Copy Markdown

Summary

Fixes #21270

BasicMCPClient.get_prompt() currently only handles TextContent and ImageContent. It raises NotImplementedError for EmbeddedResource and ValueError for other valid MCP ContentBlock variants. Any MCP server returning these spec-valid types causes a crash.

Changes

MCP Type Before After
EmbeddedResource (text) NotImplementedError Extracts text → TextBlock
EmbeddedResource (blob) NotImplementedError Falls back to URI description → TextBlock
AudioContent ValueError Converts to AudioBlock
ResourceLink ValueError Converts URI to TextBlock
Unknown types ValueError (crash) Warning + text fallback (graceful)

Key Design Decisions

  • EmbeddedResource with TextResourceContents extracts the actual text content
  • AudioContent maps directly to LlamaIndex's AudioBlock
  • Unknown future types get a warning instead of crashing — forward compatible
  • Used hasattr(types, ...) guards for types that may not exist in older MCP SDK versions

…get_prompt

get_prompt() raises NotImplementedError for EmbeddedResource and
ValueError for other valid MCP ContentBlock variants (AudioContent,
ResourceLink). Any MCP server returning these spec-valid types
causes the method to crash.

- EmbeddedResource: extract text from TextResourceContents, fall
  back to URI description for BlobResourceContents
- AudioContent: convert to LlamaIndex AudioBlock
- ResourceLink: convert to TextBlock with URI
- Unknown types: warn and fall back to text representation instead
  of raising ValueError

Fixes run-llama#21270
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 12, 2026
@gautamvarmadatla
Copy link
Copy Markdown
Contributor

gautamvarmadatla commented Apr 12, 2026

hello @Yanhu007, issue author here tysm for working on this :) there is a PR already open on this #21271

I took a brief overview of the code, and one major bug i'd say with this implementation is that EmbeddedResource blob payloads are still reduced to a text placeholder and ResourceLink is flattened to just the URI, so image, audio, document, title, and description data are not preserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: BasicMCPClient.get_prompt() fails on valid MCP ContentBlock types

2 participants