roots

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 8 Imported by: 0

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 ListClientRoots

func ListClientRoots(ctx context.Context, session *mcp.ServerSession) ([]*mcp.Root, error)

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 NewManager

func NewManager() *Manager

NewManager creates a Manager with an empty root set.

func (*Manager) FindGitRoot

func (m *Manager) FindGitRoot() (string, bool)

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) GetRoots

func (m *Manager) GetRoots() []*mcp.Root

GetRoots returns a copy of the cached root list.

func (*Manager) HasRoot

func (m *Manager) HasRoot(uri string) bool

HasRoot checks whether a specific URI exists in the cached root list.

func (*Manager) Refresh

func (m *Manager) Refresh(ctx context.Context, session *mcp.ServerSession) error

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).

func (*Manager) SetRootsForTest

func (m *Manager) SetRootsForTest(roots []*mcp.Root)

SetRootsForTest replaces the cached root list. Exported for use in tests only.

Jump to

Keyboard shortcuts

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