|
| 1 | +--- |
| 2 | +title: "Roots" |
| 3 | +description: "Understanding roots in MCP" |
| 4 | +--- |
| 5 | + |
| 6 | +Roots are a concept in MCP that define the boundaries where servers can operate. They provide a way for clients to inform servers about relevant resources and their locations. |
| 7 | + |
| 8 | +## What are Roots? |
| 9 | + |
| 10 | +A root is a URI that a client suggests a server should focus on. When a client connects to a server, it declares which roots the server should work with. While primarily used for filesystem paths, roots can be any valid URI including HTTP URLs. |
| 11 | + |
| 12 | +For example, roots could be: |
| 13 | + |
| 14 | +``` |
| 15 | +file:///home/user/projects/myapp |
| 16 | +https://api.example.com/v1 |
| 17 | +``` |
| 18 | + |
| 19 | +## Why Use Roots? |
| 20 | + |
| 21 | +Roots serve several important purposes: |
| 22 | + |
| 23 | +1. **Guidance**: They inform servers about relevant resources and locations |
| 24 | +2. **Clarity**: Roots make it clear which resources are part of your workspace |
| 25 | +3. **Organization**: Multiple roots let you work with different resources simultaneously |
| 26 | + |
| 27 | +## How Roots Work |
| 28 | + |
| 29 | +When a client supports roots, it: |
| 30 | + |
| 31 | +1. Declares the `roots` capability during connection |
| 32 | +2. Provides a list of suggested roots to the server |
| 33 | +3. Notifies the server when roots change (if supported) |
| 34 | + |
| 35 | +While roots are informational and not strictly enforcing, servers should: |
| 36 | + |
| 37 | +1. Respect the provided roots |
| 38 | +2. Use root URIs to locate and access resources |
| 39 | +3. Prioritize operations within root boundaries |
| 40 | + |
| 41 | +## Common Use Cases |
| 42 | + |
| 43 | +Roots are commonly used to define: |
| 44 | + |
| 45 | +- Project directories |
| 46 | +- Repository locations |
| 47 | +- API endpoints |
| 48 | +- Configuration locations |
| 49 | +- Resource boundaries |
| 50 | + |
| 51 | +## Best Practices |
| 52 | + |
| 53 | +When working with roots: |
| 54 | + |
| 55 | +1. Only suggest necessary resources |
| 56 | +2. Use clear, descriptive names for roots |
| 57 | +3. Monitor root accessibility |
| 58 | +4. Handle root changes gracefully |
| 59 | + |
| 60 | +## Example |
| 61 | + |
| 62 | +Here's how a typical MCP client might expose roots: |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "roots": [ |
| 67 | + { |
| 68 | + "uri": "file:///home/user/projects/frontend", |
| 69 | + "name": "Frontend Repository" |
| 70 | + }, |
| 71 | + { |
| 72 | + "uri": "https://api.example.com/v1", |
| 73 | + "name": "API Endpoint" |
| 74 | + } |
| 75 | + ] |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +This configuration suggests the server focus on both a local repository and an API endpoint while keeping them logically separated. |
0 commit comments