Skip to content

Commit dfafebd

Browse files
Avoid propagating server tool exception message to client (#242)
Co-authored-by: Eirik Tsarpalis <[email protected]>
1 parent b9c0f26 commit dfafebd

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/ModelContextProtocol/Server/AIFunctionMcpServerTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public override async Task<CallToolResponse> InvokeAsync(
270270
return new CallToolResponse()
271271
{
272272
IsError = true,
273-
Content = [new() { Text = e.Message, Type = "text" }],
273+
Content = [new() { Text = $"An error occurred invoking '{request.Params?.Name}'.", Type = "text" }],
274274
};
275275
}
276276

tests/ModelContextProtocol.Tests/Configuration/McpServerBuilderExtensionsToolsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public async Task Returns_IsError_Content_When_Tool_Fails()
376376
Assert.True(result.IsError);
377377
Assert.NotNull(result.Content);
378378
Assert.NotEmpty(result.Content);
379-
Assert.Contains("Test error", result.Content[0].Text);
379+
Assert.Contains("An error occurred", result.Content[0].Text);
380380
}
381381

382382
[Fact]

0 commit comments

Comments
 (0)