Client functions for the Skills extension (io.modelcontextprotocol/skills)
over a Snodo.Client.
Declare the extension when connecting, so a server that serves skills to
declaring clients only, as Snodo.Skills does, answers:
{:ok, client} =
Snodo.Client.connect({:http, url},
client_capabilities: Snodo.Skills.Client.capabilities()
)
{:ok, [entry | _rest]} = Snodo.Skills.Client.list(client)
{:ok, skill_md} = Snodo.Skills.Client.load(client, entry)
{:ok, forms} =
Snodo.Skills.Client.read(client, entry, "skill://pdf-processing/references/FORMS.md")list/2 and get/3 only fetch entries; neither reads a skill file. A
host reads files when it needs them: load/3 reads a skill's SKILL.md
and read/4 any file the entry lists.
Verification
Every read is checked against the entry before the content is returned:
- The URI must be listed in the entry's
"resources". - The listed size must be at most
:max_file_bytes, before anything is read. - The content's byte length must equal the listed
"size". - The SHA-256 digest of the bytes must equal the listed
"digest". - For the skill's SKILL.md, the frontmatter is parsed with
Snodo.Skills.Frontmatterand compared field by field with the entry's"frontmatter". A field that is missing on one side andnullon the other is the same.
An entry whose "resources" is "dynamic" publishes no digests, so steps
1 to 4 are skipped and only step 5 applies.
A read that fails a check returns {:error, %Snodo.Error{}} with code
-32000, kind :extension, and data %{"uri" => uri, "reason" => reason},
where reason is one of "not_listed", "too_large", "size_mismatch",
"digest_mismatch", "frontmatter_unreadable", "frontmatter_mismatch"
(data also has "fields"), "missing_content", or "malformed_entry".
The content is not returned, and nothing more is read.
Options
Each function also takes the options of Snodo.Client.request/4, and:
:max_file_bytes- the largest listed file sizeread/4andload/3fetch. Defaults to 16,777,216 (16 MiB). The encoded response must also fit the transport's limit (:max_response_bytesover HTTP,:max_line_bytesover stdio, both 16 MiB by default), or the read fails with that transport error. ASnodo.Skillsserver with the default:max_response_byteskeeps each file's"contents"array within 16 MiB less 4,096 bytes on HTTP and stdio, so the response fits unless the rest of it is over those 4,096 bytes, which with any request id the core accepts happens only when the server's encodedserver_infois over 2,408 − d bytes, d being the number of digits of the server'sresources/readttlMs(2,407 bytes for attlMsof 0 to 9). See the Skills limits in the transports guide.:frontmatter_parser- aSnodo.Skills.Frontmatter.parser/0for reading SKILL.md frontmatter.:max_pages- forlist/2, the mostskills/listpages to request. Defaults to the client's:max_pages. A listing that still has anextCursor, or repeats one, returns a -32000 transport error.
Summary
Functions
Returns client capabilities that declare the Skills extension.
Gets one skill's entry by the URI of its SKILL.md.
Lists every skill the server serves, following nextCursor. Returns the
skill entries.
Reads and verifies a skill's SKILL.md, the first step of loading a skill. Returns the resource content map the server sent.
Reads and verifies one file the skill entry lists. Returns the resource content map the server sent.
Verifies a resources/read result for uri against a skill entry without
sending anything, as read/4 does after reading. Returns the content map.
Functions
@spec capabilities() :: map()
Returns client capabilities that declare the Skills extension.
@spec get(Snodo.Client.t(), String.t(), keyword()) :: {:ok, map()} | {:error, Snodo.Error.t()}
Gets one skill's entry by the URI of its SKILL.md.
@spec list(Snodo.Client.t(), keyword()) :: {:ok, [map()]} | {:error, Snodo.Error.t()}
Lists every skill the server serves, following nextCursor. Returns the
skill entries.
@spec load(Snodo.Client.t(), map(), keyword()) :: {:ok, map()} | {:error, Snodo.Error.t()}
Reads and verifies a skill's SKILL.md, the first step of loading a skill. Returns the resource content map the server sent.
@spec read(Snodo.Client.t(), map(), String.t(), keyword()) :: {:ok, map()} | {:error, Snodo.Error.t()}
Reads and verifies one file the skill entry lists. Returns the resource content map the server sent.
Verifies a resources/read result for uri against a skill entry without
sending anything, as read/4 does after reading. Returns the content map.