list
Retrieve directory contents from OpenDAL storage services by specifying the resource URI. Lists files and folder details for efficient data management.
Instructions
List files in OpenDAL service
Args:
uri: resource URI, e.g. mys3://path/to/dir
Returns:
String containing directory content
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uri | Yes |
Implementation Reference
- src/mcp_server_opendal/server.py:84-108 (handler)The main handler for the 'list' MCP tool. Decorated with @mcp.tool() for automatic registration. Parses the URI, ensures directory path ends with '/', lists entries via OpendalResource.list(), and returns their string representation.@mcp.tool() async def list(uri: str) -> str: """ List files in OpenDAL service Args: uri: resource URI, e.g. mys3://path/to/dir Returns: String containing directory content """ logger.debug(f"Listing directory content: {uri}") try: resource, path = parse_uri(uri) # Ensure directory path ends with a slash if path and not path.endswith("/"): path = path + "/" entries = await resource.list(path) return str(entries) except Exception as e: logger.error(f"Failed to list directory content: {e!s}") return f"Error: {e!s}"
- Helper method in OpendalResource class that performs the actual directory listing using the OpenDAL operator's list iterator.async def list( self, prefix: Union[str, os.PathLike], max_keys: int = 1000 ) -> List[Entry]: """List entries with the given prefix""" logger.debug(f"Listing entries with prefix: {prefix}") if max_keys <= 0: return [] entries = [] it = await self.op.list(prefix) async for entry in it: logger.debug(f"Listing entry: {entry}") entries.append(entry) if len(entries) >= max_keys: break return entries