readResource method
Read a resource by URI
Implementation
Future<ReadResourceResult> readResource(String uri) async {
final resource = _resources[uri];
if (resource == null) {
// Check if it matches a template
for (final template in _resourceTemplates.values) {
// Simple template matching (could be improved)
if (_matchesTemplate(uri, template.uriTemplate)) {
// Return a mock result for now
return ReadResourceResult(contents: [
ResourceContentInfo(
uri: uri,
mimeType: template.mimeType,
text: 'Template-based resource content',
),
]);
}
}
throw McpError('Resource not found: $uri');
}
// Get the resource handler
final handler = _resourceHandlers[uri];
if (handler == null) {
throw McpError('No handler registered for resource: $uri');
}
return await handler(uri, {});
}