Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions PaperlessMCP/Client/PaperlessClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public DocumentDownload GetDocumentDownloadInfo(int id, string title, string? or
/// <summary>
/// Performs bulk edit operations on documents.
/// </summary>
public async Task<bool> BulkEditDocumentsAsync(
public async Task<(bool Success, string? Error)> BulkEditDocumentsAsync(
int[] documentIds,
string method,
object? parameters = null,
Expand All @@ -406,13 +406,18 @@ public async Task<bool> BulkEditDocumentsAsync(

try
{
var response = await _httpClient.PostAsJsonAsync("api/documents/bulk_edit/", request, JsonOptions, cancellationToken).ConfigureAwait(false);
return response.IsSuccessStatusCode;
var json = JsonSerializer.Serialize(request, request.GetType(), JsonOptions);
var content = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync("api/documents/bulk_edit/", content, cancellationToken).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
return (true, null);
var errorBody = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
return (false, $"HTTP {(int)response.StatusCode}: {errorBody}");
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to perform bulk edit");
return false;
return (false, ex.Message);
}
}

Expand Down
8 changes: 4 additions & 4 deletions PaperlessMCP/Tools/DocumentTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,13 +488,13 @@ public static async Task<string> BulkUpdate(
_ => null
};

var success = await client.BulkEditDocumentsAsync(ids, operation, parameters).ConfigureAwait(false);
var (success, bulkError) = await client.BulkEditDocumentsAsync(ids, operation, parameters).ConfigureAwait(false);

if (!success)
{
var errorResponse = McpErrorResponse.Create(
ErrorCodes.UpstreamError,
"Bulk operation failed",
$"Bulk operation failed: {bulkError}",
meta: new McpMeta { PaperlessBaseUrl = client.BaseUrl }
);
return JsonSerializer.Serialize(errorResponse);
Expand Down Expand Up @@ -543,13 +543,13 @@ public static async Task<string> Reprocess(
return JsonSerializer.Serialize(dryRunResponse);
}

var success = await client.BulkEditDocumentsAsync(new[] { id }, "reprocess").ConfigureAwait(false);
var (success, reprocessError) = await client.BulkEditDocumentsAsync(new[] { id }, "reprocess").ConfigureAwait(false);

if (!success)
{
var errorResponse = McpErrorResponse.Create(
ErrorCodes.UpstreamError,
$"Failed to reprocess document with ID {id}",
$"Failed to reprocess document with ID {id}: {reprocessError}",
meta: new McpMeta { PaperlessBaseUrl = client.BaseUrl }
);
return JsonSerializer.Serialize(errorResponse);
Expand Down