I'll modify the comparison logic to handle mismatched stations properly. Here are the changes:

## Instructions for Handling Mismatched Stations

### 1. Modify the `compare_1d_profiles` handler in `handle_call_tool()`

Replace the comparison logic in the `compare_1d_profiles` handler:

```python
elif name == "compare_1d_profiles":
    try:
        project_path = arguments.get("project_path")
        plan1_name = arguments["plan1_name"]
        plan2_name = arguments["plan2_name"]
        river_name = arguments.get("river_name")
        reach_name = arguments.get("reach_name")
        
        # Get or initialize project
        ras = get_or_init_project(project_path)
        
        # Get HDF paths for both plans
        plan1_hdf_path = get_plan_hdf_path(ras, plan1_name)
        plan2_hdf_path = get_plan_hdf_path(ras, plan2_name)
        
        if not plan1_hdf_path:
            return [TextContent(
                type="text",
                text=f"Error: Plan '{plan1_name}' not found or has no results HDF file"
            )]
        
        if not plan2_hdf_path:
            return [TextContent(
                type="text",
                text=f"Error: Plan '{plan2_name}' not found or has no results HDF file"
            )]
        
        response_parts = [
            f"1D Profile Comparison",
            f"Plan 1 (Baseline): {plan1_name}",
            f"Plan 2 (Comparison): {plan2_name}",
        ]
        
        if river_name:
            response_parts.append(f"River: {river_name}")
        if reach_name:
            response_parts.append(f"Reach: {reach_name}")
        
        response_parts.append("=" * 80)
        
        try:
            # Get cross-section data for both plans
            xsec_data1 = HdfResultsXsec.get_xsec_timeseries(plan1_hdf_path)
            xsec_data2 = HdfResultsXsec.get_xsec_timeseries(plan2_hdf_path)
            
            # Format results for both plans
            profile_df1 = format_profile_results(xsec_data1, river_name, reach_name)
            profile_df2 = format_profile_results(xsec_data2, river_name, reach_name)
            
            if profile_df1.empty and profile_df2.empty:
                response_parts.append("\nNo cross-section data found for the specified criteria")
            else:
                # Merge the dataframes on River, Reach, Station with outer join
                comparison_df = pd.merge(
                    profile_df1[['River', 'Reach', 'Station', 'Max WSEL']],
                    profile_df2[['River', 'Reach', 'Station', 'Max WSEL']],
                    on=['River', 'Reach', 'Station'],
                    how='outer',
                    suffixes=('_Plan1', '_Plan2')
                )
                
                # Calculate difference only where both values exist
                comparison_df['WSEL_Difference'] = pd.Series(dtype='float64')
                mask = comparison_df['Max WSEL_Plan1'].notna() & comparison_df['Max WSEL_Plan2'].notna()
                comparison_df.loc[mask, 'WSEL_Difference'] = (
                    comparison_df.loc[mask, 'Max WSEL_Plan1'] - 
                    comparison_df.loc[mask, 'Max WSEL_Plan2']
                )
                
                # Sort by River, Reach, Station
                comparison_df.sort_values(['River', 'Reach', 'Station'], inplace=True)
                
                # Replace NaN with blank strings for display
                display_df = comparison_df.copy()
                display_df = display_df.fillna('')
                
                # Round numeric values for display
                for col in ['Max WSEL_Plan1', 'Max WSEL_Plan2', 'WSEL_Difference']:
                    if col in display_df.columns:
                        # Only round numeric values, leave blanks as blanks
                        mask = display_df[col] != ''
                        if mask.any():
                            display_df.loc[mask, col] = pd.to_numeric(display_df.loc[mask, col]).round(3)
                
                response_parts.append(dataframe_to_text(display_df, "PROFILE COMPARISON"))
                
                # Add summary statistics (only for valid differences)
                if 'WSEL_Difference' in comparison_df.columns:
                    diff_col = comparison_df['WSEL_Difference'].dropna()
                    if not diff_col.empty:
                        response_parts.append("\nSUMMARY STATISTICS (for matching stations only):")
                        response_parts.append(f"  Stations in Plan 1 only: {(comparison_df['Max WSEL_Plan1'].notna() & comparison_df['Max WSEL_Plan2'].isna()).sum()}")
                        response_parts.append(f"  Stations in Plan 2 only: {(comparison_df['Max WSEL_Plan1'].isna() & comparison_df['Max WSEL_Plan2'].notna()).sum()}")
                        response_parts.append(f"  Matching stations: {mask.sum()}")
                        response_parts.append(f"  Mean Difference: {diff_col.mean():.3f}")
                        response_parts.append(f"  Max Increase: {diff_col.max():.3f}")
                        response_parts.append(f"  Max Decrease: {diff_col.min():.3f}")
                        response_parts.append(f"  Std Deviation: {diff_col.std():.3f}")
                
        except Exception as e:
            response_parts.append(f"\nError comparing profiles: {str(e)}")
        
        return [TextContent(
            type="text",
            text="\n".join(response_parts)
        )]
        
    except Exception as e:
        logger.error(f"Error comparing 1D profiles: {str(e)}")
        return [TextContent(
            type="text",
            text=f"Error comparing 1D profiles: {str(e)}"
        )]
```

