getResourceWithTemplate method
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,
) async {
if (!_initialized) {
throw McpError('Client is not initialized');
}
if (_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);
}