getResourceWithTemplate method

Future<ReadResourceResult> getResourceWithTemplate(
  1. String templateUri,
  2. Map<String, dynamic> params, {
  3. Map<String, dynamic>? meta,
  4. RequestOptions? options,
})

Get a resource using a template

templateUri - The URI template to use params - Parameters to fill in the template

Returns a Future that resolves to the resource content

Implementation

Future<ReadResourceResult> getResourceWithTemplate(
  String templateUri,
  Map<String, dynamic> params, {
  Map<String, dynamic>? meta,
  RequestOptions? options,
}) async {
  if (!_initialized) {
    throw McpError('Client is not initialized');
  }

  if (!_statelessMode && _serverCapabilities?.resources != true) {
    throw McpError('Server does not support resources');
  }

  // Construct a URI from the template and parameters
  // This is a simple implementation - for complex URI templates,
  // a more robust implementation would be needed
  String uri = templateUri;
  params.forEach((key, value) {
    uri = uri.replaceAll('{$key}', Uri.encodeComponent(value.toString()));
  });

  return await readResource(uri, meta: meta, options: options);
}