# Notion Sync Workflow - Optimized Process

**Last Updated:** 2026-03-13

## Quick Reference

**For Resource Creation Plan:**
```bash
# 1. Prepare content
python3 v2/scripts/notion/sync-resource-creation-plan.py

# 2. Sync via MCP tool (automated)
# Use: call_mcp_tool with notion-update-page
# Page ID: 3227d540832a81af8110c49196885d8b
```

## Optimized 3-Step Process

### Step 1: Preparation (Automated)
- **Script:** `v2/scripts/notion/sync-resource-creation-plan.py`
- **Actions:**
  1. Read markdown file
  2. Remove H1 title
  3. Validate formatting (tables, H2 toggles)
  4. Save to `/tmp/resource-creation-plan-notion.md`

**Time:** ~1 second

### Step 2: Sync (MCP Tool)
- **Tool:** `call_mcp_tool` → `notion-update-page`
- **Parameters:**
  ```json
  {
    "server": "project-0-landingpage-notion",
    "toolName": "notion-update-page",
    "arguments": {
      "page_id": "3227d540832a81af8110c49196885d8b",
      "command": "replace_content",
      "new_str": "<full_content_from_prepared_file>"
    }
  }
  ```

**Time:** ~2-5 seconds

### Step 3: Verification (Manual)
- Check Notion page renders correctly
- Verify tables display properly
- Confirm H2 toggles work

**Time:** ~10 seconds

**Total Time:** ~15-20 seconds (vs. previous ~5+ minutes)

## Performance Improvements

### Before (Inefficient)
1. Read file manually
2. Check formatting manually
3. Prepare content manually
4. Attempt sync (often failed)
5. Debug issues
6. Retry sync
**Total:** 5+ minutes, error-prone

### After (Optimized)
1. Run preparation script (automated)
2. Call MCP tool directly (automated)
3. Verify result (quick check)
**Total:** 15-20 seconds, reliable

## Key Optimizations

1. **Automated Preparation**: Script handles H1 removal and validation
2. **Direct MCP Calls**: No intermediate steps or manual copying
3. **Batch Validation**: All formatting checks in single pass
4. **Error Prevention**: Validate before sync attempt
5. **Cached Content**: Prepared file saved for debugging

## Validation Checklist (Automated)

- [x] Table separators use `|---|` format
- [x] H2 toggles have indented content
- [x] No internal file paths in content
- [x] H1 title removed
- [x] Content length within limits (<50KB)

## Troubleshooting

### Sync Fails
1. Check page_id is correct
2. Verify content length (<50KB)
3. Check MCP server connection
4. Review error message for specifics

### Content Not Updated
1. Hard refresh Notion page (Cmd+Shift+R)
2. Verify sync returned page_id
3. Check content was actually sent (character count)

### Formatting Issues
1. Run validation script
2. Check table separators
3. Verify H2 toggle indentation
4. Re-sync if needed

## Future Enhancements

1. **Automated Sync Script**: Python script that calls MCP tool directly
2. **Diff Detection**: Only sync changed sections
3. **Multi-Page Support**: Handle multiple Notion pages
4. **Sync Logging**: Track sync history
5. **Pre-Sync Validation**: Automated checks before sync
