Package com.tnsai.mcp.model
Class Root
java.lang.Object
com.tnsai.mcp.model.Root
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic RootfromDirectory(String path, String name) Creates a Root from a directory path string.static RootCreates a Root from a File.static RootCreates a Root from a file path.static RootCreates a Root from a file path with custom name.getName()getPath()Extracts the file path from the URI.getUri()inthashCode()static RootCreates a Root from a URI string and display name.voidvoidtoString()
-
Constructor Details
-
Root
public Root() -
Root
-
-
Method Details
-
of
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
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
Creates a Root from a file path with custom name.- Parameters:
path- the file pathname- the display name- Returns:
- a new Root instance
-
fromFile
Creates a Root from a File.- Parameters:
file- the file- Returns:
- a new Root instance
-
fromDirectory
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
-
setUri
-
getName
-
setName
-
getPath
Extracts the file path from the URI.- Returns:
- the file path, or null if not a file URI
-
equals
-
hashCode
public int hashCode() -
toString
-