TemplateFileProvider
class TemplateFileProvider(fileSystem: FileSystem, rootDir: Path, name: String = "Arbitrary local file access", description: String = "Allows reading any file by specifying {path}", mimeTypeDetector: MimeTypeDetector = MimeTypeDetector {
"text/plain"
}) : ResourceProvider
A ResourceProvider that exposes rootDir through the URI template:
file:///{path}Content copied to clipboard
to the client, where path is a relative path under rootDir.
Example usage:
val templateProvider = TemplateFileProvider(
fileSystem = FileSystem.SYSTEM,
rootDir = "/app/resources".toPath(),
)Content copied to clipboard
The client can then read resources such as file:///sub/folder/example.txt, which will be resolved to /app/resources/sub/folder/example.txt.
Constructors
Link copied to clipboard
constructor(fileSystem: FileSystem, rootDir: Path, name: String = "Arbitrary local file access", description: String = "Allows reading any file by specifying {path}", mimeTypeDetector: MimeTypeDetector = MimeTypeDetector {
"text/plain"
})
Functions
Link copied to clipboard
open fun attachCallbacks(onResourceChange: suspend (String) -> Unit, onResourcesListChanged: suspend () -> Unit)
Link copied to clipboard
We have no discrete listing of resources; everything is driven by the template, so listResources returns empty by default.
Link copied to clipboard
Returns the resource template defined in the constructor
Link copied to clipboard
Given a 'file:///{path}', we parse the actual path from the URI. Then we do a minimal check (normalize & trivial sandbox check) and read the file from disk if it exists.