π The fast, Pythonic way to build MCP servers and clients.
Rewrite skills docs around Skill and SkillCatalogProvider (#6066)
nate nowack8514f0ece06c
diff --git a/docs/servers/skills.mdx b/docs/servers/skills.mdxindex 40f62197b..e38d94c83 100644--- a/docs/servers/skills.mdx+++ b/docs/servers/skills.mdx@@ -1,7 +1,7 @@---title: Skills over MCPsidebarTitle: Skills-description: Serve a folder of agent skills from a FastMCP server so every connected agent reads the same maintained copy.+description: Serve agent skills from a FastMCP server so every connected agent reads the same maintained copy.icon: wand-magic-sparkles---@@ -9,70 +9,183 @@ import { VersionBadge } from '/snippets/version-badge.mdx'<VersionBadge version="3.0.0" />-An agent skill is a folder with a `SKILL.md` file of instructions and any supporting files those instructions refer to. Agents usually load skills from a local folder, so every machine needs its own copy and every copy drifts. Serving skills from an MCP server keeps one maintained copy in your repository: agents that connect read the current version, and an update ships when you deploy the server.+An agent skill is a `SKILL.md` file of instructions plus any supporting files those instructions refer to. Agents usually load skills from a local folder, so every machine needs its own copy and every copy drifts. Serving skills from an MCP server keeps one maintained copy: agents that connect read the current version, and an update ships when you deploy the server.-FastMCP serves a skills folder in two ways at once:+Clients see served skills in two ways:- **As resources.** Each skill's files are ordinary MCP resources under `skill://` URIs. Every MCP client can list and read them today.-- **Through Skills discovery.** Since FastMCP 4.1.2, the [MCP Skills extension](https://modelcontextprotocol.io/seps/2640-skills-extension) adds `skills/list` and `skills/get`, which return each skill's frontmatter and a manifest of its files with sizes and SHA-256 digests. A host that supports the extension can offer your skills to its agent without a separate install step. This support is experimental in FastMCP, and few hosts read it yet.+- **Through Skills discovery.** Since FastMCP 4.1.2, the [MCP Skills extension](https://modelcontextprotocol.io/seps/2640-skills-extension) adds `skills/list` and `skills/get`, which return each skill's frontmatter and a manifest of its files with sizes and SHA-256 digests. A host that supports the extension can offer your skills to its agent without a separate install step. This support is experimental in FastMCP, and only a handful of hosts read it so far.-The rest of this page builds one server that does both, then shows what each kind of client sees.+The recommended path is to define each skill as a `Skill` object, and serve them with `SkillCatalogProvider`, which publishes them both as resources and through discovery. The rest of this page follows that path, then covers the folder-based providers and when to pick them.-## Lay out the skills folder+## Define skills-Keep skills in a folder in the repository that owns them, one folder per skill. The folder name is the skill's name and becomes its URI.+<VersionBadge version="4.2.0" />-```text-skills/-βββ server-authoring/-β βββ SKILL.md-β βββ references/-β βββ testing.md-βββ client-cli/- βββ SKILL.md+A `Skill` holds one skill's files in memory, exactly as they will be served. You can write it in Python, read it from a folder, or load it from an installed package.++```python+from fastmcp.skills import Skill++release_notes = Skill(+ name="release-notes",+ description="Write release notes from merged pull requests.",+ instructions="# Release notes\n\nGroup changes by theme. Follow template.md.\n",+ files={"template.md": "## Highlights\n\n## Fixes\n"},+)```-Start each `SKILL.md` with [Agent Skills](https://agentskills.io/specification) frontmatter. Skills discovery requires a `name` equal to the folder name, made of lowercase letters, digits, and single hyphens, and a `description` of up to 1,024 characters. The description is what an agent reads to decide whether the skill applies, so say when to use it.+The constructor writes `SKILL.md` from `name`, `description`, `instructions`, and any extra `frontmatter` you pass. Refer to supporting files by their path relative to the skill, as `template.md` does above; clients resolve that path against the skill's URI.++The other constructors read files you already have:++- `Skill.from_directory("skills/deploy")` reads a skill folder.+- `Skill.from_package("my_package", "skills/review")` reads a skill folder shipped inside an installed Python package.+- `Skill.from_files({"SKILL.md": ..., "notes.md": ...})` builds a skill from a mapping of relative paths to `str` or `bytes`.++Each one reads the files once and keeps their exact bytes, so later edits to a folder don't change the skill. A `Skill` is immutable and validated when you create it. Its `SKILL.md` needs [Agent Skills](https://agentskills.io/specification) frontmatter with a `name` made of lowercase letters, digits, and single hyphens, and a `description` of up to 1,024 characters. The description is what an agent reads to decide whether the skill applies, so say when to use it. A folder's name must match its `name`, and a skill may hold up to 512 files and 16 MiB in total.++A skill folder looks like this:++```text+skills/deploy/+βββ SKILL.md+βββ references/+ βββ checklist.md+``````markdown----name: server-authoring-description: Build, extend, and review MCP servers in this repository.+name: deploy+description: Deploy the app to staging or production. Use before any release.----# Server authoring+# Deploy-Before changing a tool, read `references/testing.md` and test through an in-memory client.+Run through `references/checklist.md` before deploying.```-Refer to supporting files by their path relative to the skill folder, as `references/testing.md` does above. Clients resolve that path against the skill's URI.--## Serve the folder+## Serve skills-`SkillsDirectoryProvider` publishes every skill folder under a root directory. Setting `experimental_skills=True` on it also turns on Skills discovery: the provider registers `SkillsExtension` on the server for you.+`SkillCatalogProvider` serves a list of `Skill` objects. It registers `SkillsExtension` on the server for you, so adding the provider turns on Skills discovery.```python-from pathlib import Path-from fastmcp import FastMCP-from fastmcp.server.providers.skills import SkillsDirectoryProvider-SKILLS_DIR = Path(__file__).parent / "skills"+from fastmcp.skills.provider import SkillCatalogProvider+from fastmcp.skills import Skill++release_notes = Skill(+ name="release-notes",+ description="Write release notes from merged pull requests.",+ instructions="# Release notes\n\nGroup changes by theme. Follow template.md.\n",+ files={"template.md": "## Highlights\n\n## Fixes\n"},+)mcp = FastMCP("Team Skills")-skills = SkillsDirectoryProvider(SKILLS_DIR, experimental_skills=True)+skills = SkillCatalogProvider([release_notes, Skill.from_directory("skills/deploy")])mcp.add_provider(skills)if __name__ == "__main__":mcp.run(transport="http", port=8000)```-Save this as `server.py` next to the `skills/` folder and run `python server.py`. The server can carry tools, resources, and prompts as usual; skills are one more provider.+Each skill is served at `skill://{name}/`. Every file is listed as a resource, along with a `_manifest` resource for clients that read skills without discovery.-To serve skills as resources only, leave out `experimental_skills=True`.+Pass a mapping to choose a skill's path, such as `{"team/review": review}`. The last segment must match the skill's name, and one skill's path can't sit inside another's.-## Read skills as resources+### Load skills at request time-Any MCP client sees each skill as two listed resources: its `SKILL.md` and a synthetic `_manifest`.+To serve skills that change while the server runs, such as rows in a database, subclass the provider and override `load_skills()`. FastMCP calls it once per MCP request, and every lookup in that request sees the same skills.++```python+from fastmcp import FastMCP+from fastmcp.skills.provider import SkillCatalogProvider+from fastmcp.skills import Skill++# Stands in for your storage: one dict of files per skill.+SKILL_ROWS = [+ {"SKILL.md": "---\nname: triage\ndescription: Triage new issues.\n---\n# Triage\n"},+]+++class StoredSkills(SkillCatalogProvider):+ async def load_skills(self) -> list[Skill]:+ return [Skill.from_files(files) for files in SKILL_ROWS]+++mcp = FastMCP("Stored Skills")+skills = StoredSkills()+mcp.add_provider(skills)+```++### Choose a provider++`SkillCatalogProvider` fits most servers. The folder providers read skills straight from disk on every request, which suits a skills folder you are still editing or one owned by a coding agent.++| You want to serve | Use |+|-------------------|-----|+| Skills written in code, shipped in a package, or loaded from storage | `SkillCatalogProvider` |+| A folder you edit while the server runs, or skills nested inside other skills | `SkillsDirectoryProvider` |+| A coding agent's own skills folder, such as `~/.claude/skills/` | A vendor provider, such as `ClaudeSkillsProvider` |+| One skill folder, as resources only | `SkillProvider` |++### Serve a skills folder from disk++`SkillsDirectoryProvider` publishes every skill folder under one or more roots. Set `experimental_skills=True` on it to turn on discovery; the provider then registers `SkillsExtension` for you.++```python+from pathlib import Path++from fastmcp import FastMCP+from fastmcp.server.providers.skills import SkillsDirectoryProvider++mcp = FastMCP("Folder Skills")+skills = SkillsDirectoryProvider(+ roots=[Path.cwd() / "skills", Path.home() / ".claude" / "skills"],+ experimental_skills=True,+)+mcp.add_provider(skills)+```++With `experimental_skills=True`, the provider reads files from disk on every request, serves a nested skill such as `skills/team/review/SKILL.md` as its own entry, applies the same validation and limits as `Skill`, and leaves invalid skills out of `skills/list` with a warning while keeping their files readable. Skill roots and their contents must not be symbolic links, and every file in a skill folder is published, including hidden files. When the same skill path appears in more than one root, discovery omits it.++Without the flag, the provider serves resources only and keeps its permissive behavior: frontmatter is optional, the first root wins on duplicate names, and links to folders elsewhere on disk are followed. A few options apply to this mode:++- `reload=True` re-scans the roots on every request, for local editing. Leave it off in production.+- `supporting_files="resources"` lists every supporting file in `resources/list`. By default, clients find them through each skill's `_manifest` and a `skill://{name}/{path*}` template.++Vendor providers are `SkillsDirectoryProvider` subclasses with roots fixed to a coding agent's skills folder. They take the same options except `roots`.++| Provider | Folder |+|----------|--------|+| `ClaudeSkillsProvider` | `~/.claude/skills/` |+| `CursorSkillsProvider` | `~/.cursor/skills/` |+| `VSCodeSkillsProvider` | `~/.copilot/skills/` |+| `CodexSkillsProvider` | `/etc/codex/skills/`, then `~/.codex/skills/` |+| `GeminiSkillsProvider` | `~/.gemini/skills/` |+| `GooseSkillsProvider` | `~/.config/agents/skills/` |+| `CopilotSkillsProvider` | `~/.copilot/skills/` |+| `OpenCodeSkillsProvider` | `~/.config/opencode/skills/` |++`SkillProvider(Path("skills/deploy"))` serves a single skill folder as resources. For discovery, serve `Skill.from_directory()` with `SkillCatalogProvider` instead.++## Access control++Skills discovery respects the same rules as resource reads. A skill is omitted from `skills/list` when any of its files is hidden from the caller, denied by `Middleware.check_resource_access`, or shadowed by another resource at the same URI. `check_resource_access` is the hook that [`AuthMiddleware`](/servers/authorization) and the default `on_read_resource` use, so implement custom resource authorization there; restrictions in other middleware hooks are invisible to discovery.++## Mounted servers++Skills follow a [mounted server](/servers/composition) to its parent. The parent's `skills/list` includes the child's skills at the URIs the parent serves them at, so `mount(child, namespace="team")` turns `skill://review/SKILL.md` into `skill://team/review/SKILL.md`, and every file in the manifest moves with it. This works through any depth of mounts.++The parent lists a mounted skill only when it routes every file back to the child and the caller passes the parent's own access checks. A parent resource that shadows one of the files, or a parent middleware rule that denies one, hides the skill. Two mounts that publish the same skill URI hide each other's copy.++To limit discovery to specific providers instead, register the extension yourself with `mcp.add_extension(SkillsExtension(providers=[...]))`. An explicit registration replaces the automatic one and doesn't include mounted servers.++## Read skills from a client++### Read skills as resources++Any MCP client can list a server's skills and read their files.```pythonimport asyncio@@ -85,34 +198,25 @@ async def main() -> None:for resource in await client.list_resources():print(resource.uri)- result = await client.read_resource("skill://server-authoring/SKILL.md")+ result = await client.read_resource("skill://deploy/SKILL.md")print(result[0].text)asyncio.run(main())```-```text-skill://client-cli/SKILL.md-skill://client-cli/_manifest-skill://server-authoring/SKILL.md-skill://server-authoring/_manifest-```--Supporting files are not listed one by one. Each skill exposes a resource template, `skill://server-authoring/{path*}`, and the manifest names the files that template serves:+Each skill's `_manifest` resource lists its files with sizes and hashes:```json{- "skill": "server-authoring",+ "skill": "deploy","files": [- {"path": "SKILL.md", "size": 214, "hash": "sha256:751c708f..."},- {"path": "references/testing.md", "size": 88, "hash": "sha256:a4ea8ebc..."}+ {"path": "SKILL.md", "size": 157, "hash": "sha256:751c708f..."},+ {"path": "references/checklist.md", "size": 88, "hash": "sha256:a4ea8ebc..."}]}```-Read a supporting file by joining its path onto the skill's URI, such as `skill://server-authoring/references/testing.md`. To list every file as its own resource instead, see [supporting files](#list-supporting-files-as-resources).-### Install skills into a local agentAgents that only read skills from disk can still use a served copy. `sync_skills()` downloads every skill on the server into a local skills folder, and `download_skill()` downloads one. Both skip skills that already exist unless you pass `overwrite=True`.@@ -137,9 +241,9 @@ async def main() -> None:asyncio.run(main())```-`fastmcp.utilities.skills` also provides `list_skill_summaries()`, which lists skill names from the resource listing, and `get_skill_manifest()`, which reads one manifest. These helpers work with any server that publishes skills as resources, with or without discovery. Earlier releases named the summary helper `list_skills()`; that name still works with a deprecation warning. It is unrelated to `client.list_skills()`, described below.+`fastmcp.utilities.skills` also provides `list_skill_summaries()`, which lists skill names from the resource listing, and `get_skill_manifest()`, which reads one manifest. These helpers work with any server that publishes skills as resources, with or without discovery. Earlier releases named the summary helper `list_skills()`; that name still works with a deprecation warning. It is unrelated to `client.list_skills()`, described next.-## Discover skills with the Skills extension+### Discover skills with the Skills extensionA client that opts into the extension can ask the server for its skills directly. Discovery requires a connection on a modern MCP protocol version, which `Client` negotiates by default.@@ -165,15 +269,9 @@ async def main() -> None:asyncio.run(main())```-```text-skill://client-cli/SKILL.md - Discover and call tools on an existing MCP server from the command line.- skill://client-cli/SKILL.md 179 sha256:6208dfcc...-skill://server-authoring/SKILL.md - Build, extend, and review MCP servers in this repository.- skill://server-authoring/SKILL.md 214 sha256:751c708f...- skill://server-authoring/references/testing.md 88 sha256:a4ea8ebc...-```+`client.list_skills()` and `client.get_skill()` return `MCPSkill` objects: the wire record that describes a skill, much as `MCPTool` describes a tool. `Skill.to_mcp_skill()` builds the same record from a `Skill`. `client.list_skills()` follows every page of `skills/list`; use `list_skills_mcp()` to fetch one page at a time.-`client.list_skills()` and `client.get_skill()` return `MCPSkill` objects: the wire record for a skill, not the skill itself. Listing returns metadata only. The agent reads the files it needs through `resources/read`, and should check each file against its manifest record before using it:+Listing returns metadata only. The agent reads the files it needs through `resources/read`, and should check each file against its manifest record before using it:```pythonimport asyncio@@ -203,7 +301,7 @@ async def main() -> None:extensions=[SkillsClientExtension()],)async with client:- skill = await client.get_skill("skill://server-authoring/SKILL.md")+ skill = await client.get_skill("skill://deploy/SKILL.md")for file in skill.resources:data = await read_verified(client, file.uri, file.size, file.digest)print(file.uri, len(data), "bytes verified")@@ -212,178 +310,15 @@ async def main() -> None:asyncio.run(main())```-A mismatch means the file changed between discovery and the read. Refresh the entry with `client.get_skill(uri)` and read again. `client.list_skills()` follows every page of `skills/list`; use `list_skills_mcp()` to fetch one page at a time.--The client methods only transport entries. Deciding when to load a skill, asking a user to approve it, and running anything it describes are the host's job.--## Define skills in code--A skill doesn't have to live in a folder. `Skill` holds a skill's files in memory, and `SkillCatalogProvider` serves any list of them, so you can write skills in Python, ship them inside a package, or build them from a database. A folder is just one way to create a `Skill`.--<VersionBadge version="4.2.0" />--```python-from fastmcp import FastMCP-from fastmcp.skills.provider import SkillCatalogProvider-from fastmcp.skills import Skill--release_notes = Skill(- name="release-notes",- description="Write release notes from merged pull requests.",- instructions="# Release notes\n\nGroup changes by theme. Follow template.md.\n",- files={"template.md": "## Highlights\n\n## Fixes\n"},-)-deploy = Skill.from_directory("skills/deploy")-review = Skill.from_package("my_package", "skills/review")--mcp = FastMCP("Skills")-skills = SkillCatalogProvider([release_notes, deploy, review])-mcp.add_provider(skills)-```--The constructor writes `SKILL.md` from `name`, `description`, `instructions`, and any extra `frontmatter`. `Skill.from_directory()` and `Skill.from_package()` read a folder once and keep its exact bytes, so later edits to the folder don't change the served skill. Every `Skill` is validated when you create it: frontmatter follows the same strict rules as discovery mode, and a folder's name must match the `name` in its `SKILL.md`.--`SkillCatalogProvider` serves each skill at `skill://{name}/` both as resources and through Skills discovery, so plain MCP clients, `sync_skills()`, and discovery clients all see the same files. Pass a mapping to choose the path, such as `{"team/review": review}`; the last segment must match the skill's name.--To serve skills that change at runtime, subclass the provider and override `load_skills()`. FastMCP calls it once per MCP request, and every lookup in that request sees the same skills.--```python-from fastmcp.skills.provider import SkillCatalogProvider-from fastmcp.skills import Skill---# Stands in for your storage: one dict of files per skill.-SKILL_ROWS = [- {"SKILL.md": "---\nname: triage\ndescription: Triage new issues.\n---\n# Triage\n"},-]---class StoredSkills(SkillCatalogProvider):- async def load_skills(self) -> list[Skill]:- return [Skill.from_files(files) for files in SKILL_ROWS]-```--## Configure the provider--### Search several roots--Pass a list to serve more than one folder. When the same skill name appears in more than one root, the first root wins in resource mode. In discovery mode, duplicate skill paths are omitted from `skills/list`.--```python-from pathlib import Path--from fastmcp import FastMCP-from fastmcp.server.providers.skills import SkillsDirectoryProvider--mcp = FastMCP("Skills")-mcp.add_provider(- SkillsDirectoryProvider(- roots=[- Path.cwd() / "skills",- Path.home() / ".claude" / "skills",- ]- )-)-```--### List supporting files as resources--With the default `supporting_files="template"`, clients find supporting files through each skill's manifest. Set `supporting_files="resources"` to list every file in `resources/list` as well, for clients that expect a flat resource list.--```python-from pathlib import Path--from fastmcp.server.providers.skills import SkillsDirectoryProvider--skills = SkillsDirectoryProvider(Path("skills"), supporting_files="resources")-```--### Pick up edits without restarting--In resource mode the provider scans its roots once. Set `reload=True` to re-scan on every request while you edit skills locally; it adds a directory scan to each request, so leave it off in production. Discovery mode ignores `reload` and always serves current files.--```python-from pathlib import Path--from fastmcp.server.providers.skills import SkillsDirectoryProvider--skills = SkillsDirectoryProvider(Path("skills"), reload=True)-```--### Serve one skill--`SkillProvider` serves a single skill folder, for a server that ships exactly one skill.--```python-from pathlib import Path--from fastmcp import FastMCP-from fastmcp.server.providers.skills import SkillProvider--mcp = FastMCP("Release Skill")-mcp.add_provider(SkillProvider(Path("skills") / "server-authoring"))-```--`SkillProvider` serves resources only. For discovery, serve `Skill.from_directory(path)` with `SkillCatalogProvider`.--### Serve a coding agent's skills folder--Vendor providers are `SkillsDirectoryProvider` subclasses whose roots are fixed to a coding agent's default skills folder. They take the same options except `roots`.--| Provider | Folder |-|----------|--------|-| `ClaudeSkillsProvider` | `~/.claude/skills/` |-| `CursorSkillsProvider` | `~/.cursor/skills/` |-| `VSCodeSkillsProvider` | `~/.copilot/skills/` |-| `CodexSkillsProvider` | `/etc/codex/skills/`, then `~/.codex/skills/` |-| `GeminiSkillsProvider` | `~/.gemini/skills/` |-| `GooseSkillsProvider` | `~/.config/agents/skills/` |-| `CopilotSkillsProvider` | `~/.copilot/skills/` |-| `OpenCodeSkillsProvider` | `~/.config/opencode/skills/` |--```python-from fastmcp import FastMCP-from fastmcp.server.providers.skills import ClaudeSkillsProvider--mcp = FastMCP("My Claude Skills")-mcp.add_provider(ClaudeSkillsProvider())-```--## What discovery mode changes--Setting `experimental_skills=True` makes the provider stricter, because a discovery entry promises exact bytes:--- **Validation.** A skill without valid frontmatter is left out of `skills/list` with a warning, but its files stay readable as resources. Frontmatter must have unique string keys and JSON-compatible values; timestamps, binary values, non-finite numbers, and YAML aliases are rejected.-- **Nested skills.** A skill folder inside another skill, such as `skills/team/review/SKILL.md`, gets its own entry with the URI `skill://team/review/SKILL.md`. The parent's manifest includes the nested files too.-- **Exact reads.** Files are read from disk on every request and returned byte for byte, including CRLF line endings and binary content. Reads that discovery depends on bypass `ResponseCachingMiddleware`.-- **Limits.** A skill with more than 512 files or 16 MiB in total is omitted. Skill roots and their contents must not be symbolic links.-- **Everything is published.** Every file in a skill folder becomes part of the skill, including hidden files, so keep version control and editor files out of skill folders.-- **Generic resource descriptions.** Listed resources carry descriptions such as `Skill: server-authoring` instead of the frontmatter description, so a malformed file can't break resource listing. The author's description appears in the discovery entry.--The manifest is a point-in-time record, not a filesystem snapshot. If a file changes between discovery and a read, the digest check above catches it.--Without the flag, the provider keeps its permissive resource-mode behavior: frontmatter is optional, the description falls back to the first line of the file, links to skill folders elsewhere on disk are followed, and the first root wins on duplicate names.--## Access control--Skills discovery respects the same rules as resource reads. A skill is omitted from `skills/list` when any of its files is hidden from the caller or denied by `Middleware.check_resource_access`, the hook that [`AuthMiddleware`](/servers/authorization) and the default `on_read_resource` use. Implement custom resource authorization in that hook so discovery can apply it; restrictions applied in other middleware hooks are invisible to discovery.--## Mounted servers--<VersionBadge version="4.2.0" />--Skills follow a [mounted server](/servers/composition) to its parent. The parent's `skills/list` includes the child's skills at the URIs the parent serves them at, so `mount(child, namespace="team")` turns `skill://review/SKILL.md` into `skill://team/review/SKILL.md`, and every file in the manifest moves with it. This works through any depth of mounts.--The parent lists a mounted skill only when it routes every file back to the child and the caller passes the parent's own access checks. A parent resource that shadows one of the files, or a parent middleware rule that denies one, hides the skill. Two mounts that publish the same skill URI hide each other's copy.--To limit discovery to specific providers instead, register the extension yourself with `mcp.add_extension(SkillsExtension(providers=[...]))`. An explicit registration replaces the automatic one and doesn't include mounted servers.+A mismatch means the file changed between discovery and the read. Refresh the entry with `client.get_skill(uri)` and read again. The client methods only transport entries; deciding when to load a skill, asking a user to approve it, and running anything it describes are the host's job.## Current limits-Skills discovery serves skills from `SkillsDirectoryProvider` and `SkillCatalogProvider` instances registered on the server you run or on servers mounted into it.+Skills discovery serves skills from `SkillCatalogProvider` and `SkillsDirectoryProvider` instances registered on the server you run or on servers mounted into it.- A skill provider added with a namespace or other transforms is left out of `skills/list`. To namespace skills, mount a server that holds the provider. A server with server-level transforms lists no skills.- A proxy in front of the server forwards the skill files as resources, but not `skills/list` or `skills/get`.+- `SkillCatalogProvider` does not nest skills inside other skills and has no built-in reload; override `load_skills()` for skills that change.- The optional `directoryRead` capability is not implemented.-Resource mode has none of these limits. Serve skills as resources everywhere, and add discovery on the server that clients connect to directly.+Resource mode has none of these limits.