Documentation
¶
Overview ¶
Package skills implements the server half of the MCP Skills extension: https://github.com/modelcontextprotocol/ext-skills/blob/main/specification/beta/skills.mdx.
Skills are directories of ordinary resources, entered through a SKILL.md. Registry holds validated files and manifests; Publisher serves skills/list, skills/get, resources/read and optional directory reads using the MCP SDK. The bundled GitHub workflow catalog lives in the catalog subpackage.
Index ¶
- Constants
- Variables
- func Digest(content []byte) string
- func FileMIMEType(filePath string, content []byte) string
- func FrontmatterEqual(a, b Frontmatter) bool
- func IsText(content []byte) bool
- func NegotiatedProtocolVersion(ctx context.Context, params mcp.Params, ss *mcp.ServerSession) string
- func SkillURI(skillPath, filePath string) string
- func SupportsRequestScopedContext(version string) bool
- func ValidateDigest(digest string) error
- func ValidateName(name string) error
- func Verify(content []byte, want EntryResource) error
- func WithinSkill(skillPath, uri string) bool
- type Child
- type ContentSource
- type DirectorySource
- type Entry
- type EntryResource
- type File
- type Frontmatter
- type GetSkillParams
- type GetSkillResult
- type ListSkillsParams
- type ListSkillsResult
- type Publisher
- type ReadDirectoryParams
- type ReadDirectoryResult
- type Registry
- func (r *Registry) Files(context.Context) ([]ResourceFile, error)
- func (r *Registry) ForTools(available func(string) bool) (*Registry, error)
- func (r *Registry) Get(_ context.Context, uri string) (Entry, bool, error)
- func (r *Registry) Len() int
- func (r *Registry) List(context.Context) ([]Entry, error)
- func (r *Registry) ReadDirectory(_ context.Context, uri string) ([]Child, bool, error)
- func (r *Registry) Retaining(keep func(*Skill) bool) (*Registry, error)
- func (r *Registry) Skill(skillPath string) (*Skill, bool)
- func (r *Registry) WithSkills(additional ...*Skill) (*Registry, error)
- type ResourceFile
- type Skill
- type Source
- type URI
Constants ¶
const ( MethodListSkills = "skills/list" MethodGetSkill = "skills/get" MethodReadDirectory = "resources/directory/read" )
Method names defined by the extension.
const ( // ExtensionID is the capability extension identifier. ExtensionID = "io.modelcontextprotocol/skills" // SettingDirectoryRead advertises resources/directory/read support. SettingDirectoryRead = "directoryRead" // URIScheme is the scheme used for skill resources. URIScheme = "skill" // SkillFile is the required entry file of every skill. SkillFile = "SKILL.md" // DirectoryMIMEType identifies directories in resource listings. DirectoryMIMEType = "inode/directory" // SkillMIMEType is the media type of SKILL.md. SkillMIMEType = "text/markdown" // MetaPrefix is reserved for extension-defined resource metadata. MetaPrefix = "io.modelcontextprotocol.skills/" // ReservedMetadataPrefix is reserved within frontmatter metadata. ReservedMetadataPrefix = "io.modelcontextprotocol/" // MaxResourcesPerSkill includes SKILL.md and every supporting file. MaxResourcesPerSkill = 512 // MaxSkillBytes is the sum of all raw file sizes in a skill. MaxSkillBytes int64 = 16 * 1024 * 1024 )
const DefaultPageSize = 50
DefaultPageSize is the number of entries a page carries when the caller does not choose otherwise.
const DigestPrefix = "sha256:"
DigestPrefix is the algorithm prefix of every digest this extension defines.
const DynamicResources = "dynamic"
DynamicResources is the literal value a skill entry carries in place of a resource array when its content is generated and stable digests cannot be published. The marker is explicit so a host can distinguish a deliberately unverifiable skill from a malformed entry.
const ListTTL = 60_000
ListTTL is the freshness hint published with a skills listing, in milliseconds. It says only how long a listing may be reused before re-fetching; it makes no claim about content, which digest verification governs regardless.
const MaxNameLength = 64
MaxNameLength is the Agent Skills limit on a skill name.
const ProtocolVersionRequestScoped = "2026-07-28"
ProtocolVersionRequestScoped is the first protocol version whose requests carry their own negotiated context, and the version from which the extension's results carry list-caching attributes.
const ResultTypeComplete = "complete"
ResultTypeComplete marks a custom-method result as whole rather than a fragment of a multi-part response. It is emitted only for protocol versions that define it.
Variables ¶
var ErrInvalidCursor = errors.New("invalid pagination cursor")
ErrInvalidCursor reports a cursor that this server did not issue, or issued under an encoding it no longer accepts.
var ErrMissingResources = errors.New("skill entry resources must be an array or the string \"dynamic\"")
ErrMissingResources reports an entry whose resources field is absent or is neither an array nor the literal "dynamic". Such an entry is invalid and a host must not load it.
Functions ¶
func Digest ¶
Digest computes the digest of a file's raw bytes in the extension's format, sha256:{hex} with 64 lowercase hexadecimal characters.
func FileMIMEType ¶
FileMIMEType infers a media type from a file's extension, falling back to a text or binary default based on the content itself.
func FrontmatterEqual ¶
func FrontmatterEqual(a, b Frontmatter) bool
FrontmatterEqual reports whether two frontmatter objects are identical in content. Hosts perform this comparison after fetching a SKILL.md; servers use it to catch a listing that has drifted from the file it describes.
func IsText ¶
IsText reports whether content can be served as text: valid UTF-8 with no NUL bytes. Resource contents that are not text must be sent base64-encoded.
func NegotiatedProtocolVersion ¶
func NegotiatedProtocolVersion(ctx context.Context, params mcp.Params, ss *mcp.ServerSession) string
NegotiatedProtocolVersion resolves the protocol version in force for a single request.
Resolution is request-scoped and never inferred from cached session state. The context is consulted first, because a stateless HTTP server establishes per-request values there and its session carries none. Failing that, the request's own _meta is consulted, which is where a 2026-07-28 client puts the negotiated version. Only then does the session's initialize params apply, which is how a stdio client that negotiated once and stays connected is answered.
The empty string means the version is unknown, which is treated throughout as "older than 2026-07-28" — the conservative reading, since an older client must not be sent fields its protocol version does not define.
func SkillURI ¶
SkillURI builds the URI of a file within a skill. An empty filePath yields the skill root.
func SupportsRequestScopedContext ¶
SupportsRequestScopedContext reports whether a protocol version is 2026-07-28 or later. MCP versions are ISO dates, so lexical ordering is chronological.
func ValidateDigest ¶
ValidateDigest checks that a digest string is well formed.
func ValidateName ¶
ValidateName reports whether a skill name satisfies the Agent Skills naming rules. The final segment of a skill path must equal the skill's frontmatter name, so both are checked against this.
func Verify ¶
func Verify(content []byte, want EntryResource) error
Verify checks retrieved content against the size and digest an entry published for it.
The size check is not an optimization: a read whose byte length differs from the entry's size is a verification failure equivalent to a digest mismatch, so it is reported as one whether or not the digest is then computed.
A digest match proves only that listing and content are consistent. It is not a security boundary: both are supplied by the same server, and any intermediary can rewrite them together.
func WithinSkill ¶
WithinSkill reports whether uri addresses the skill rooted at skillPath — either its SKILL.md or a file within its directory. It is the check behind the origin-scoping rule that a skill's resources may only name that skill's own files.
Types ¶
type Child ¶
type Child struct {
// URI is the child's resource URI, written without a trailing slash for
// directories.
URI string
// Name is the child's final path segment.
Name string
// Description is optional resource metadata.
Description string
// MIMEType is DirectoryMIMEType for a subdirectory, or the file's media
// type otherwise.
MIMEType string
// Size is the file's raw byte length, and zero for a directory.
Size int64
}
Child is one entry of a directory listing: either a file or a subdirectory.
type ContentSource ¶
type ContentSource interface {
Source
// Files returns every file the source serves, as resource descriptors
// paired with their content, in a stable order.
Files(ctx context.Context) ([]ResourceFile, error)
}
ContentSource is implemented by a Source that holds file content and can therefore have its files registered as ordinary MCP resources.
type DirectorySource ¶
type DirectorySource interface {
Source
// ReadDirectory returns the direct children of a directory URI, in a
// stable order. It reports false when the URI does not exist or exists but
// is not a directory; both cases are invalid params to the caller. An
// existing but empty directory returns an empty slice and true.
ReadDirectory(ctx context.Context, uri string) ([]Child, bool, error)
}
DirectorySource is implemented by a Source that can enumerate the children of a directory in its namespace. A server declares directoryRead only when its source implements this, so that the capability reflects a genuine implementation rather than an aspiration.
type Entry ¶
type Entry struct {
// URI is the resource URI of the skill's SKILL.md.
URI string `json:"uri"`
// Frontmatter is a verbatim JSON rendering of that file's YAML frontmatter.
Frontmatter Frontmatter `json:"frontmatter"`
// Resources enumerates every file of the skill, each exactly once,
// including one entry matching URI. It is nil when Dynamic is set.
Resources []EntryResource `json:"-"`
// Dynamic marks a skill whose content is generated, so that no stable
// digests can be published. It is mutually exclusive with Resources.
Dynamic bool `json:"-"`
}
Entry is a skill's published record: the URI of its SKILL.md, the verbatim frontmatter of that file, and its resource manifest. It is the unit returned by both skills/list and skills/get, identical in shape and meaning in each.
func (Entry) MarshalJSON ¶
MarshalJSON renders resources as either the manifest array or the literal "dynamic". It never omits the field: an entry with no resources is invalid.
func (Entry) TotalSize ¶
TotalSize sums the manifest's sizes. It is meaningless for a dynamic entry, which offers nothing to count.
func (*Entry) UnmarshalJSON ¶
UnmarshalJSON parses the resources union, rejecting anything that is neither an array nor the literal "dynamic".
type EntryResource ¶
type EntryResource struct {
URI string `json:"uri"`
Digest string `json:"digest"`
Size int64 `json:"size"`
}
EntryResource is one file of a skill: its URI, the digest of its raw bytes, and that byte length. Together these let a host budget a skill before fetching anything and detect a truncated or padded read before hashing it.
func (EntryResource) Validate ¶
func (r EntryResource) Validate() error
Validate checks a single manifest entry.
type File ¶
type File struct {
// Path is the file's path relative to the skill directory root, using "/"
// as the separator.
Path string
// Content is the file's raw bytes.
Content []byte
// MIMEType overrides the type inferred from the file extension. Leave it
// empty to infer.
MIMEType string
}
File is one file of a skill, held as the raw bytes the digest covers.
type Frontmatter ¶
Frontmatter is a SKILL.md's YAML frontmatter rendered as a JSON object.
It is verbatim: every field the author wrote is preserved, not a curated subset, because a host builds its registry from the listing alone and later re-parses the fetched SKILL.md and compares it field-by-field against this. Dropping or rewriting a field here would make that comparison fail.
func ParseFrontmatter ¶
func ParseFrontmatter(content []byte) (Frontmatter, string, error)
ParseFrontmatter extracts the YAML frontmatter from SKILL.md content and returns it as a JSON-shaped object along with the markdown body that follows.
Content is normalized for CRLF so that a checkout with Windows line endings parses identically; the digest, by contrast, always covers the raw bytes as served.
func (Frontmatter) Description ¶
func (f Frontmatter) Description() string
Description returns the frontmatter description field, which the Agent Skills specification requires.
func (Frontmatter) Name ¶
func (f Frontmatter) Name() string
Name returns the frontmatter name field, which the Agent Skills specification requires.
func (Frontmatter) Validate ¶
func (f Frontmatter) Validate() error
Validate checks the fields the Agent Skills specification requires of every SKILL.md.
type GetSkillParams ¶
type GetSkillParams struct {
mcp.ParamsBase
// URI is the resource URI of a skill's SKILL.md.
URI string `json:"uri"`
}
GetSkillParams are the parameters of skills/get.
type GetSkillResult ¶
type GetSkillResult struct {
mcp.ResultBase
ResultType string `json:"resultType,omitempty"`
Skill Entry `json:"skill"`
TTLMs *int `json:"ttlMs,omitempty"`
CacheScope string `json:"cacheScope,omitempty"`
}
GetSkillResult is the result of skills/get. It carries no pagination cursor: a single entry is not a list.
type ListSkillsParams ¶
type ListSkillsParams struct {
mcp.ParamsBase
// Cursor is an opaque pagination cursor from a previous result's
// nextCursor.
Cursor string `json:"cursor,omitempty"`
}
ListSkillsParams are the parameters of skills/list.
type ListSkillsResult ¶
type ListSkillsResult struct {
mcp.ResultBase
// ResultType marks the result complete. It is omitted for protocol
// versions that predate the attribute.
ResultType string `json:"resultType,omitempty"`
Skills []Entry `json:"skills"`
// NextCursor is present only when further pages remain.
NextCursor string `json:"nextCursor,omitempty"`
// TTLMs and CacheScope are the base protocol's list-caching attributes,
// carried from protocol version 2026-07-28 and omitted before it. They are
// a freshness hint for the listing, not an integrity property: content is
// governed by digest verification however fresh a cached listing is.
TTLMs *int `json:"ttlMs,omitempty"`
CacheScope string `json:"cacheScope,omitempty"`
}
ListSkillsResult is the result of skills/list.
Skills is always rendered, as an empty array when the server publishes nothing. An empty listing is a valid answer and is not proof that the server has no skills: a large, generated, or otherwise unenumerable catalog may decline to enumerate itself while still answering skills/get for every skill it serves.
type Publisher ¶
type Publisher struct {
// PageSize bounds how many entries one page of skills/list carries. Pages
// are sliced by whole entries, so a skill's resource manifest is never
// split across pages.
PageSize int
// contains filtered or unexported fields
}
Publisher serves the skills extension for one Source. A source must also implement ContentSource for Install to register the files its entries name.
Declaring the extension commits a server to both skills/list and skills/get, so DeclareCapability and Install belong together: declare the capability on the options used to build the server, then install the methods on the server itself.
func NewPublisher ¶
NewPublisher returns a publisher for a source.
func (*Publisher) DeclareCapability ¶
func (p *Publisher) DeclareCapability(caps *mcp.ServerCapabilities)
DeclareCapability adds the extension to a server's declared capabilities.
The settings object carries directoryRead only when the source implements it; an empty object declares the extension with no optional features, which is the correct declaration for a source that serves skills but cannot enumerate directories.
func (*Publisher) Install ¶
Install registers the extension's methods on a server.
skills/list and skills/get are always registered, because declaring the extension commits the server to both. resources/directory/read is registered only when the source implements DirectorySource, matching what DeclareCapability advertised. Installation requires a ContentSource and validates every listed manifest against its files before registering methods.
func (*Publisher) SupportsDirectoryRead ¶
SupportsDirectoryRead reports whether the source can genuinely enumerate directories. The capability is declared only when it can, because a client that sees directoryRead: true is entitled to call the method for every directory in the namespaces the server serves.
type ReadDirectoryParams ¶
type ReadDirectoryParams struct {
mcp.ParamsBase
// URI is the directory resource URI, written without a trailing slash.
URI string `json:"uri"`
// Cursor is an opaque pagination cursor from a previous result's
// nextCursor.
Cursor string `json:"cursor,omitempty"`
}
ReadDirectoryParams are the parameters of resources/directory/read.
type ReadDirectoryResult ¶
type ReadDirectoryResult struct {
mcp.ResultBase
ResultType string `json:"resultType,omitempty"`
Resources []*mcp.Resource `json:"resources"`
NextCursor string `json:"nextCursor,omitempty"`
TTLMs *int `json:"ttlMs,omitempty"`
CacheScope string `json:"cacheScope,omitempty"`
}
ReadDirectoryResult is the result of resources/directory/read. It carries the direct children of one directory; the listing is not recursive, and clients descend by calling the method again on a child directory.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is an in-memory Source holding a fixed set of validated skills. It implements DirectorySource and ContentSource, so a server built on it serves the whole extension.
A Registry is immutable once built and is safe for concurrent use.
func NewRegistry ¶
NewRegistry builds a registry from already-validated skills.
Two skills may share a name — names are labels, not identifiers — but two skills may not share a path, because the path is what identifies a skill within a server.
Skills may nest. From an enclosing skill's perspective a nested skill's files are ordinary supporting files, so the same URI is legitimately claimed by both skills; the registry serves it once. Conflicting content and incomplete static enclosing manifests are rejected.
func (*Registry) Files ¶
func (r *Registry) Files(context.Context) ([]ResourceFile, error)
Files returns every file the registry serves, ordered by URI.
func (*Registry) ForTools ¶
ForTools returns a catalog whose core workflows can run with available tools. Filtering rebuilds every index, so list/get, directories and file reads share the same exposure rules without changing the original registry.
func (*Registry) List ¶
List returns every entry, ordered by skill path so that pagination is reproducible.
func (*Registry) ReadDirectory ¶
ReadDirectory returns the direct children of a directory in the registry.
func (*Registry) Retaining ¶
Retaining returns a registry holding only the skills keep accepts.
A skill is guidance for driving a particular set of tools, so a server that registers none of them is in no position to offer it: the skill would occupy the menu a model chooses from, describe a workflow the model cannot begin, and be discovered as a dead end only after it was selected. Publishing less than the whole catalog is the honest response to a narrower configuration, not a degradation of it.
The receiver is left untouched, so a process-wide catalog can be filtered per request without the requests interfering. Ordering, digests and file contents are those of the retained skills, so anything published here still matches what a client fetches.
type ResourceFile ¶
type ResourceFile struct {
// URI is the file's resource URI.
URI string
// SkillPath is the path of the skill the file belongs to.
SkillPath string
// File is the file itself.
File File
// Name and Description carry the resource metadata for the file. For a
// SKILL.md these come from the skill's frontmatter.
Name string
Description string
}
ResourceFile pairs a skill file with the URI it is served at.
type Skill ¶
type Skill struct {
// SkillPath locates the skill within the server's namespace. Its final
// segment equals the frontmatter name.
SkillPath string
// Frontmatter is the verbatim frontmatter of the skill's SKILL.md.
Frontmatter Frontmatter
// Dynamic marks a skill whose content is generated, so that it publishes
// no digests. Its files are still served, but its entry carries the
// "dynamic" marker rather than a manifest.
Dynamic bool
// RequiredTools is server-only availability information, never frontmatter
// or wire metadata. Every group must have at least one available tool;
// alternatives accommodate consolidated and granular tool surfaces.
RequiredTools [][]string
// OptionalTools documents supporting tools whose absence does not prevent
// the core workflow. It is never published as metadata or a permission grant.
OptionalTools []string
// contains filtered or unexported fields
}
Skill is a complete skill held in memory: its location in the server's namespace, its parsed frontmatter, and its files.
Construct one with NewSkill, which enforces the extension's structural rules and per-skill limits. A Skill obtained any other way has not been validated.
func NewSkill ¶
NewSkill builds a skill from its path and files.
The files must include a SKILL.md at the skill root; its frontmatter is parsed and its name is required to equal the final segment of skillPath. The per-skill limits are enforced here, so a registry never serves an entry a conforming host would refuse.
func (*Skill) Description ¶
Description returns the skill's frontmatter description.
func (*Skill) Entry ¶
Entry renders the skill's published record. A dynamic skill carries the "dynamic" marker in place of a manifest; every other skill carries a complete one, listing every file exactly once including its own SKILL.md.
func (*Skill) Name ¶
Name returns the skill's name: its frontmatter name, which by construction equals the final segment of its path.
type Source ¶
type Source interface {
// List returns the entries the server publishes, in a stable order. The
// order must not change between paginated calls, or an atomic page
// boundary would not be reproducible.
List(ctx context.Context) ([]Entry, error)
// Get returns the entry for the skill whose SKILL.md is at uri. The
// boolean reports whether the server serves that skill at all; an unknown
// URI is reported as not found rather than as an error.
Get(ctx context.Context, uri string) (Entry, bool, error)
}
Source supplies the skills a server publishes.
A listing may be empty or partial — a server with a large, generated, or otherwise unenumerable catalog is not required to enumerate it — but a source MUST still answer Get for every skill it serves, including skills that never appear in a listing. Every listed skill's resources must be supplied by a ContentSource; Publisher.Install validates the listed manifests against those files before registering the extension.
type URI ¶
type URI struct {
// Scheme is the URI scheme, always URIScheme for URIs this package mints.
Scheme string
// SkillPath locates the skill directory within the server's namespace, as
// a "/"-separated path of one or more segments. Its final segment is the
// skill name; any preceding segments are a server-chosen organizational
// prefix.
SkillPath string
// FilePath is the file's path relative to the skill directory root. It is
// empty for the skill root URI.
FilePath string
}
URI is a parsed skill:// resource URI. The zero value is not meaningful; use ParseURI.
func ParseURI ¶
ParseURI parses a skill:// URI into its skill path and file path. It does not validate that the referenced skill exists.
A URI naming only the skill path — no file path — parses as the skill root. Callers that require a file, such as the SKILL.md URI in a skills/get request, must check FilePath themselves.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package catalog holds the skills this server bundles: portable, host-agnostic guidance for GitHub workflows that the MCP tools in this repository support.
|
Package catalog holds the skills this server bundles: portable, host-agnostic guidance for GitHub workflows that the MCP tools in this repository support. |