Skip to main content
Glama
Xuanwo

MCP Server for Apache OpenDAL™

by Xuanwo

read

Retrieve file content from various storage services using a unified URI interface. Specify the resource location to access data across S3, Azure Blob Storage, and Google Cloud Storage.

Instructions

Read file content from OpenDAL service

Args:
    uri: resource URI, e.g. mys3://path/to/file

Returns:
    File content or error information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
uriYes

Implementation Reference

  • The MCP tool handler for 'read'. It processes the URI input, parses it using parse_uri, and invokes the opendal_resource template to retrieve and format the file content as text or base64-encoded binary.
    @mcp.tool()
    async def read(uri: str) -> Dict[str, Any]:
        """
        Read file content from OpenDAL service
    
        Args:
            uri: resource URI, e.g. mys3://path/to/file
    
        Returns:
            File content or error information
        """
        logger.debug(f"Reading file content: {uri}")
        try:
            resource, path = parse_uri(uri)
            # Directly call the resource function to get content
            return await opendal_resource(resource.scheme, path)
        except Exception as e:
            logger.error(f"Failed to read file content: {e!s}")
            return {"error": str(e)}
  • Key helper resource template (@mcp.resource) that performs the core file reading logic. Reads raw bytes with read_path, stats the file, detects text/binary, and formats the output dictionary used by the 'read' tool.
    @mcp.resource("{scheme}://{path}")
    async def opendal_resource(scheme: str, path: str) -> Dict[str, Any]:
        """
        Access files in OpenDAL service
    
        Args:
            scheme: storage service scheme
            path: file path
    
        Returns:
            Dictionary containing file content and metadata
        """
        logger.debug(f"Reading template resource content: {scheme}://{path}")
        try:
            resource = OpendalResource(scheme)
            data = await resource.read_path(path)
            metadata = await resource.stat(path)
    
            if resource.is_text_file(path):
                return {
                    "content": data.decode("utf-8"),
                    "mime_type": metadata.content_type or "text/plain",
                    "size": metadata.content_length,
                    "is_binary": False,
                }
            else:
                return {
                    "content": base64.b64encode(data).decode("ascii"),
                    "mime_type": metadata.content_type or "application/octet-stream",
                    "size": metadata.content_length,
                    "is_binary": True,
                }
        except Exception as e:
            logger.error(f"Failed to read resource: {e!s}")
            return {"error": str(e)}
  • Low-level asynchronous method in OpendalResource class that executes the actual file read operation using the underlying OpenDAL operator (self.op.read). Called by opendal_resource.
    async def read_path(self, path: Union[str, os.PathLike]) -> bytes:
        """Read content from a specific path"""
        logger.debug(f"Reading path: {path}")
        return await self.op.read(path)
  • Utility function to parse the input URI into scheme and path, instantiating the appropriate OpendalResource. Used by the 'read' tool.
    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)

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Xuanwo/mcp-server-opendal'

If you have feedback or need assistance with the MCP directory API, please join our Discord server