Skip to main content
agent-skills-ts-sdk is a TypeScript implementation of the AgentSkills specification. It parses SKILL.md files, validates frontmatter, generates prompt blocks, and applies patches. This package sits adjacent to the core WebMCP runtime and does not depend on it.
npm: agent-skills-ts-sdk
license: MIT
node: >= 22.12
dependencies: yaml

Installation

npm install agent-skills-ts-sdk

Minimal example

Parsing

parseSkillContent(content, options?)

Parses a SKILL.md string into frontmatter properties and a markdown body.
import { parseSkillContent } from 'agent-skills-ts-sdk';

const { properties, body } = parseSkillContent(`---
name: my-skill
description: A test skill
---
# My Skill

Instructions here.`);
For content extracted from a DOM <script> element (which may have a leading newline), use embedded mode:
const { properties, body } = parseSkillContent(contentFromDom, {
  inputMode: 'embedded',
});

parseFrontmatter(content, options?)

Parses YAML frontmatter into the spec’s hyphenated keys. Trims required fields and preserves metadata scalars as strings.

frontmatterToProperties(frontmatter)

Converts a SkillFrontmatter object to a camelCased SkillProperties shape without re-parsing.

extractBody(content)

Strips frontmatter and returns the markdown body.

findSkillMdFile(files)

Finds the SKILL.md entry in an in-memory file list. Does not assume a filesystem.
import { findSkillMdFile, readSkillProperties } from 'agent-skills-ts-sdk';

const files = [{ name: 'SKILL.md', content: skillMarkdown }];
const entry = findSkillMdFile(files);
const properties = readSkillProperties(files);

readSkillProperties(files, options?)

Reads and parses skill properties from an in-memory file list. Extracts resource links from the markdown body.

Validation

validateSkillContent(content)

Validates a single SKILL.md string. Checks frontmatter fields, unknown fields, and structural rules.
import { validateSkillContent } from 'agent-skills-ts-sdk';

const errors = validateSkillContent(content);
if (errors.length > 0) {
  console.error('Validation errors:', errors);
}

validateSkillProperties(properties, options?)

Validates a SkillProperties object against name/description/compatibility rules.
import { validateSkillProperties } from 'agent-skills-ts-sdk';

const errors = validateSkillProperties({
  name: 'my-skill',
  description: 'A test skill',
});

validateSkillEntries(files, options?)

Mirrors the reference library’s skills-ref validate for in-memory file lists. Hosts supply their own storage model.

Validation rules

RuleConstraint
nameRequired. Max 64 characters. Lowercase only. Hyphens allowed (not at start/end, no consecutive). Unicode normalized (NFKC).
descriptionRequired. Max 1024 characters.
compatibilityOptional. Max 500 characters.
licenseOptional.
metadataOptional. Key-value pairs.
allowed-toolsOptional. Experimental.

Validation constants

ConstantValue
MAX_SKILL_NAME_LENGTH64
MAX_DESCRIPTION_LENGTH1024
MAX_COMPATIBILITY_LENGTH500
ALLOWED_FIELDSSet of valid frontmatter field names

Prompt utilities

toPrompt(entries)

Builds an <available_skills> XML block from parsed entries or raw SKILL.md content.
import { toPrompt } from 'agent-skills-ts-sdk';

const promptBlock = toPrompt([
  { content: skillMarkdown, location: 'skills/my-skill/SKILL.md' },
]);

toDisclosurePrompt(entries)

Generates a disclosure prompt, optionally including resource names for tier-3 hints.
import { toDisclosurePrompt } from 'agent-skills-ts-sdk';

const xml = toDisclosurePrompt([
  { name: 'pizza-maker', description: 'Interactive pizza builder', resources: ['build-pizza'] },
]);

toDisclosureInstructions(options)

Generates canonical read-protocol instruction text.
import { toDisclosureInstructions } from 'agent-skills-ts-sdk';

const instructions = toDisclosureInstructions({ toolName: 'read_site_context' });

toReadToolSchema(skills, options?)

Builds a strict JSON Schema declaration for a read tool.
import { toReadToolSchema } from 'agent-skills-ts-sdk';

const schema = toReadToolSchema(
  [{ name: 'pizza-maker' }],
  { toolName: 'read_site_context' }
);

handleSkillRead(args)

Handles 2-level read requests in memory (overview vs. specific resource).

Diff and patch

createSkillPatch(oldContent, newContent, options?)

Builds a contextual patch from two SKILL.md strings.
import { createSkillPatch, applySkillPatch } from 'agent-skills-ts-sdk';

const patch = createSkillPatch(oldContent, newContent);
const result = applySkillPatch(oldContent, patch);

if (!result.ok) {
  console.error(result.errors);
} else {
  console.log(result.content);
}

applySkillPatch(content, patch, options?)

Applies patch operations and returns structured errors when a patch cannot be applied or yields invalid SKILL.md.

diffSkillContent(oldContent, newContent)

Returns a line-based diff for display or patch construction.

validateSkillPatch(patch)

Runtime validation for model-provided patch payloads.

Utilities

FunctionDescription
normalizeNFKC(str)Matches Python’s unicodedata.normalize("NFKC", ...) for name validation
estimateTokens(text)Conservative heuristic for context budgeting

Types

Core types

TypeDescription
SkillPropertiesCamelCased JS view of skill frontmatter
SkillFrontmatterSpec-key (allowed-tools) frontmatter shape
SkillParseResultResult of parseSkillContent: { properties, body }
SkillFrontmatterParseResultResult of parseFrontmatter
SkillContentRaw skill content string
SkillBodyMarkdown body after frontmatter removal
SkillIdBranded string for skill identifiers

Storage types

TypeDescription
SkillFile{ name: string, content: string } for in-memory file lists
SkillMetadataStorage-friendly wrapper for persisted skills
SkillMetadataMapMap of skill ID to metadata
SkillContentEntryEntry for prompt generation
ResolvedSkillFully resolved skill with properties, body, and metadata
SkillResourceA skill resource reference

Prompt types

TypeDescription
SkillPromptEntryEntry passed to toPrompt
SkillPromptSourceSource location for a skill
DisclosurePromptEntryEntry passed to toDisclosurePrompt
DisclosureInstructionOptionsOptions for toDisclosureInstructions

Patch types

TypeDescription
SkillPatchA patch object with operations
SkillPatchOperationA single add/remove/replace operation
SkillPatchOperationType'add' | 'remove' | 'replace'
SkillPatchApplyResultResult with ok, content, and errors
SkillPatchValidationResultValidation result for model-provided patches
SkillPatchIssueA specific issue found during patch validation
SkillPatchIssueCodeError code enum for patch issues
SkillDiffSegmentA segment in a line-based diff
SkillLineDiffFull line-based diff result

Read tool types

TypeDescription
ReadToolSchemaJSON Schema for a read tool
ReadToolSchemaOptionsOptions for toReadToolSchema
SkillReadArgsArguments for handleSkillRead
SkillReadResultSuccessful read result
SkillReadErrorError from a read operation
SkillReadErrorCodeError code enum

Error classes

ClassDescription
ParseErrorThrown when parsing fails
ValidationErrorThrown when validation fails

Specification compliance

This package mirrors the AgentSkills specification for content parsing and validation. It aligns with the Python skills-ref reference implementation. Directory-level checks are surfaced through validateSkillEntries so hosts can supply their own storage model.