Use the list_roots() method on the context object:
from mcp_use.server import Context, MCPServerserver = MCPServer(name="File Server")@server.tool()async def get_workspace_info(ctx: Context) -> str: """Get information about the client's available workspaces.""" roots = await ctx.list_roots() if not roots: return "No roots available from client" lines = [f"Available workspaces ({len(roots)}):"] for root in roots: name = root.name or "(unnamed)" lines.append(f" - {name}: {root.uri}") return "\n".join(lines)
@server.tool()async def search_files(pattern: str, ctx: Context) -> str: """Search for files matching a pattern in client workspaces.""" roots = await ctx.list_roots() if not roots: return "No workspaces available to search" results = [] for root in roots: path = str(root.uri).replace("file://", "") # Search logic here... results.append(f"Searched in: {root.name or path}") return "\n".join(results)