@@ -243,6 +243,28 @@ static fastmcpp::Json build_openai_messages(const fastmcpp::Json& params)
243243 fastmcpp::Json{{" role" , " tool" }, {" tool_call_id" , tool_use_id}, {" content" , text}});
244244 }
245245
246+ // Python fastmcp commit d6b55c0b (#3857): raise on unhandled content types instead of
247+ // silently dropping. The OpenAI compatible handler currently supports text + tool_use +
248+ // tool_result; image/audio request-body conversion (F16 / commit 734b93b9) is not yet
249+ // implemented in C++, so raise a clear error rather than producing an empty assistant
250+ // message that misleads upstream code.
251+ for (const auto & block : normalize_content_to_array (content))
252+ {
253+ if (!block.is_object ())
254+ continue ;
255+ const std::string t = block.value (" type" , " " );
256+ if (t == " text" || t == " tool_use" || t == " tool_result" || t.empty ())
257+ continue ;
258+ if (t == " image" || t == " audio" )
259+ throw std::runtime_error (
260+ " OpenAI sampling handler: '" + t +
261+ " ' content not yet supported (F16 / fastmcp #3550); cannot dispatch sampling "
262+ " request" );
263+ // Unknown type — surface clearly so callers don't get silent data loss.
264+ throw std::runtime_error (
265+ " OpenAI sampling handler: unhandled content type '" + t + " '" );
266+ }
267+
246268 std::string text = join_text_blocks (content);
247269 auto tool_uses = extract_blocks_by_type (content, " tool_use" );
248270
@@ -388,6 +410,18 @@ static fastmcpp::Json build_anthropic_messages(const fastmcpp::Json& params)
388410 blocks.push_back (std::move (out));
389411 continue ;
390412 }
413+ // Python fastmcp commit d6b55c0b (#3857): raise on unhandled content types.
414+ // Anthropic handler does not support audio inputs at all (Anthropic API doesn't
415+ // accept audio); image is acknowledged but request-body conversion is part of F16
416+ // (commit 734b93b9) and not yet implemented in C++.
417+ if (type == " image" )
418+ throw std::runtime_error (
419+ " Anthropic sampling handler: 'image' content not yet supported "
420+ " (F16 / fastmcp #3550); cannot dispatch sampling request" );
421+ if (type == " audio" )
422+ throw std::runtime_error (
423+ " Anthropic sampling handler: 'audio' content is not supported by the "
424+ " Anthropic Messages API" );
391425 if (type == " tool_result" )
392426 {
393427 // Anthropic expects tool_use_id and string content.
0 commit comments