request method

Future<McpJsonMap> request(
  1. String method, {
  2. Object? id,
  3. McpJsonMap? params,
  4. bool streamable = true,
  5. bool includeSession = true,
  6. String? protocolVersion,
  7. Map<String, String> headers = const <String, String>{},
})

Sends a stateful JSON-RPC request using the active MCP session.

Implementation

Future<McpJsonMap> request(
  String method, {
  Object? id,
  McpJsonMap? params,
  bool streamable = true,
  bool includeSession = true,
  String? protocolVersion,
  Map<String, String> headers = const <String, String>{},
}) async {
  final response = await post(
    <String, Object?>{
      'jsonrpc': '2.0',
      'id': id ?? _nextRequestId++,
      'method': method,
      'params': ?params,
    },
    streamable: streamable,
    includeSession: includeSession,
    protocolVersion: protocolVersion,
    headers: headers,
  );
  if (response == null) {
    throw FormatException('$method did not return a JSON-RPC body');
  }
  return response;
}