Documentation
¶
Overview ¶
Package skills implements the Beta specification for the MCP Skills extension.
Servers opt in with AddHandlers and serve skill files through the ordinary MCP resource APIs. Clients register AddMethods before connecting, then use ListPage, List, and Get to discover entries. VerifySkillMD and VerifyResource check content retrieved on demand against an entry from the same server.
Index ¶
- Constants
- Variables
- func Add(server *mcp.Server, entries []*Skill, options *ServerOptions) error
- func AddHandlers(server *mcp.Server, handlers *Handlers, options *ServerOptions) error
- func AddMethods(client *mcp.Client) error
- func DirectoryEntries(ctx context.Context, session *mcp.ClientSession, params *ReadDirectoryParams) iter.Seq2[*mcp.Resource, error]
- func List(ctx context.Context, session *mcp.ClientSession, params *ListSkillsParams, ...) iter.Seq2[*Skill, error]
- func PaginateDirectoryResources(resources []*mcp.Resource, cursor string, pageSize int) ([]*mcp.Resource, string, error)
- func VerifyResource(skill *Skill, uri string, content []byte) error
- func VerifySkillMD(skill *Skill, content []byte) error
- type Frontmatter
- type GetSkillHandler
- type GetSkillParams
- type GetSkillRequest
- type GetSkillResult
- type Handlers
- type InvalidSkill
- type Limits
- type ListOptions
- type ListSkillsHandler
- type ListSkillsParams
- type ListSkillsRequest
- type ListSkillsResult
- type ReadDirectoryHandler
- type ReadDirectoryParams
- type ReadDirectoryRequest
- type ReadDirectoryResult
- type Resource
- type Resources
- type ServerOptions
- type Skill
Examples ¶
Constants ¶
const ( // ExtensionID is the capability identifier for the Skills extension. ExtensionID = "io.modelcontextprotocol/skills" // MethodList is the skills/list method name. MethodList = "skills/list" // MethodGet is the skills/get method name. MethodGet = "skills/get" // MethodReadDirectory is the resources/directory/read method name. MethodReadDirectory = "resources/directory/read" )
Variables ¶
var ErrDynamicResources = errors.New("skills: dynamic resources cannot be integrity-verified")
ErrDynamicResources reports that content cannot be integrity-verified because the skill declares dynamic resources.
Functions ¶
func Add ¶
func Add(server *mcp.Server, entries []*Skill, options *ServerOptions) error
Add serves a static catalog with URI-based lookup and pagination. Pass the complete catalog in one call; subsequent registrations replace its handlers. Entries and their manifests must remain immutable while the server serves them.
Example ¶
package main
import (
"context"
"crypto/sha256"
"fmt"
"log"
"github.com/modelcontextprotocol/go-sdk/extensions/skills"
"github.com/modelcontextprotocol/go-sdk/mcp"
)
func main() {
// !+skillsserver
caps := &mcp.ServerCapabilities{}
caps.AddExtension(skills.ExtensionID, nil)
server := mcp.NewServer(&mcp.Implementation{Name: "skills", Version: "v1.0.0"}, &mcp.ServerOptions{Capabilities: caps})
const uri = "skill://greeting/SKILL.md"
const content = "---\nname: greeting\ndescription: Greet the user.\n---\n# Greeting\nSay hello to the user.\n"
entry := &skills.Skill{
URI: uri,
Frontmatter: skills.Frontmatter{
"name": "greeting", "description": "Greet the user.",
},
Resources: skills.StaticResources(&skills.Resource{
URI: uri, Digest: fmt.Sprintf("sha256:%x", sha256.Sum256([]byte(content))), Size: int64(len(content)),
}),
}
server.AddResource(&mcp.Resource{
URI: uri, Name: "greeting", Description: "Greet the user.", MIMEType: "text/markdown",
}, func(context.Context, *mcp.ReadResourceRequest) (*mcp.ReadResourceResult, error) {
return &mcp.ReadResourceResult{Contents: []*mcp.ResourceContents{{
URI: uri, MIMEType: "text/markdown", Text: content,
}}}, nil
})
err := skills.Add(server, []*skills.Skill{entry}, nil)
if err != nil {
log.Fatal(err)
}
// !-skillsserver
// !+skillsclient
ctx := context.Background()
client := mcp.NewClient(&mcp.Implementation{Name: "skills-client", Version: "v1.0.0"}, nil)
if err := skills.AddMethods(client); err != nil {
log.Fatal(err)
}
serverTransport, clientTransport := mcp.NewInMemoryTransports()
serverSession, err := server.Connect(ctx, serverTransport, nil)
if err != nil {
log.Fatal(err)
}
defer serverSession.Close()
session, err := client.Connect(ctx, clientTransport, nil)
if err != nil {
log.Fatal(err)
}
defer session.Close()
for skill, err := range skills.List(ctx, session, nil, nil) {
if err != nil {
log.Fatal(err)
}
fmt.Println(skill.URI, skill.Frontmatter.Description())
}
// !-skillsclient
// !+skillsverify
result, err := skills.Get(ctx, session, &skills.GetSkillParams{URI: "skill://greeting/SKILL.md"})
if err != nil {
log.Fatal(err)
}
resource, err := session.ReadResource(ctx, &mcp.ReadResourceParams{URI: result.Skill.URI})
if err != nil {
log.Fatal(err)
}
if len(resource.Contents) != 1 || resource.Contents[0] == nil || resource.Contents[0].URI != result.Skill.URI || resource.Contents[0].Blob != nil {
log.Fatal("expected one text resource for SKILL.md")
}
if err := skills.VerifySkillMD(result.Skill, []byte(resource.Contents[0].Text)); err != nil {
log.Fatal(err)
}
fmt.Println("verified", result.Skill.URI)
// !-skillsverify
}
Output: skill://greeting/SKILL.md Greet the user. verified skill://greeting/SKILL.md
func AddHandlers ¶
func AddHandlers(server *mcp.Server, handlers *Handlers, options *ServerOptions) error
AddHandlers registers the Skills extension. Register skill content separately with mcp.Server.AddResource or mcp.Server.AddResourceTemplate before connecting. Advertise ExtensionID in the server options. Resource registrations advertise the required resources capability. Configure the server before connecting.
If options is nil, no manifest caps apply. Handlers own pagination; use PaginateDirectoryResources to paginate in-memory slices. AddHandlers supplies resultType and default cache hints for the request's protocol version. See ListSkillsResult and GetSkillResult.
Options and handler functions are copied. Results are validated without modifying handler-owned values; handlers must synchronize their own state.
func AddMethods ¶
AddMethods registers the Skills requests on a client before it connects.
func DirectoryEntries ¶
func DirectoryEntries(ctx context.Context, session *mcp.ClientSession, params *ReadDirectoryParams) iter.Seq2[*mcp.Resource, error]
DirectoryEntries returns an iterator over a directory read, starting at params.Cursor. Each page is validated as in ReadDirectory. The iterator stops after yielding its first error.
func List ¶
func List(ctx context.Context, session *mcp.ClientSession, params *ListSkillsParams, options *ListOptions) iter.Seq2[*Skill, error]
List returns an iterator over skills/list, starting at params.Cursor. A nil params starts at the first page. Each page is validated as in ListPage. The session, options, and parameters are captured when List is called. The iterator stops after yielding its first error.
func PaginateDirectoryResources ¶
func PaginateDirectoryResources(resources []*mcp.Resource, cursor string, pageSize int) ([]*mcp.Resource, string, error)
PaginateDirectoryResources returns one URI-ordered directory page without modifying resources. A zero page size uses mcp.DefaultPageSize.
func VerifyResource ¶
VerifyResource checks membership, size, and digest against the held skill entry. It returns ErrDynamicResources for a dynamic manifest. It checks the entry's structure without reapplying size limits configured during discovery.
func VerifySkillMD ¶
VerifySkillMD verifies SKILL.md with VerifyResource and compares every frontmatter field with the held entry. For a dynamic manifest it still checks frontmatter, returning ErrDynamicResources only if the frontmatter matches.
Types ¶
type Frontmatter ¶
Frontmatter is all of a SKILL.md's YAML frontmatter represented as JSON-compatible values. JSON numbers are decoded as json.Number to preserve their precision.
func (Frontmatter) Description ¶
func (f Frontmatter) Description() string
Description returns the skill description from frontmatter.
func (Frontmatter) Name ¶
func (f Frontmatter) Name() string
Name returns the skill name from frontmatter.
func (*Frontmatter) UnmarshalJSON ¶
func (f *Frontmatter) UnmarshalJSON(data []byte) error
type GetSkillHandler ¶
type GetSkillHandler func(context.Context, *GetSkillRequest) (*GetSkillResult, error)
GetSkillHandler handles skills/get. Return (nil, nil) for an unknown skill; AddHandlers translates it to JSON-RPC Invalid Params. Explicit JSON-RPC errors are preserved; other errors become Internal Error.
type GetSkillParams ¶
type GetSkillParams struct {
mcp.ParamsBase
URI string `json:"uri"`
}
GetSkillParams contains parameters for skills/get.
type GetSkillRequest ¶
type GetSkillRequest = mcp.ServerRequest[*GetSkillParams]
Request types for Skills server handlers.
type GetSkillResult ¶
type GetSkillResult struct {
mcp.ResultBase
mcp.Cacheable
Skill *Skill `json:"skill"`
// contains filtered or unexported fields
}
GetSkillResult is the result of skills/get. Its result type and cache hints are handled as in ListSkillsResult.
func Get ¶
func Get(ctx context.Context, session *mcp.ClientSession, params *GetSkillParams) (*GetSkillResult, error)
Get calls skills/get and validates the response without imposing manifest size caps. The URI in params must identify a SKILL.md, whether or not it was listed.
func (*GetSkillResult) MarshalJSON ¶
func (r *GetSkillResult) MarshalJSON() ([]byte, error)
func (*GetSkillResult) UnmarshalJSON ¶
func (r *GetSkillResult) UnmarshalJSON(data []byte) error
type Handlers ¶
type Handlers struct {
List ListSkillsHandler
Get GetSkillHandler
ReadDirectory ReadDirectoryHandler
}
Handlers contains the Skills extension handlers. List and Get are required; ReadDirectory is optional.
type InvalidSkill ¶
InvalidSkill describes an entry omitted from a list response.
type Limits ¶
type Limits struct {
// MaxResourcesPerSkill limits the number of files, including SKILL.md.
MaxResourcesPerSkill int
// MaxTotalSize limits the sum of the files' raw byte lengths.
MaxTotalSize int64
}
Limits bounds a static skill manifest. Positive fields are exact caps; zero fields are unlimited, and negative fields are invalid. The zero value imposes no manifest caps. Limits never disable structural validation.
Limits are optional application policy. BaselineLimits provides the spec's interoperability baseline. Applications manage budgets for dynamic content.
func BaselineLimits ¶
func BaselineLimits() Limits
BaselineLimits returns the Skills spec's interoperability baseline: 512 files and 16 MiB per skill. Hosts must support at least this much and may support more; servers should stay within it for broad compatibility. The SDK does not impose these caps by default. Use explicit numeric limits to pin application policy independently of future spec revisions.
type ListOptions ¶
type ListOptions struct {
// SkipInvalidSkills omits invalid entries instead of rejecting the page.
// Invalid response envelopes always fail. Skipped entries are reported in
// ListSkillsResult.InvalidSkills and, if set, to OnInvalidSkill.
SkipInvalidSkills bool
// OnInvalidSkill receives each skipped entry, including during List.
OnInvalidSkill func(InvalidSkill)
}
ListOptions controls how list calls handle malformed entries.
type ListSkillsHandler ¶
type ListSkillsHandler func(context.Context, *ListSkillsRequest) (*ListSkillsResult, error)
ListSkillsHandler handles skills/list requests.
type ListSkillsParams ¶
type ListSkillsParams struct {
mcp.ParamsBase
Cursor string `json:"cursor,omitempty"`
}
ListSkillsParams contains parameters for skills/list.
type ListSkillsRequest ¶
type ListSkillsRequest = mcp.ServerRequest[*ListSkillsParams]
Request types for Skills server handlers.
type ListSkillsResult ¶
type ListSkillsResult struct {
mcp.ResultBase
mcp.Cacheable
NextCursor string `json:"nextCursor,omitempty"`
Skills []*Skill `json:"skills"`
// InvalidSkills reports entries skipped by List with SkipInvalidSkills enabled.
InvalidSkills []InvalidSkill `json:"-"`
// contains filtered or unexported fields
}
ListSkillsResult is one page of skills/list. Each Skill is a complete entry; its manifest is never split across pages. AddHandlers sets the result type and defaults CacheScope to "public"; a zero TTLMs marks the response immediately stale. These fields are omitted before protocol version 2026-07-28.
func ListPage ¶
func ListPage(ctx context.Context, session *mcp.ClientSession, params *ListSkillsParams, options *ListOptions) (*ListSkillsResult, error)
ListPage calls skills/list and validates the response without imposing manifest size caps. If params is nil, ListPage requests the first page.
func (*ListSkillsResult) MarshalJSON ¶
func (r *ListSkillsResult) MarshalJSON() ([]byte, error)
func (*ListSkillsResult) UnmarshalJSON ¶
func (r *ListSkillsResult) UnmarshalJSON(data []byte) error
type ReadDirectoryHandler ¶
type ReadDirectoryHandler func(context.Context, *ReadDirectoryRequest) (*ReadDirectoryResult, error)
ReadDirectoryHandler handles resources/directory/read. Return (nil, nil) if the URI does not exist or is not a directory. An empty directory has a non-nil result.
type ReadDirectoryParams ¶
type ReadDirectoryParams struct {
mcp.ParamsBase
URI string `json:"uri"`
Cursor string `json:"cursor,omitempty"`
}
ReadDirectoryParams contains parameters for resources/directory/read.
type ReadDirectoryRequest ¶
type ReadDirectoryRequest = mcp.ServerRequest[*ReadDirectoryParams]
Request types for Skills server handlers.
type ReadDirectoryResult ¶
type ReadDirectoryResult struct {
mcp.ResultBase
mcp.Cacheable
NextCursor string `json:"nextCursor,omitempty"`
Resources []*mcp.Resource `json:"resources"`
// contains filtered or unexported fields
}
ReadDirectoryResult is the result of resources/directory/read. Its result type and cache hints are handled as in ListSkillsResult. The hints describe the freshness of the listing, not of a held skill entry.
func ReadDirectory ¶
func ReadDirectory(ctx context.Context, session *mcp.ClientSession, params *ReadDirectoryParams) (*ReadDirectoryResult, error)
ReadDirectory calls resources/directory/read and validates the response. The server must advertise directoryRead, and params must specify a directory URI.
func (*ReadDirectoryResult) MarshalJSON ¶
func (r *ReadDirectoryResult) MarshalJSON() ([]byte, error)
func (*ReadDirectoryResult) UnmarshalJSON ¶
func (r *ReadDirectoryResult) UnmarshalJSON(data []byte) error
type Resource ¶
type Resource struct {
URI string `json:"uri"`
// Digest is the SHA-256 hash of the raw file bytes, as "sha256:" followed
// by 64 lowercase hexadecimal digits.
Digest string `json:"digest"`
// Size is the length of the raw file content in bytes.
Size int64 `json:"size"`
}
Resource identifies and fingerprints one file in a skill.
func (*Resource) UnmarshalJSON ¶
type Resources ¶
type Resources struct {
// contains filtered or unexported fields
}
Resources is either a complete static resource manifest or the dynamic marker. Its zero value is invalid; use StaticResources or DynamicResources.
func DynamicResources ¶
func DynamicResources() Resources
DynamicResources constructs the marker used when stable digests cannot be published.
func StaticResources ¶
StaticResources constructs a complete static resource manifest. It must include SKILL.md and every supporting file, including nested skills. The resource slice and its entries are retained, not copied.
func (Resources) List ¶
List returns the static manifest and true, or nil and false for dynamic or unset resources. The returned slice and entries are shared with r.
func (Resources) MarshalJSON ¶
func (*Resources) UnmarshalJSON ¶
type ServerOptions ¶
type ServerOptions struct {
// Limits optionally bounds static manifests; zero fields impose no caps.
// Use [BaselineLimits] to opt into the spec's interoperability baseline.
// AddHandlers copies the value during registration.
Limits Limits
}
ServerOptions configures the per-skill limits. Protocol validation always runs; applications can perform additional checks in their handlers.
type Skill ¶
type Skill struct {
URI string `json:"uri"`
Frontmatter Frontmatter `json:"frontmatter"`
Resources Resources `json:"resources"`
// Meta is reserved for protocol metadata. Keys defined by the Skills
// extension use the io.modelcontextprotocol.skills/ prefix.
Meta mcp.Meta `json:"_meta,omitempty"`
}
Skill is an entry returned by skills/list or skills/get.