Propagate tool call exceptions through filters (#844)

* Add McpProtocolException specifically for JSON-RPC errors
This commit is contained in:
Stephen Halter 2025-10-14 21:10:55 -05:00 • committed by GitHub
commit 3255adb4d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -62,7 +62,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
};
default:
throw new McpException($"Unexpected cursor: '{cursor}'", McpErrorCode.InvalidParams);
throw new McpProtocolException($"Unexpected cursor: '{cursor}'", McpErrorCode.InvalidParams);
}
})
.WithListResourceTemplatesHandler(async (request, cancellationToken) =>
@ -91,7 +91,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
}],
};
default:
throw new McpException($"Unexpected cursor: '{cursor}'", McpErrorCode.InvalidParams);
throw new McpProtocolException($"Unexpected cursor: '{cursor}'", McpErrorCode.InvalidParams);
}
})
.WithReadResourceHandler(async (request, cancellationToken) =>
@ -109,7 +109,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
};
}
throw new McpException($"Resource not found: {request.Params?.Uri}");
throw new McpProtocolException($"Resource not found: {request.Params?.Uri}");
})
.WithResources<SimpleResources>();
}
@ -235,7 +235,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
{
await using McpClient client = await CreateMcpClientForServer();
await Assert.ThrowsAsync<McpException>(async () => await client.ReadResourceAsync(
await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ReadResourceAsync(
$"resource://mcp/{nameof(SimpleResources.ThrowsException)}",
cancellationToken: TestContext.Current.CancellationToken));
}
@ -245,7 +245,7 @@ public partial class McpServerBuilderExtensionsResourcesTests : ClientServerTest
{
await using McpClient client = await CreateMcpClientForServer();
var e = await Assert.ThrowsAsync<McpException>(async () => await client.ReadResourceAsync(
var e = await Assert.ThrowsAsync<McpProtocolException>(async () => await client.ReadResourceAsync(
"test:///NotRegisteredResource",
cancellationToken: TestContext.Current.CancellationToken));