# `Snodo.Skills`
[🔗](https://github.com/joshrotenberg/snodo/blob/v0.5.0/lib/snodo/skills.ex#L1)

The Skills extension (SEP-2640, `io.modelcontextprotocol/skills`) for MCP
`2026-07-28`. Skills is Beta. See
[Extension maturity](extensions.html#extension-maturity).

A skill is a directory with a `SKILL.md` file at its root and any number of
supporting files. Each file is an MCP resource under
`skill://<skill-path>/<file>`, where the last segment of the skill path is
the skill name. The extension adds three methods:

  * `skills/list` - the skills the server serves, one entry per skill with
    its URI, its SKILL.md frontmatter, and a `{"uri", "digest", "size"}`
    object for every file, so a client can verify what it reads.
  * `skills/get` - one skill's entry, by the URI of its SKILL.md.
  * `resources/directory/read` - the direct children of a skill directory.
    Subdirectories carry the MIME type `inode/directory`. The server
    advertises `"directoryRead": true` when this method is enabled.

## Defining skills

`use Snodo.Skills` builds the catalog when the module compiles:

    defmodule MyApp.Skills do
      use Snodo.Skills, directory: "priv/skills"
    end

`:directory` is searched for `SKILL.md` files at any depth; each one makes
its directory a skill, whose path is the directory's path relative to
`:directory`. A relative `:directory` is relative to the working directory
of the compiler, which under Mix is the project root. Every regular file in
the skill directory except dotfiles is part of the skill. The module
recompiles when a file under `:directory` is added, removed, or changed:
it records the path, size, and modification time of every entry when it
compiles, and its `__mix_recompile__?/0` compares them on each
`mix compile`. Modification times are in whole seconds and contents are
not compared, so this check misses a change that keeps a file's size and
lands in the same second as the file's previous modification; touch the
file again or run `mix compile --force`. A symbolic link anywhere under
`:directory` raises `ArgumentError` rather than being followed, so a link
cannot publish a file from outside it. A skill's file count and sizes are
checked against the limits below before any of its files is read. The
directory is read when the module compiles and is trusted not to change
during compilation.

`:entries` adds skills the application supplies, each a keyword list or map
with a `:path` and a `:files` map of relative paths to file contents:

    use Snodo.Skills,
      entries: [
        [path: "release-notes", files: %{"SKILL.md" => skill_md, "TEMPLATE.md" => template}]
      ]

Only skills supplied through `:entries` can set `:metadata`. It supplies the
protocol `"_meta"` object in `skills/list` and `skills/get` and is separate
from the Agent Skills frontmatter `metadata` field. Invalid metadata raises
`ArgumentError` when the module compiles.

The two options can be combined. Skill path segments may not be `.` or
`..`. The SKILL.md frontmatter is read with
`Snodo.Skills.Frontmatter` and must have a non-empty `name`, equal to the
last segment of the skill path, and a non-empty `description`. Digests are
SHA-256 hashes of each file's bytes, computed when the module compiles.

Other options:

  * `:directory_read` - serve `resources/directory/read` and advertise
    `"directoryRead": true`. Defaults to `true`.
  * `:page_size` - skills per `skills/list` page. Defaults to 50. A skill
    entry is never split across pages, and a page ends early when the next
    entry would take it past `:max_response_bytes`.
  * `:directory_page_size` - children per `resources/directory/read` page.
    Defaults to 100, and bounded by `:max_response_bytes` in the same way.
  * `:max_response_bytes` - the largest response the module may send.
    Defaults to 16,777,216 (16 MiB), the default response limit of
    `Snodo.Client` over HTTP and stdio. 4,096 bytes of it are left for the
    JSON-RPC envelope. The rest, the budget, bounds the skills part of
    each response measured as the JSON array it is sent in, brackets and
    commas included: the `"contents"` of a `resources/read` result and
    the pages of `skills/list` and `resources/directory/read`. So every
    file's content, every skill entry, and every directory child must
    encode to at most the budget less 2 bytes, and pages are cut to the
    budget. Sizes are the larger of the HTTP encoding (raw UTF-8) and the
    stdio framing, which writes every character outside ASCII as a
    `\uXXXX` escape, so an "é" counts as 6 bytes and a character above
    U+FFFF as 12. Must be at least 4,098, so the budget holds the 2-byte
    `[]` an empty `skills/list` sends. The whole response fits only if the
    rest of it fits in the 4,096 bytes. The request id is bounded by the
    core (a string of at most 256 bytes or an int64), a `nextCursor` is
    at most 99 bytes, and the rest grows by one byte for each digit of
    `ttlMs` after the first; on `resources/read` it also holds the
    server's `server_info` under `_meta`, which nothing bounds. The Skills limits section of the
    transports guide gives the exact sizes and says what happens
    otherwise.
  * `:max_skill_files` - files per skill, SKILL.md included. Defaults to
    512.
  * `:max_skill_bytes` - the total size of a skill's files. Defaults to
    16,777,216 (16 MiB).
  * `:frontmatter_parser` - a `t:Snodo.Skills.Frontmatter.parser/0` to read
    full YAML instead of the built-in subset.
  * `:cache` - `[ttl_ms: non_neg_integer, scope: "private" | "public"]`,
    the `ttlMs` and `cacheScope` of the three results. Defaults to
    `ttl_ms: 0, scope: "private"`.

An invalid skill, such as a missing SKILL.md, a name that breaks the naming
rules, unreadable frontmatter, a skill over `:max_skill_files` or
`:max_skill_bytes`, or a file, skill entry, or `resources/directory/read`
child over `:max_response_bytes`, raises `ArgumentError` and the module
does not compile. A directory child carries both the URI and the file or
directory name, so a very long name can fail this check alone; the check
is skipped with `directory_read: false`. A file within
`:max_skill_bytes` can still be over `:max_response_bytes` once encoded:
base64 makes a binary file a third larger, JSON escapes a control
character in a text file as six bytes, and the stdio framing makes
non-ASCII text up to three times larger.

## Serving skills

The module is the extension, and `resources/0` returns one generated
`Snodo.Resource` module per file, which serves the file's bytes through
`resources/read` and lists it in `resources/list`. A SKILL.md resource takes
its name and description from the frontmatter. Install the extension,
register the resources, and advertise both:

    defmodule MyApp.Server do
      use Snodo.Server,
        name: "my-app",
        version: "1.0.0",
        extensions: [MyApp.Skills]

      for file <- MyApp.Skills.resources(), do: resource(file)
    end

Derived capabilities include `"resources"` when the router registers
resources, so register the skill files as shown above.
A server that passes explicit `capabilities:` can call `capabilities/1`,
which adds `"resources"` and the extension's declaration to the map.

## Negotiation

Like every `Snodo.Extension`, the three methods are answered only for a
request whose client declares `io.modelcontextprotocol/skills` in its
capabilities. A client that does not gets -32021 (missing required client
capability), with the extension in the error's `requiredCapabilities`. The
skill files themselves are ordinary resources that any client can read.
`Snodo.Skills.Client.capabilities/0` returns the declaration for
`Snodo.Client`.

## Errors

`skills/get` for a URI that is not a served skill's SKILL.md, and
`resources/directory/read` for a URI that is not a served skill directory,
answer -32602 with the URI in the error data. An invalid or expired cursor,
one longer than 1,024 bytes, or one issued for another listing or directory
answers -32602. Cursors the server issues are under 100 bytes.

# `capabilities`

```elixir
@spec capabilities(map(), boolean()) :: map()
```

Adds `"resources"` (keeping any settings already there) and the extension's
declaration to `capabilities`. The declaration is `%{"directoryRead" =>
true}` when `directory_read?` is true, and `%{}` otherwise.

# `id`

```elixir
@spec id() :: String.t()
```

Returns the extension identifier, `"io.modelcontextprotocol/skills"`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
