Class Root

java.lang.Object
com.tnsai.mcp.model.Root

public class Root extends Object
Represents a root directory that clients can expose to servers.

Roots allow servers to understand the file system context of the client, enabling features like file watching and path resolution.

Example usage:


 Root projectRoot = Root.of("/home/user/project", "My Project");
 Root homeRoot = Root.fromPath(Paths.get(System.getProperty("user.home")));

 mcpClient.setRoots(List.of(projectRoot, homeRoot));
 
  • Constructor Details

    • Root

      public Root()
    • Root

      public Root(String uri, String name)
  • Method Details

    • of

      public static Root of(String uri, String name)
      Creates a Root from a URI string and display name.
      Parameters:
      uri - the file URI (e.g., "file:///path/to/dir")
      name - the display name
      Returns:
      a new Root instance
    • fromPath

      public static Root fromPath(Path path)
      Creates a Root from a file path.
      Parameters:
      path - the file path
      Returns:
      a new Root instance with URI and name derived from path
    • fromPath

      public static Root fromPath(Path path, String name)
      Creates a Root from a file path with custom name.
      Parameters:
      path - the file path
      name - the display name
      Returns:
      a new Root instance
    • fromFile

      public static Root fromFile(File file)
      Creates a Root from a File.
      Parameters:
      file - the file
      Returns:
      a new Root instance
    • fromDirectory

      public static Root fromDirectory(String path, String name)
      Creates a Root from a directory path string.
      Parameters:
      path - the directory path (will be converted to file URI)
      name - the display name
      Returns:
      a new Root instance
    • getUri

      public String getUri()
    • setUri

      public void setUri(String uri)
    • getName

      public String getName()
    • setName

      public void setName(String name)
    • getPath

      public String getPath()
      Extracts the file path from the URI.
      Returns:
      the file path, or null if not a file URI
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object