get_info
Retrieve file metadata from storage services (e.g., S3, Azure Blob) via OpenDAL. Input the resource URI to access detailed file information instantly.
Instructions
Get metadata of file in OpenDAL service
Args:
uri: resource URI, e.g. mys3://path/to/file
Returns:
File metadata information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uri | Yes |
Implementation Reference
- src/mcp_server_opendal/server.py:134-158 (handler)The main handler function for the 'get_info' tool. It parses the URI, retrieves metadata using OpendalResource.stat, formats the file path, size, and content type into a string response, and handles errors.@mcp.tool() async def get_info(uri: str) -> str: """ Get metadata of file in OpenDAL service Args: uri: resource URI, e.g. mys3://path/to/file Returns: File metadata information """ logger.debug(f"Getting file info: {uri}") try: resource, path = parse_uri(uri) metadata = await resource.stat(path) result = f"File: {path}\n" result += f"Size: {metadata.content_length} bytes\n" result += f"Type: {metadata.content_type}\n" return result except Exception as e: logger.error(f"Failed to get file info: {e!s}") return f"Error: {e!s}"
- Helper function parse_uri used in get_info to parse the input URI into an OpendalResource instance and the file path.def parse_uri(uri: str) -> Tuple[OpendalResource, str]: """Parse a URI into a resource and path""" from urllib.parse import unquote, urlparse logger.debug(f"Parsing URI: {uri}") parsed = urlparse(uri) scheme = parsed.scheme path = parsed.netloc + parsed.path path = unquote(path) # Decode URL-encoded characters return (OpendalResource(scheme), path)
- OpendalResource.stat method invoked by get_info to retrieve the file metadata (content_length, content_type).async def stat(self, path: Union[str, os.PathLike]) -> Metadata: """Get metadata for a specific path""" logger.debug(f"Statting path: {path}") return await self.op.stat(path)