From 58e31d67b57aba29ae3beca1797691c6eef430c2 Mon Sep 17 00:00:00 2001 From: a4abdulaleem Date: Tue, 14 Jul 2026 23:27:05 +0500 Subject: [PATCH 1/2] fix: throw InvalidOperationException when MarkItDownMcpReader encounters IsError --- .../MarkItDownMcpReader.cs | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs b/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs index cbec488cb2e..93bcb9fb21a 100644 --- a/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs +++ b/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs @@ -87,7 +87,28 @@ private async Task ConvertToMarkdownAsync(DataContent dataContent, Cance }; // Call the convert_to_markdown tool - var result = await client.CallToolAsync("convert_to_markdown", parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var result = await client.CallToolAsync("convert_to_markdown", parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + + // FIX: Check if the tool execution returned an error + if (result.IsError) + { + // Extract the error message from the content block if available, or fall back to a default error + string errorText = "An unknown error occurred during document conversion."; + + if (result.Content != null && result.Content.Count > 0) + { + foreach (var content in result.Content) + { + if (content.Type == "text" && content is TextContentBlock textBlock) + { + errorText = textBlock.Text; + break; + } + } + } + + throw new InvalidOperationException($"Failed to convert document to markdown: {errorText}"); + } // Extract markdown content from result // The result is expected to be in the format: { "content": [{ "type": "text", "text": "markdown content" }] } From fdf893f7c17ea929f56a84d58595dfb6e6430996 Mon Sep 17 00:00:00 2001 From: a4abdulaleem Date: Wed, 15 Jul 2026 00:36:21 +0500 Subject: [PATCH 2/2] fix: handle nullable bool and fix analyzer formatting rules --- .../MarkItDownMcpReader.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs b/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs index 93bcb9fb21a..6726aff4e2b 100644 --- a/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs +++ b/src/Libraries/Microsoft.Extensions.DataIngestion.MarkItDown/MarkItDownMcpReader.cs @@ -87,14 +87,14 @@ private async Task ConvertToMarkdownAsync(DataContent dataContent, Cance }; // Call the convert_to_markdown tool - var result = await client.CallToolAsync("convert_to_markdown", parameters, cancellationToken: cancellationToken).ConfigureAwait(false); + var result = await client.CallToolAsync("convert_to_markdown", parameters, cancellationToken: cancellationToken).ConfigureAwait(false); - // FIX: Check if the tool execution returned an error - if (result.IsError) + // FIX: Check if the tool execution returned an error (handles bool?) + if (result.IsError == true) { // Extract the error message from the content block if available, or fall back to a default error string errorText = "An unknown error occurred during document conversion."; - + if (result.Content != null && result.Content.Count > 0) { foreach (var content in result.Content)