MCPcopy
hub / github.com/anthropics/skills / parse_skill_md

Function parse_skill_md

skills/skill-creator/scripts/utils.py:7–47  ·  view source on GitHub ↗

Parse a SKILL.md file, returning (name, description, full_content).

(skill_path: Path)

Source from the content-addressed store, hash-verified

5
6
7def parse_skill_md(skill_path: Path) -> tuple[str, str, str]:
8 """Parse a SKILL.md file, returning (name, description, full_content)."""
9 content = (skill_path / "SKILL.md").read_text()
10 lines = content.split("\n")
11
12 if lines[0].strip() != "---":
13 raise ValueError("SKILL.md missing frontmatter (no opening ---)")
14
15 end_idx = None
16 for i, line in enumerate(lines[1:], start=1):
17 if line.strip() == "---":
18 end_idx = i
19 break
20
21 if end_idx is None:
22 raise ValueError("SKILL.md missing frontmatter (no closing ---)")
23
24 name = ""
25 description = ""
26 frontmatter_lines = lines[1:end_idx]
27 i = 0
28 while i < len(frontmatter_lines):
29 line = frontmatter_lines[i]
30 if line.startswith("name:"):
31 name = line[len("name:"):].strip().strip('"').strip("'")
32 elif line.startswith("description:"):
33 value = line[len("description:"):].strip()
34 # Handle YAML multiline indicators (>, |, >-, |-)
35 if value in (">", "|", ">-", "|-"):
36 continuation_lines: list[str] = []
37 i += 1
38 while i < len(frontmatter_lines) and (frontmatter_lines[i].startswith(" ") or frontmatter_lines[i].startswith("\t")):
39 continuation_lines.append(frontmatter_lines[i].strip())
40 i += 1
41 description = " ".join(continuation_lines)
42 continue
43 else:
44 description = value.strip('"').strip("'")
45 i += 1
46
47 return name, description, content

Callers 4

run_loopFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected