fix(mcp): reject an empty compatibility

The Agent Skills format requires a compatibility value, when present, to
hold 1 to 500 characters, so an empty one is skipped like an overlong one.
This commit is contained in:
Willie
2026-10-06 15:39:06 +08:00
parent 4f7f2d8151
commit 6285e490e6
2 changed files with 4 additions and 3 deletions
+2 -2
View File
@@ -75,8 +75,8 @@ func Load(dir string) (*Package, error) {
// metadata is left unchecked: the format wants string values, but lists there are
// common and tool clients read them fine, so skipping those skills would cost more.
compat, ok := fm["compatibility"].(string)
if _, set := fm["compatibility"]; set && !ok {
return nil, fmt.Errorf("compatibility must be text")
if _, set := fm["compatibility"]; set && (!ok || compat == "") {
return nil, fmt.Errorf("compatibility must be non-empty text")
}
if n := utf8.RuneCountInString(compat); n > MaxCompatibility {
return nil, fmt.Errorf("compatibility has %d characters; the limit is %d", n, MaxCompatibility)
+2 -1
View File
@@ -174,12 +174,13 @@ func TestBuild_SkipsSkillWhoseDescriptionOrCompatibilityIsTooLong(t *testing.T)
writeFile(t, filepath.Join(src, "long/SKILL.md"), skill("long", strings.Repeat("a", 1025)))
writeFile(t, filepath.Join(src, "wide/SKILL.md"), skill("wide", strings.Repeat("技", 1024)))
writeFile(t, filepath.Join(src, "compat/SKILL.md"), "---\nname: compat\ndescription: Use when testing\ncompatibility: "+strings.Repeat("a", 501)+"\n---\n")
writeFile(t, filepath.Join(src, "blank/SKILL.md"), "---\nname: blank\ndescription: Use when testing\ncompatibility: \"\"\n---\n")
c, err := (&Builder{Source: src}).Build()
if err != nil {
t.Fatal(err)
}
if len(c.Skills) != 1 || c.Skills[0].URI != "skill://wide/SKILL.md" || !hasWarning(c, "skipped long") || !hasWarning(c, "skipped compat") {
if len(c.Skills) != 1 || c.Skills[0].URI != "skill://wide/SKILL.md" || !hasWarning(c, "skipped long") || !hasWarning(c, "skipped compat") || !hasWarning(c, "skipped blank") {
t.Errorf("skills=%v warnings=%v, want long and compat skipped, wide served", c.Skills, c.Skipped)
}
}