FastestMCP.Resources.Directory (fastest_mcp v0.1.2)

Copy Markdown View Source

Helper for serving directory listings as JSON resources.

This helper covers the common directory-resource cases:

  • absolute-path validation
  • non-recursive or recursive file listing
  • optional hidden-file inclusion
  • normalized read errors

read/1 returns a FastestMCP.Resources.Result with one JSON content item. That keeps the result transport-safe while still making the directory listing explicit and inspectable in Elixir code.

Example

directory = FastestMCP.Resources.Directory.new("/tmp/reports", recursive: true)

FastestMCP.add_resource(server, "dir:///tmp/reports", fn _arguments, _ctx ->
  FastestMCP.Resources.Directory.read(directory)
end)

Summary

Functions

Lists files in the configured directory.

Builds a directory-listing resource helper.

Reads the directory listing and returns a normalized resource result.

Types

t()

@type t() :: %FastestMCP.Resources.Directory{
  include_hidden: boolean(),
  mime_type: String.t(),
  path: Path.t(),
  recursive: boolean()
}

Functions

list_files(directory)

Lists files in the configured directory.

new(path, opts \\ [])

Builds a directory-listing resource helper.

read(directory)

Reads the directory listing and returns a normalized resource result.