skills: add SEP-2640 support - #1238
Conversation
a92d749 to
adc1ddf
Compare
adc1ddf to
ca89d93
Compare
|
Woooot great to see this @sambhav. I ran the SEP-2640 conformance scenarios against this branch (conformance PR 330, the traceability extraction and server scenarios Il share soon for the skills extension). 41 checks, 0 failures.
Repro, pointing a minimal Got three tiny notes (none blocking): 1. 2. Two untestable 3. Possible doc gap dueto needing flags against this branch. The runner defaults to the draft stateless wire. here it asserts |
Summary
Add typed Go SDK support for SEP-2640:
skills/listandskills/getserver handlers and typed client callsresources/directory/readsupport"dynamic"resourcesAddDirectoryandAddFSutilities with configurable startup, interval, request, and externally triggered catalog refreshExisting API and behavior
This change is additive. It does not change the signature or documented behavior of existing resource APIs.
The only addition to the existing
mcppackage is(*Server).AddExtension, which safely adds an extension capability without mutating caller-ownedServerCapabilities. ExistingAddResource,AddResourceTemplate,resources/list, andresources/readbehavior is unchanged. The filesystem utility uses the existing dynamic resource-template dispatch path rather than modifying startup resource registration semantics.Filesystem refresh policy
DirectoryOptions.RefreshModemakes catalog discovery explicit:Cached modes can also refresh early from a caller-owned clock, filesystem watcher, or monitor:
RefreshOnRequestdiscovers additions, changes, and removals immediately. List/get requests build complete manifests and hashes; directory and individual resource reads only index metadata and do not hash unrelated files.RefreshOnStartupbuilds, validates, and hashes the catalog once whenNewDirectoryProvider,NewFSProvider,AddDirectory, orAddFSis called. ARefreshsignal can explicitly replace that snapshot.RefreshPeriodicallybuilds the same initial snapshot and refreshes it lazily on the first request afterRefreshInterval, or earlier whenRefreshis signaled.Refreshis receive-only to the provider. Signals are coalesced and consumed on requests, so callers should use a buffered channel and retain ownership of any producer lifecycle.resources/readstill reads the requested file at call time in every mode, so file bytes are not retained in memory.Simple usage
Server
./skillsmay contain one or more skill directories, each rooted by aSKILL.md. The zero-value options rescan on every request; passDirectoryOptionsto select another refresh policy.Client
skills.ReadDirectoryandskills.DirectoryEntriesexpose the optionalresources/directory/readcapability; ordinary file content is read withsession.ReadResource.Custom filesystem
A minimal in-memory filesystem uses the standard library
fstest.MapFS:AddFSworks withembed.FS,fstest.MapFS, or any implementation offs.FS. A production mutable in-memory or database-backed implementation must synchronize its reads and updates according to thefs.FScontract. After committing an update, its watcher can request a new catalog without blocking:Filesystem cost model
RefreshOnRequestdirectory or resource lookupRefreshOnRequestlist/getRefreshOnStartupcached requestresources/readstill reads only the requested fileRefreshPeriodicallyStatic manifests cannot avoid reading and hashing their resources: SEP-2640 requires complete
{uri, digest, size}entries. For a database or remote object store where full scans are expensive, prefer a startup/periodic cache with explicit monitor signals. If complete manifests are inherently expensive or impossible, implementAddHandlersand returnskills.DynamicResources()instead.Custom list/get handlers
Servers that do not map skills to a filesystem can implement the extension methods directly. This example publishes generated content with the explicit
"dynamic"resource marker:Custom handlers register content separately through the existing
server.AddResourceorserver.AddResourceTemplateAPIs.AddHandlersvalidates returned skills using SEP defaults and advertises the extension capability.Design decisions and tradeoffs
skillspackageskills.AddHandlersorskills.AddClientskills/getskills/listandskills/getValidation
go test ./...go test -race ./skillsgo vet ./...go build ./...govulncheck ./...— no reachable vulnerabilitiesGenerated client and server documentation is included.