expectToolCallFails function

Future<CallToolResult> expectToolCallFails(
  1. McpServerHarness harness,
  2. String name, {
  3. Map<String, Object?>? arguments,
})

Calls the tool name with arguments and fails the current test unless the call reports an in-band error (isError: true).

A protocol-level RpcException is not treated as a pass: the MCP specification wants tool failures reported in-band, so an exception propagates and fails the test with its own message.

Implementation

Future<CallToolResult> expectToolCallFails(
  McpServerHarness harness,
  String name, {
  Map<String, Object?>? arguments,
}) async {
  final result = await harness.callTool(name, arguments: arguments);
  if (!(result.isError ?? false)) {
    fail(
      'Expected tool "$name" to answer with an in-band error, but it '
      'succeeded: ${_contentSummary(result)}',
    );
  }
  return result;
}