@@ -38,6 +38,7 @@ It implements the Model Context Protocol specification, handling model context r
3838- Supports resource registration and retrieval
3939- Supports stdio & Streamable HTTP (including SSE) transports
4040- Supports notifications for list changes (tools, prompts, resources)
41+ - Supports roots (server-to-client filesystem boundary queries)
4142- Supports sampling (server-to-client LLM completion requests)
4243
4344### Supported Methods
@@ -52,6 +53,7 @@ It implements the Model Context Protocol specification, handling model context r
5253- ` resources/read ` - Retrieves a specific resource by name
5354- ` resources/templates/list ` - Lists all registered resource templates and their schemas
5455- ` completion/complete ` - Returns autocompletion suggestions for prompt arguments and resource URIs
56+ - ` roots/list ` - Requests filesystem roots from the client (server-to-client)
5557- ` sampling/createMessage ` - Requests LLM completion from the client (server-to-client)
5658- ` elicitation/create ` - Requests user input from the client (server-to-client)
5759
@@ -891,6 +893,70 @@ server = MCP::Server.new(
891893)
892894```
893895
896+ ### Roots
897+
898+ The Model Context Protocol allows servers to request filesystem roots from clients through the ` roots/list ` method.
899+ Roots define the boundaries of where a server can operate, providing a list of directories and files the client has made available.
900+
901+ ** Key Concepts:**
902+
903+ - ** Server-to-Client Request** : Like sampling, roots listing is initiated by the server
904+ - ** Client Capability** : Clients must declare ` roots ` capability during initialization
905+ - ** Change Notifications** : Clients that support ` roots.listChanged ` send ` notifications/roots/list_changed ` when roots change
906+
907+ ** Using Roots in Tools:**
908+
909+ Tools that accept a ` server_context: ` parameter can call ` list_roots ` on it.
910+ The request is automatically routed to the correct client session:
911+
912+ ``` ruby
913+ class FileSearchTool < MCP ::Tool
914+ description " Search files within the client's project roots"
915+ input_schema(
916+ properties: {
917+ query: { type: " string" }
918+ },
919+ required: [" query" ]
920+ )
921+
922+ def self .call (query: , server_context: )
923+ roots = server_context.list_roots
924+ root_uris = roots[:roots ].map { |root | root[:uri ] }
925+
926+ MCP ::Tool ::Response .new ([{
927+ type: " text" ,
928+ text: " Searching in roots: #{ root_uris.join(" , " ) } "
929+ }])
930+ end
931+ end
932+ ```
933+
934+ Result contains an array of root objects:
935+
936+ ``` ruby
937+ {
938+ roots: [
939+ { uri: " file:///home/user/projects/myproject" , name: " My Project" },
940+ { uri: " file:///home/user/repos/backend" , name: " Backend Repository" }
941+ ]
942+ }
943+ ```
944+
945+ ** Handling Root Changes:**
946+
947+ Register a callback to be notified when the client's roots change:
948+
949+ ``` ruby
950+ server.roots_list_changed_handler do
951+ puts " Client's roots have changed, tools will see updated roots on next call."
952+ end
953+ ```
954+
955+ ** Error Handling:**
956+
957+ - Raises ` RuntimeError ` if client does not support ` roots ` capability
958+ - Raises ` StandardError ` if client returns an error response
959+
894960### Sampling
895961
896962The Model Context Protocol allows servers to request LLM completions from clients through the ` sampling/createMessage ` method.
0 commit comments