readResource method

Future<List<McpJsonMap>> readResource(
  1. String uri, {
  2. Object? id,
  3. bool streamable = true,
  4. bool directJson = false,
  5. String? protocolVersion,
  6. Map<String, String> headers = const <String, String>{},
})

Reads a resource through the active MCP session.

Implementation

Future<List<McpJsonMap>> readResource(
  String uri, {
  Object? id,
  bool streamable = true,
  bool directJson = false,
  String? protocolVersion,
  Map<String, String> headers = const <String, String>{},
}) async {
  final resourceUri = _validatedMcpResourceUri(uri, 'uri');
  final response = await request(
    'resources/read',
    id: id,
    params: <String, Object?>{'uri': resourceUri},
    streamable: directJson ? false : streamable,
    includeSession: !directJson,
    protocolVersion: protocolVersion,
    headers: headers,
  );
  final result = _jsonRpcResultFrom(response, method: 'resources/read');
  return _validatedResourceReadContents(
    _jsonMapListFrom(
      result,
      key: 'contents',
      method: 'resources/read',
      label: 'resources/read result content',
    ),
    label: 'resources/read result content',
  );
}