@mcp-b/agent-skills
v2.0.5
Published
TypeScript parser, validator, prompt, and patch utilities for the AgentSkills specification
Readme
@mcp-b/agent-skills
TypeScript implementation of the AgentSkills specification.
Overview
This package provides parser and validator for Agent Skills, following the official specification at https://agentskills.io/specification.
Agent Skills are folders of instructions, scripts, and resources that agents can discover and use. Skills are defined in SKILL.md files with YAML frontmatter.
References
- Specification: https://agentskills.io/specification
- Reference Implementation: agentskills/skills-ref (Python)
- Example Skills: https://github.com/anthropics/skills
- Reference Repository: https://github.com/agentskills/agentskills/tree/main/skills-ref
Installation
pnpm add @mcp-b/agent-skillsUsage
Parsing SKILL.md
import { parseSkillContent, validateSkillContent } from "@mcp-b/agent-skills"
const content = `---
name: my-skill
description: A test skill
---
# My Skill
Instructions here.`
const { properties, body } = parseSkillContent(content)
const errors = validateSkillContent(content)
if (errors.length > 0) {
console.error("Validation errors:", errors)
}Validation
import { validateSkillProperties } from "@mcp-b/agent-skills"
const properties = {
name: "my-skill",
description: "A test skill"
}
const errors = validateSkillProperties(properties)In-memory file lists (Durable Objects or other non-filesystem hosts)
import {
findSkillMdFile,
readSkillProperties,
validateSkillEntries
} from "@mcp-b/agent-skills"
const files = [
{ name: "SKILL.md", content: skillMarkdown }
]
const entry = findSkillMdFile(files)
const properties = readSkillProperties(files)
const errors = validateSkillEntries(files, { expectedName: properties.name })Prompt generation
import { toPrompt } from "@mcp-b/agent-skills"
const promptBlock = toPrompt([
{ content: skillMarkdown, location: "skills/my-skill/SKILL.md" }
])Diff + patch
import { createSkillPatch, applySkillPatch } from "@mcp-b/agent-skills"
const patch = createSkillPatch(oldContent, newContent)
const result = applySkillPatch(oldContent, patch)
if (!result.ok) {
console.error(result.errors)
} else {
console.log(result.content)
}Library Guide
Parsing
parseFrontmatterparses YAML frontmatter into the spec’s hyphenated keys, trims required fields, and preserves metadata scalars as strings.parseSkillContentreturns both the markdown body and a JS-friendlySkillPropertiesshape.frontmatterToPropertiesconvertsSkillFrontmattertoSkillPropertieswithout re-parsing.extractBodystrips frontmatter and returns the markdown body.findSkillMdFileandreadSkillPropertiesmirror the reference library’s file lookup without assuming a filesystem.
Validation
validateSkillPropertiesenforces the name/description/compatibility rules and optionally checks an expected name.validateSkillContentvalidates a single SKILL.md string, including unknown frontmatter fields.validateSkillEntriesmirrorsskills-ref validatefor in-memory file lists while letting the host surface path and directory state.
Prompt utilities
toPromptbuilds the<available_skills>XML block from parsed entries or raw SKILL.md content.
Diff + patch
diffSkillContentreturns a line-based diff for display or patch construction.createSkillPatchbuilds a contextual patch from two SKILL.md strings.applySkillPatchapplies patch operations and returns structured errors when a patch cannot be applied or yields invalid SKILL.md.validateSkillPatchperforms runtime validation for model-provided patch payloads.
Utilities
normalizeNFKCmatches Python’sunicodedata.normalize("NFKC", ...)for name validation.estimateTokensprovides a conservative heuristic for context budgeting.
Types
SkillFrontmattermatches spec keys (allowed-tools),SkillPropertiesis the camel-cased JS view.SkillFileandSkillMetadataare storage-friendly wrappers used by hosts that persist skills.
Specification Compliance
This package mirrors the Agent Skills specification for content parsing and
validation, and aligns with the Python skills-ref reference behavior.
Directory-level checks (missing paths, non-directories, name-to-location match)
are surfaced through validateSkillEntries so hosts can supply their own storage model.
Required Fields
name(max 64 chars, lowercase, hyphens only)description(max 1024 chars)
Optional Fields
licensecompatibility(max 500 chars)metadata(key-value pairs)allowed-tools(experimental)
Validation Rules
- Name must be lowercase
- Name cannot start/end with hyphen
- Name cannot contain consecutive hyphens
- Unicode normalization (NFKC)
- i18n support (Chinese, Russian, etc.)
Testing
This package follows Test-Driven Development with comprehensive test coverage:
# Run tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Generate coverage report
pnpm test:coverageCoverage goals:
- Line coverage: >95%
- Branch coverage: >90%
- Function coverage: >95%
API Reference
See API.md for full module and function details.
License
MIT