### 2. Modify the `plot_profile_comparison` function

Replace the `plot_profile_comparison` function to handle NaN values properly:

```python
def plot_profile_comparison(comparison_df, plan1_name, plan2_name, river_name=None, reach_name=None):
    """Create a comparison plot of two profiles."""
    
    # Set up the plot
    fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 8), dpi=80, 
                                   gridspec_kw={'height_ratios': [3, 1]})
    
    # Create title
    title_parts = [f"Profile Comparison - {plan1_name} vs {plan2_name}"]
    if river_name:
        title_parts.append(f"River: {river_name}")
    if reach_name:
        title_parts.append(f"Reach: {reach_name}")
    
    if not comparison_df.empty:
        # Sort by station
        comparison_df = comparison_df.sort_values('Station')
        
        # Separate data for each plan (removing NaN values for plotting)
        plan1_data = comparison_df[['Station', 'Max WSEL_Plan1']].dropna()
        plan2_data = comparison_df[['Station', 'Max WSEL_Plan2']].dropna()
        diff_data = comparison_df[['Station', 'WSEL_Difference']].dropna()
        
        # Top plot - both profiles
        if not plan1_data.empty:
            ax1.plot(plan1_data['Station'], plan1_data['Max WSEL_Plan1'], 
                    'b-o', linewidth=2, markersize=6, label=f'Plan: {plan1_name}')
        
        if not plan2_data.empty:
            ax1.plot(plan2_data['Station'], plan2_data['Max WSEL_Plan2'], 
                    'r--s', linewidth=2, markersize=6, label=f'Plan: {plan2_name}')
        
        ax1.set_ylabel('Water Surface Elevation', fontsize=12)
        ax1.legend(loc='best', fontsize=10)
        ax1.grid(True, alpha=0.3)
        ax1.set_title('\n'.join(title_parts), fontsize=14, fontweight='bold')
        
        # Bottom plot - difference (only where both exist)
        if not diff_data.empty:
            ax2.plot(diff_data['Station'], diff_data['WSEL_Difference'], 
                    'g-^', linewidth=2, markersize=6)
            
            # Add shading for positive/negative differences
            stations = diff_data['Station'].values
            differences = diff_data['WSEL_Difference'].values
            ax2.fill_between(stations, 0, differences, where=(differences > 0), 
                            alpha=0.3, color='blue', label='Plan1 Higher')
            ax2.fill_between(stations, 0, differences, where=(differences < 0), 
                            alpha=0.3, color='red', label='Plan2 Higher')
        
        ax2.axhline(y=0, color='k', linestyle='-', alpha=0.3)
        ax2.set_xlabel('Station', fontsize=12)
        ax2.set_ylabel('Difference (Plan1 - Plan2)', fontsize=12)
        ax2.grid(True, alpha=0.3)
        
        # Add markers for stations that exist in only one plan
        plan1_only = comparison_df[comparison_df['Max WSEL_Plan2'].isna() & comparison_df['Max WSEL_Plan1'].notna()]
        plan2_only = comparison_df[comparison_df['Max WSEL_Plan1'].isna() & comparison_df['Max WSEL_Plan2'].notna()]
        
        if not plan1_only.empty:
            ax1.scatter(plan1_only['Station'], plan1_only['Max WSEL_Plan1'], 
                       color='blue', s=100, marker='v', alpha=0.7, 
                       label='Plan1 only', zorder=5)
        
        if not plan2_only.empty:
            ax1.scatter(plan2_only['Station'], plan2_only['Max WSEL_Plan2'], 
                       color='red', s=100, marker='^', alpha=0.7, 
                       label='Plan2 only', zorder=5)
        
        # Update legend if we added markers
        if not plan1_only.empty or not plan2_only.empty:
            ax1.legend(loc='best', fontsize=10)
    
    plt.tight_layout()
    
    # Save to BytesIO buffer
    buffer = BytesIO()
    plt.savefig(buffer, format='png', dpi=80, bbox_inches='tight', 
                facecolor='white', edgecolor='none')
    plt.close()
    
    # Check size
    buffer.seek(0)
    img_size = len(buffer.getvalue())
    
    if img_size > 1024 * 1024:  # Reduce quality if needed
        buffer = BytesIO()
        fig, ax = plt.subplots(figsize=(8, 5), dpi=72)
        # Simplified plot
        if not plan1_data.empty:
            ax.plot(plan1_data['Station'], plan1_data['Max WSEL_Plan1'], 'b-', label=plan1_name)
        if not plan2_data.empty:
            ax.plot(plan2_data['Station'], plan2_data['Max WSEL_Plan2'], 'r--', label=plan2_name)
        ax.set_title(f"Comparison - {plan1_name} vs {plan2_name}", fontsize=12)
        ax.set_xlabel('Station')
        ax.set_ylabel('WSEL')
        ax.legend()
        ax.grid(True, alpha=0.3)
        plt.tight_layout()
        plt.savefig(buffer, format='png', dpi=72, bbox_inches='tight')
        plt.close()
    
    buffer.seek(0)
    return buffer
```

