mcpskills

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package mcpskills discovers skills served by a trusted Model Context Protocol (MCP) server. It reads the skill://index.json discovery document and supports skill-md and ZIP archive entries.

Skill-md discovery uses index metadata without downloading SKILL.md. The first successful GetContent call caches the full instructions; GetResource fetches named sibling resources on demand. Resources may contain text or binary github.com/microsoft/agent-framework-go/message.DataContent.

Archives are refreshed on every discovery, with optional SHA-256 digest verification and configurable download, file-count, and uncompressed-size limits. Extraction is confined to each skill directory. Extracted scripts are never executable; configure resource extensions to make script files readable. Archive containers use safe directory names, independently of the names of skills within them. Archive resource reads are serialized with refresh and cleanup; waiting reads honor context cancellation. Unsupported entry types, including mcp-resource-template, are skipped.

Register a source with github.com/microsoft/agent-framework-go/agent/skills.ContextProviderOptions.Sources. The provider caches discovery by default; configure its RefreshInterval or DisableCaching when server content changes. Resource reads continue to use the originating server even when discovery is cached.

The caller owns the MCP session. Close the source before closing the session, or transfer source ownership to the skills provider with OwnsSources. Only connect to trusted servers: remote instructions and resources may contain prompt injection. Digests verify consistency with the server's index, not authenticity or trustworthiness.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Session is an initialized connection to a trusted MCP server. The source
	// borrows the session; the caller remains responsible for closing it.
	Session *mcp.ClientSession

	// ArchiveDirectory holds extracted archive skills. The source exclusively
	// manages its subdirectories and prunes skills no longer advertised by the
	// server. Each source must use a separate directory.
	// Existing regular files are preserved; colliding archive entries are skipped.
	// Empty uses a private temporary directory, removed by [Source.Close].
	ArchiveDirectory string

	// ArchiveResourceExtensions selects readable archive resource extensions.
	// Nil defaults to .md, .json, .yaml, .yml, .csv, .xml, and .txt.
	// An explicitly empty slice disables resource discovery. Script extensions
	// may be included here, but archive scripts are never executable.
	ArchiveResourceExtensions []string

	// ArchiveResourceSearchDepth limits resource discovery within each skill.
	// Nil defaults to 2; explicit values must be at least 1.
	ArchiveResourceSearchDepth *int

	// ArchiveMaxFileCount limits extracted files per archive. Nil defaults to
	// 20. Zero disallows files; negative values are invalid.
	ArchiveMaxFileCount *int

	// ArchiveMaxSizeBytes limits decoded archive downloads. Nil defaults to
	// 1 MiB. Zero disallows nonempty archives; negative values are invalid.
	ArchiveMaxSizeBytes *int64

	// ArchiveMaxUncompressedSizeBytes limits the actual total bytes extracted
	// per archive. Nil defaults to 1 MiB. Negative values are invalid.
	ArchiveMaxUncompressedSizeBytes *int64

	// Logger receives discovery and skipped-entry diagnostics.
	// Nil uses a discard logger.
	Logger *slog.Logger
}

Config configures an MCP-backed skills source.

type Source

type Source struct {
	// contains filtered or unexported fields
}

Source discovers skills from an MCP server's skill://index.json resource. Construct it with NewSource and release its filesystem resources with Source.Close. It implements skills.Source.

Discovery is not cached. Archive reconciliation and resource reads are serialized; compose with skills.NewCachingSource or use the skills provider's default caching to share discovery work.

func NewSource

func NewSource(config Config) *Source

NewSource creates a source, copying configuration values and slices. It panics if Session is nil, a size or file-count limit is negative, or the resource search depth is less than 1. No discovery or filesystem work occurs until Source.Skills is called.

func (*Source) Close

func (s *Source) Close() error

Close idempotently releases archive filesystem handles and removes the private temporary directory, if any. Caller-configured directories are retained. Close never closes the borrowed MCP session. New discovery, archive resource reads, and lazy remote reads fail with fs.ErrClosed. Already fetched MCP resource content remains usable.

func (*Source) Skills

func (s *Source) Skills(ctx context.Context, sourceContext skills.SourceContext) ([]*skills.Skill, error)

Skills reads the discovery index, constructs lazy skill-md entries, and refreshes archive entries. Unsupported or invalid entries are logged and skipped. An absent, empty, malformed, or protocol-unreadable index advertises no skills and still prunes previously extracted archives. Cancellation, transport failures, and archive-root access errors propagate. Individual archive extraction failures are logged and skipped. Missing extracted archive directories are also logged and skipped.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL