INNER CODE UNIT · Python

read_file

existence-master/Sentient · src/server/mcp_hub/file_management/main.py:57

async def read_file(ctx: Context, filename: str) -> Dict[str, Any]:
    """
    Reads the content of a specified file from the temporary storage and extracts its text content. The `filename` should be one of the files returned by `list_files`.
    """
    logger.info(f"Executing tool: read_file with filename='{filename}'")
    try:
        user_id = auth.get_user_id_from_context(ctx)
        safe_user_id = "".join(c for c in user_id if c.isalnum() or c in ('-', '_'))
        # Prepend user_id to filename to create the relative path
        relative_path = os.path.join(safe_user_id, filename)
        safe_path = _get_safe_filepath(relative_path)
        
        if not safe_path.exists():
            return {"status": "failure", "error": "File not found."}
        
        def process_file():
            try:
                # Convert the Path object to a string. This is all that's needed.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…