Documentation
¶
Overview ¶
Package roots provides client workspace discovery via the MCP Roots capability.
Roots is a client-side capability — the client declares workspace directories/files and the server can query them via ServerSession.ListRoots(). The Manager caches current roots per session and provides helpers for workspace-aware operations.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientSupportsRoots ¶ added in v1.2.1
func ClientSupportsRoots(session *mcp.ServerSession) bool
ClientSupportsRoots reports whether the client advertised the roots capability during the MCP initialize handshake. Returns false when the session has not yet completed initialize, when capabilities are missing, or when the client did not declare a roots capability.
func ListClientRoots ¶
ListClientRoots queries the client for its current workspace roots via the tool request's session. Returns nil with no error when the session is unavailable, enabling graceful degradation for clients without roots support.
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager caches client-provided roots for a session and provides workspace-aware lookup helpers. Safe for concurrent use.
func (*Manager) FindGitRoot ¶
FindGitRoot scans cached roots for a path that looks like a Git repository root (URI path ends with ".git" or the root name contains "git"/"repo" hints). Returns the URI and true if found, or ("", false) otherwise.
func (*Manager) Refresh ¶
Refresh queries the client for its current roots via the session and caches the result. Returns nil with an empty root list if the client does not support roots or returns an error (graceful degradation).
When the client did not advertise the roots capability during initialization, Refresh clears the cache and returns nil without contacting the client. This avoids a guaranteed-to-fail JSON-RPC request and the noisy warning that would follow.
func (*Manager) SetRootsForTest ¶
SetRootsForTest replaces the cached root list. Exported for use in tests only.