Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Preserve 4.1 skills type checks and resource-only manifest migration (#6305)

nate nowack6ad09c8d7589
diff --git a/docs/servers/skills.mdx b/docs/servers/skills.mdx
index 94b09500d..e55fbf662 100644
--- a/docs/servers/skills.mdx
+++ b/docs/servers/skills.mdx
@@ -194,8 +194,12 @@ The providers in `fastmcp.server.providers.skills` and the helpers in `fastmcp.u
| `SkillProvider(path)` | `SkillCatalogProvider([Skill.from_directory(path)])` |
| `SkillsDirectoryProvider(root, experimental_skills=True)` | `SkillsDirectoryProvider(root)` from `fastmcp.skills.provider`; the old call already returns it |
| `list_skills(client)` | `client.list_skill_resources()` (any server) or `client.list_skills()` (Skills extension) |
-| `get_skill_manifest(client, name)` | `client.get_skill(uri)` |
+| `get_skill_manifest(client, name)` | `client.read_resource('skill://<name>/_manifest')` for manifest JSON on any resource server; `client.get_skill(uri)` for Skills-extension entries |
| `Skill(uri=..., frontmatter=..., resources=...)` from `fastmcp.skills` | `MCPSkill(...)`; `Skill` is now the authoring class |
| `download_skill()` / `sync_skills()` | `client.read_skill(uri)` then `skill.to_directory(path)` ([example](#install-skills-into-a-local-agent)) |
`client.list_skills()` needs a server that serves the Skills extension, which a 4.1 server doesn't. `client.list_skill_resources()` lists skills on any server that publishes them as `skill://` resources, and `client.read_skill(uri)` reads a valid skill through its `_manifest` resource, so both keep working with older servers after 4.3. The new provider has no `main_file_name` or `supporting_files`: the main file is always `SKILL.md`, and every file in a skill is readable as a resource.
+
+For manifest metadata alone, read the `_manifest` resource and parse its JSON; this does not require the Skills extension, download the skill's files, or validate their frontmatter. `client.get_skill(uri)` requires the extension, while `client.read_skill(uri)` downloads and validates the whole skill.
+
+Existing Pydantic fields annotated with the 4.1 `Skill` spelling still validate wire payloads as `MCPSkill`, and wire entries still satisfy `isinstance(entry, Skill)`. Change wire-model annotations and checks to `MCPSkill` before 4.3. File-serving providers require authored `Skill` values containing the actual files, so passing a wire entry to `SkillCatalogProvider` remains an error.
diff --git a/fastmcp_slim/fastmcp/skills/provider.py b/fastmcp_slim/fastmcp/skills/provider.py
index 3c7f16630..992ce2ece 100644
--- a/fastmcp_slim/fastmcp/skills/provider.py
+++ b/fastmcp_slim/fastmcp/skills/provider.py
@@ -10,19 +10,24 @@ import re
from collections.abc import Iterable, Mapping, Sequence
from contextlib import suppress
from pathlib import Path
-from typing import TYPE_CHECKING, Any, cast
+from typing import TYPE_CHECKING, Annotated, Any, cast
from urllib.parse import quote, unquote
import anyio
from mcp.server.context import ServerRequestContext
-from pydantic import AnyUrl, ConfigDict, ValidationError
+from pydantic import AnyUrl, BeforeValidator, ConfigDict, ValidationError
from fastmcp.resources.base import Resource, ResourceContent, ResourceResult
from fastmcp.server.dependencies import get_context
from fastmcp.server.providers.base import Provider
from fastmcp.skills._routing import _may_read, _resolve_read
from fastmcp.skills.models import MCPSkill
-from fastmcp.skills.skill import Skill, _validate_relative_path
+from fastmcp.skills.skill import (
+ Skill,
+ _is_authored_skill,
+ _require_authored_skill,
+ _validate_relative_path,
+)
from fastmcp.utilities.logging import get_logger
from fastmcp.utilities.versions import VersionSpec
@@ -41,7 +46,7 @@ class SkillFileResource(Resource):
model_config = ConfigDict(arbitrary_types_allowed=True)
- skill: Skill
+ skill: Annotated[Skill, BeforeValidator(_require_authored_skill)]
skill_path: str
file_path: str
@@ -59,7 +64,7 @@ class SkillManifestResource(Resource):
model_config = ConfigDict(arbitrary_types_allowed=True)
- skill: Skill
+ skill: Annotated[Skill, BeforeValidator(_require_authored_skill)]
async def read(self) -> str:
files = [
@@ -375,11 +380,13 @@ def _normalize(skills: SkillCatalog) -> dict[str, Skill]:
else:
catalog = {}
for skill in skills:
+ if not _is_authored_skill(skill):
+ raise TypeError(f"Expected a Skill, got {type(skill).__name__}")
if skill.name in catalog:
raise ValueError(f"Duplicate skill name: {skill.name!r}")
catalog[skill.name] = skill
for path, skill in catalog.items():
- if not isinstance(skill, Skill):
+ if not _is_authored_skill(skill):
raise TypeError(f"Expected a Skill at {path!r}, got {type(skill).__name__}")
if path.split("/")[-1] != skill.name:
raise ValueError(
diff --git a/fastmcp_slim/fastmcp/skills/skill.py b/fastmcp_slim/fastmcp/skills/skill.py
index 6872e759d..b7056143e 100644
--- a/fastmcp_slim/fastmcp/skills/skill.py
+++ b/fastmcp_slim/fastmcp/skills/skill.py
@@ -10,10 +10,11 @@ import warnings
from collections.abc import Mapping
from pathlib import Path, PureWindowsPath
from types import MappingProxyType
-from typing import Any, cast
+from typing import Any, TypeGuard, cast
from urllib.parse import quote
-from pydantic import JsonValue
+from pydantic import GetCoreSchemaHandler, JsonValue
+from pydantic_core import CoreSchema, core_schema
from typing_extensions import Self
from fastmcp._warnings import FastMCPDeprecationWarning
@@ -62,7 +63,27 @@ def _render_skill_md(frontmatter: Mapping[str, JsonValue], instructions: str) ->
return f"---\n{header}---\n{instructions}".encode()
-class Skill:
+class _SkillMeta(type):
+ def __instancecheck__(cls, instance: object) -> bool:
+ # The public 4.1 spelling also identified wire entries. Do not extend
+ # this compatibility behavior to subclasses of the authoring class.
+ return super().__instancecheck__(instance) or (
+ cls is Skill and isinstance(instance, MCPSkill)
+ )
+
+
+def _is_authored_skill(value: object) -> TypeGuard[Skill]:
+ """Check real inheritance, excluding the public wire-model compatibility alias."""
+ return issubclass(type(value), Skill)
+
+
+def _require_authored_skill(value: object) -> Skill:
+ if not _is_authored_skill(value):
+ raise ValueError("Expected an authored Skill with file contents")
+ return value
+
+
+class Skill(metaclass=_SkillMeta):
"""An agent skill: a `SKILL.md` plus supporting files, independent of storage.
A `Skill` holds exact file bytes. It doesn't know where it came from or which
@@ -88,6 +109,19 @@ class Skill:
_files: Mapping[str, bytes]
_frontmatter: SkillFrontmatter
+ @classmethod
+ def __get_pydantic_core_schema__(
+ cls, source_type: Any, handler: GetCoreSchemaHandler
+ ) -> CoreSchema:
+ # Existing authoring values stay intact; dictionaries and JSON retain
+ # the 4.1 wire-model validation and serialization contract.
+ if cls is not Skill:
+ return core_schema.is_instance_schema(cls)
+ wire_schema = handler.generate_schema(MCPSkill)
+ return core_schema.union_schema(
+ [core_schema.is_instance_schema(cls), wire_schema]
+ )
+
def __new__(cls, *args: Any, **kwargs: Any) -> Self:
# In 4.1 `fastmcp.skills.Skill` was the wire model now named `MCPSkill`.
# Its keywords (`uri`, `resources`) never mean an authored skill.
@@ -310,7 +344,7 @@ class Skill:
)
def __eq__(self, other: object) -> bool:
- return isinstance(other, Skill) and self._files == other._files
+ return _is_authored_skill(other) and self._files == other._files
def __hash__(self) -> int:
return hash(tuple(self._files.items()))
diff --git a/fastmcp_slim/fastmcp/utilities/skills.py b/fastmcp_slim/fastmcp/utilities/skills.py
index 196f318fb..ab630905f 100644
--- a/fastmcp_slim/fastmcp/utilities/skills.py
+++ b/fastmcp_slim/fastmcp/utilities/skills.py
@@ -124,8 +124,10 @@ async def get_skill_manifest(client: Client, skill_name: str) -> SkillManifest:
"""
_deprecated(
"get_skill_manifest",
- "Use `await client.get_skill('skill://<name>/SKILL.md')`; its "
- "`resources` list every file with its digest and size.",
+ "Use `await client.read_resource('skill://<name>/_manifest')` to read "
+ "manifest JSON without the Skills extension, or "
+ "`await client.get_skill('skill://<name>/SKILL.md')` for "
+ "Skills-extension entries with file digests and sizes.",
)
return await _get_skill_manifest(client, skill_name)
diff --git a/tests/skills/test_deprecated_paths.py b/tests/skills/test_deprecated_paths.py
index 588218cf7..d425350b9 100644
--- a/tests/skills/test_deprecated_paths.py
+++ b/tests/skills/test_deprecated_paths.py
@@ -2,16 +2,23 @@
from __future__ import annotations
+import json
import warnings
from pathlib import Path
import pytest
+from pydantic import BaseModel, TypeAdapter, ValidationError
from fastmcp import Client, FastMCP
from fastmcp._warnings import FastMCPDeprecationWarning
-from fastmcp.skills import Skill, SkillsClientExtension
+from fastmcp.skills import MCPSkill, Skill, SkillsClientExtension
from fastmcp.skills.extension import SkillsExtension
-from fastmcp.skills.provider import SkillsDirectoryProvider
+from fastmcp.skills.provider import (
+ SkillCatalogProvider,
+ SkillFileResource,
+ SkillManifestResource,
+ SkillsDirectoryProvider,
+)
from fastmcp.utilities.tests import temporary_settings
REVIEW = Skill(name="review", description="Review changes", instructions="# Review\n")
@@ -232,3 +239,88 @@ def test_experimental_skills_refuses_subclasses(tmp_path: Path):
with pytest.raises(TypeError, match="GuardedProvider"):
GuardedProvider(tmp_path, experimental_skills=True)
+
+
+def test_41_skill_pydantic_field_and_instance_checks():
+ class Envelope(BaseModel):
+ skill: Skill
+
+ payload = {
+ "uri": "skill://review/SKILL.md",
+ "frontmatter": {"name": "review", "description": "Review changes"},
+ "resources": "dynamic",
+ }
+ envelope = Envelope.model_validate({"skill": payload})
+ assert isinstance(envelope.skill, Skill)
+ assert isinstance(envelope.skill, MCPSkill)
+ assert (
+ Envelope.model_validate_json(envelope.model_dump_json(by_alias=True))
+ == envelope
+ )
+ assert Envelope.model_json_schema()["properties"]["skill"]
+ adapter = TypeAdapter(Skill)
+ assert adapter.validate_python(payload) == envelope.skill
+ assert (
+ adapter.validate_json(adapter.dump_json(envelope.skill, by_alias=True))
+ == envelope.skill
+ )
+ assert adapter.validate_python(REVIEW) is REVIEW
+
+
+def test_wire_skill_is_not_an_authored_catalog_value():
+ entry = REVIEW.to_mcp_skill()
+ assert isinstance(entry, Skill)
+ assert REVIEW != entry
+ with pytest.raises(TypeError, match="Expected a Skill"):
+ SkillCatalogProvider({"review": entry})
+ with pytest.raises(TypeError, match="Expected a Skill"):
+ SkillCatalogProvider([entry])
+
+
[email protected]("resource_cls", [SkillFileResource, SkillManifestResource])
+def test_skill_resources_require_authored_file_contents(resource_cls: type):
+ with pytest.raises(ValidationError, match="Expected an authored Skill"):
+ resource_cls(
+ uri="skill://review/SKILL.md",
+ skill=REVIEW.to_mcp_skill(),
+ skill_path="review",
+ file_path="SKILL.md",
+ )
+
+
+def test_wire_skill_does_not_satisfy_an_authoring_subclass():
+ class CustomSkill(Skill):
+ pass
+
+ assert not isinstance(REVIEW.to_mcp_skill(), CustomSkill)
+ assert isinstance(
+ CustomSkill(name="review", description="Review", instructions=""), Skill
+ )
+
+ adapter = TypeAdapter(CustomSkill)
+ custom = CustomSkill(name="review", description="Review", instructions="")
+ assert adapter.validate_python(custom) is custom
+ for wire in (REVIEW.to_mcp_skill(), REVIEW.to_mcp_skill().model_dump()):
+ with pytest.raises(ValidationError, match="CustomSkill"):
+ adapter.validate_python(wire)
+
+
+async def test_manifest_warning_preserves_resource_only_access(tmp_path: Path):
+ from fastmcp.server.providers.skills import SkillProvider
+ from fastmcp.utilities.skills import get_skill_manifest
+
+ folder = write_invalid(tmp_path / "review")
+ with pytest.warns(FastMCPDeprecationWarning):
+ provider = SkillProvider(folder)
+ async with Client(FastMCP("Resources only", providers=[provider])) as client:
+ with pytest.warns(FastMCPDeprecationWarning) as record:
+ manifest = await get_skill_manifest(client, "review")
+ assert "client.read_resource('skill://<name>/_manifest')" in str(
+ record[0].message
+ )
+ (content,) = await client.read_resource("skill://review/_manifest")
+ assert json.loads(getattr(content, "text"))["files"][0]["size"] == (
+ manifest.files[0].size
+ )
+ with pytest.raises(RuntimeError, match="Skills extension"):
+ await client.get_skill("skill://review/SKILL.md")