### 3. Update the plotting handler for comparison

Update the `plot_1d_profile_comparison` handler to use the same logic:

```python
elif name == "plot_1d_profile_comparison":
    try:
        project_path = arguments.get("project_path")
        plan1_name = arguments["plan1_name"]
        plan2_name = arguments["plan2_name"]
        river_name = arguments.get("river_name")
        reach_name = arguments.get("reach_name")
        
        # Get or initialize project
        ras = get_or_init_project(project_path)
        
        # Get HDF paths for both plans
        plan1_hdf_path = get_plan_hdf_path(ras, plan1_name)
        plan2_hdf_path = get_plan_hdf_path(ras, plan2_name)
        
        if not plan1_hdf_path:
            return [TextContent(
                type="text",
                text=f"Error: Plan '{plan1_name}' not found or has no results HDF file"
            )]
        
        if not plan2_hdf_path:
            return [TextContent(
                type="text",
                text=f"Error: Plan '{plan2_name}' not found or has no results HDF file"
            )]
        
        try:
            # Get cross-section data for both plans
            xsec_data1 = HdfResultsXsec.get_xsec_timeseries(plan1_hdf_path)
            xsec_data2 = HdfResultsXsec.get_xsec_timeseries(plan2_hdf_path)
            
            # Format results
            profile_df1 = format_profile_results(xsec_data1, river_name, reach_name)
            profile_df2 = format_profile_results(xsec_data2, river_name, reach_name)
            
            if profile_df1.empty and profile_df2.empty:
                return [TextContent(
                    type="text",
                    text="No cross-section data found for the specified criteria"
                )]
            
            # Merge for comparison
            comparison_df = pd.merge(
                profile_df1[['River', 'Reach', 'Station', 'Max WSEL']],
                profile_df2[['River', 'Reach', 'Station', 'Max WSEL']],
                on=['River', 'Reach', 'Station'],
                how='outer',
                suffixes=('_Plan1', '_Plan2')
            )
            
            # Calculate difference only where both values exist
            comparison_df['WSEL_Difference'] = pd.Series(dtype='float64')
            mask = comparison_df['Max WSEL_Plan1'].notna() & comparison_df['Max WSEL_Plan2'].notna()
            comparison_df.loc[mask, 'WSEL_Difference'] = (
                comparison_df.loc[mask, 'Max WSEL_Plan1'] - 
                comparison_df.loc[mask, 'Max WSEL_Plan2']
            )
            
            # Sort by station
            comparison_df.sort_values(['River', 'Reach', 'Station'], inplace=True)
            
            # Create plot
            img_buffer = plot_profile_comparison(
                comparison_df, plan1_name, plan2_name, river_name, reach_name
            )
            
            # Convert to base64
            img_base64 = base64.b64encode(img_buffer.getvalue()).decode('utf-8')
            
            # Get summary stats
            diff_col = comparison_df['WSEL_Difference'].dropna()
            summary_text = ""
            if not diff_col.empty:
                n_plan1_only = (comparison_df['Max WSEL_Plan1'].notna() & comparison_df['Max WSEL_Plan2'].isna()).sum()
                n_plan2_only = (comparison_df['Max WSEL_Plan1'].isna() & comparison_df['Max WSEL_Plan2'].notna()).sum()
                n_matching = mask.sum()
                
                summary_text = (
                    f"\n\nStation Summary:\n"
                    f"- Stations in Plan 1 only: {n_plan1_only}\n"
                    f"- Stations in Plan 2 only: {n_plan2_only}\n"
                    f"- Matching stations: {n_matching}\n\n"
                    f"Statistics (for matching stations):\n"
                    f"- Mean Difference: {diff_col.mean():.3f}\n"
                    f"- Max Increase: {diff_col.max():.3f}\n"
                    f"- Max Decrease: {diff_col.min():.3f}\n"
                    f"- Std Deviation: {diff_col.std():.3f}"
                )
            
            # Return as markdown image with summary
            return [TextContent(
                type="text",
                text=f"![1D Profile Comparison](data:image/png;base64,{img_base64})\n\n"
                     f"Profile comparison - {plan1_name} vs {plan2_name}"
                     f"{f' - River: {river_name}' if river_name else ''}"
                     f"{f' - Reach: {reach_name}' if reach_name else ''}"
                     f"{summary_text}"
            )]
            
        except Exception as e:
            return [TextContent(
                type="text",
                text=f"Error creating comparison plot: {str(e)}"
            )]
        
    except Exception as e:
        logger.error(f"Error plotting profile comparison: {str(e)}")
        return [TextContent(
            type="text",
            text=f"Error plotting profile comparison: {str(e)}"
        )]
```

## Summary of Changes

1. **Modified tabular comparison**:
   - Now shows blank cells for stations that don't exist in one of the plans
   - Only calculates differences where both plans have values
   - Added station counts to summary statistics

2. **Enhanced plotting**:
   - Plots handle NaN values properly by filtering them out
   - Each plan's profile is plotted independently by station
   - Added visual markers (triangles) for stations that exist in only one plan
   - Difference plot only shows where both plans have data

3. **Better statistics**:
   - Summary now shows count of matching vs non-matching stations
   - Statistics are calculated only for matching stations
   - Makes it clear when geometries differ between plans

This approach clearly highlights geometry differences between plans while still allowing meaningful comparison where stations match.