Skip to content

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

Verify advertised skill frontmatter when reading content (#6090)

nate nowack9d3e5eae0c24
diff --git a/fastmcp_slim/fastmcp/client/mixins/skills.py b/fastmcp_slim/fastmcp/client/mixins/skills.py
index 847117dc6..e95c72966 100644
--- a/fastmcp_slim/fastmcp/client/mixins/skills.py
+++ b/fastmcp_slim/fastmcp/client/mixins/skills.py
@@ -240,7 +240,8 @@ class ClientSkillsMixin:
The manifest comes from `skills/get` when the Skills extension was
negotiated, and otherwise from the `_manifest` resource that FastMCP
skill providers serve next to the files. Every file must match the
- size and SHA-256 digest the manifest promised.
+ size and SHA-256 digest the manifest promised. When an extension entry
+ is available, the parsed frontmatter must also match that entry.
Args:
uri: URI of the skill's `SKILL.md` resource.
@@ -258,7 +259,7 @@ class ClientSkillsMixin:
_, authority, segments = _parse_resource_uri(uri)
if not segments or segments[-1] != "SKILL.md":
raise ValueError(f"read_skill takes a skill's SKILL.md URI, got {uri!r}")
- manifest = await self._skill_manifest(uri, cache_mode)
+ manifest, entry = await self._skill_manifest(uri, cache_mode)
for path in manifest:
_validate_relative_path(path)
files: dict[str, bytes] = {}
@@ -276,6 +277,10 @@ class ClientSkillsMixin:
)
files[path] = content
skill = Skill.from_files(files)
+ if entry is not None and json.dumps(
+ skill.frontmatter.root, sort_keys=True
+ ) != json.dumps(entry.frontmatter.root, sort_keys=True):
+ raise ValueError(f"Skill at {uri!r} does not match its entry's frontmatter")
expected = segments[-2] if len(segments) > 1 else unquote(authority)
if skill.name != expected:
raise ValueError(
@@ -285,8 +290,8 @@ class ClientSkillsMixin:
async def _skill_manifest(
self: Client, uri: str, cache_mode: CacheMode
- ) -> dict[str, SkillResource]:
- """Relative path -> manifest record for every file in the skill.
+ ) -> tuple[dict[str, SkillResource], MCPSkill | None]:
+ """File records and the entry whose frontmatter must match the content.
A skill the server serves as resources but does not advertise through
the extension, such as one behind a proxy, still has a `_manifest`.
@@ -308,8 +313,8 @@ class ClientSkillsMixin:
if path in manifest:
raise ValueError(f"Duplicate skill file path: {path!r}")
manifest[path] = resource
- return manifest
- return await self._resource_mode_manifest(uri)
+ return manifest, entry
+ return await self._resource_mode_manifest(uri), None
async def _resource_mode_manifest(
self: Client, uri: str
diff --git a/tests/skills/test_read_skill.py b/tests/skills/test_read_skill.py
index a67c15190..4dde37456 100644
--- a/tests/skills/test_read_skill.py
+++ b/tests/skills/test_read_skill.py
@@ -17,7 +17,7 @@ from fastmcp import Client, ClientGroup, FastMCP
from fastmcp.server.providers.skills import SkillProvider, SkillsDirectoryProvider
from fastmcp.skills import Skill, SkillsClientExtension
from fastmcp.skills.extension import SkillsExtension
-from fastmcp.skills.models import MCPSkill
+from fastmcp.skills.models import MCPSkill, SkillFrontmatter
from fastmcp.skills.provider import SkillCatalogProvider
REVIEW = Skill(
@@ -40,6 +40,45 @@ async def test_read_skill_returns_an_equal_skill_through_the_extension():
assert skill.files["refs/logo.bin"] == b"\x00\xff\r\n"
+ "advertised",
+ [
+ {"description": "Different instructions"},
+ {"custom": {"enabled": 1}},
+ {"custom": {"enabled": True, "extra": "claim"}},
+ ],
+)
+async def test_read_skill_reconciles_all_advertised_frontmatter(
+ advertised: dict[str, Any],
+):
+ original = Skill(
+ name="review",
+ description="Review changes",
+ instructions="# Review\n",
+ frontmatter={"custom": {"enabled": True}},
+ )
+ requests = 0
+
+ class Inconsistent(SkillCatalogProvider):
+ async def _get_skill_entry(
+ self, uri: str, context: ServerRequestContext[Any, Any]
+ ) -> MCPSkill | None:
+ nonlocal requests
+ requests += 1
+ entry = await super()._get_skill_entry(uri, context)
+ assert entry is not None
+ frontmatter = SkillFrontmatter.model_validate(
+ {**entry.frontmatter.root, **advertised}
+ )
+ return entry.model_copy(update={"frontmatter": frontmatter})
+
+ server = FastMCP("Skills", providers=[Inconsistent([original])])
+ async with skills_client(server) as client:
+ with pytest.raises(ValueError, match="frontmatter"):
+ await client.read_skill("skill://review/SKILL.md")
+ assert requests == 1
+
+
async def test_read_skill_falls_back_to_the_manifest_resource():
server = FastMCP("Skills", providers=[SkillCatalogProvider([REVIEW])])
async with Client(server) as client: